From eb3dbcaffc2210d22881c729f2682a7ab7467f7f Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Sun, 10 Apr 2022 14:38:03 +0200 Subject: [PATCH] basic wifi connection on arduino --- SourceCode/arduino/.gitignore | 7 +++++ SourceCode/arduino/include/theWifi.h | 23 ++++++++++++++ SourceCode/arduino/lib/README | 46 ++++++++++++++++++++++++++++ SourceCode/arduino/platformio.ini | 16 ++++++++++ SourceCode/arduino/src/main.cpp | 12 ++++++++ 5 files changed, 104 insertions(+) create mode 100644 SourceCode/arduino/.gitignore create mode 100644 SourceCode/arduino/include/theWifi.h create mode 100644 SourceCode/arduino/lib/README create mode 100644 SourceCode/arduino/platformio.ini create mode 100644 SourceCode/arduino/src/main.cpp diff --git a/SourceCode/arduino/.gitignore b/SourceCode/arduino/.gitignore new file mode 100644 index 0000000..0520d57 --- /dev/null +++ b/SourceCode/arduino/.gitignore @@ -0,0 +1,7 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch + +include/theSecrets.h \ No newline at end of file diff --git a/SourceCode/arduino/include/theWifi.h b/SourceCode/arduino/include/theWifi.h new file mode 100644 index 0000000..1c33737 --- /dev/null +++ b/SourceCode/arduino/include/theWifi.h @@ -0,0 +1,23 @@ +#ifndef THEWIFI_H +#define THEWIFI_H + +#include "esp32-hal-log.h" +#include "WiFi.h" +#include "theSecrets.h" + +const char *serverIp; + +void connectWifi() +{ + log_i("Attempting to connect to WPA SSID: %s", ssid); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, psk); + while (WiFi.status() != WL_CONNECTED) + { + delay(1000); + } + serverIp = WiFi.localIP().toString().c_str(); + log_i("Connected, IP Address: %s", serverIp); +} + +#endif \ No newline at end of file diff --git a/SourceCode/arduino/lib/README b/SourceCode/arduino/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/SourceCode/arduino/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/SourceCode/arduino/platformio.ini b/SourceCode/arduino/platformio.ini new file mode 100644 index 0000000..31365bd --- /dev/null +++ b/SourceCode/arduino/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32-evb] +platform = espressif32 +board = esp32-evb +framework = arduino +monitor_speed = 115200 +build_flags = -DCORE_DEBUG_LEVEL=3 diff --git a/SourceCode/arduino/src/main.cpp b/SourceCode/arduino/src/main.cpp new file mode 100644 index 0000000..22db30b --- /dev/null +++ b/SourceCode/arduino/src/main.cpp @@ -0,0 +1,12 @@ +#include +#include "theWifi.h" + +void setup() +{ + connectWifi(); +} + +void loop() +{ + // put your main code here, to run repeatedly: +} \ No newline at end of file