diff --git a/firmware/README.md b/firmware/README.md index 3a3cea5..7cbcf45 100644 --- a/firmware/README.md +++ b/firmware/README.md @@ -3,6 +3,19 @@ This firmware interfaces with the LoRa transciever and Javascript web apps. # Setup and development See the main [README](https://github.com/sudomesh/disaster-radio) to build the firmware +## Connect to existing WiFi + +In WiFi mode, the firmware by default creates it's own SSID. If you want to connect to your own Wifi instead, +copy the file `secrets.H` to `secrets.h` and modify the file accordingly + + /* Place SSIDs, Passwords, Hashes, etc. in this file, it will not be tracked by git */ + + // Uncomment to enable the Wifi client + // #define WIFI_SSID "WIFI_SSID" + // #define WIFI_PASSWORD "WIFI_PASSWORD" + +Then follow the build instruction in the main [README](https://github.com/sudomesh/disaster-radio) + # Testing Debugging can be done over serial using a tty interface, such as screen or minicom. To test the web app: diff --git a/firmware/main.ino b/firmware/main.ino index 933e739..a930368 100644 --- a/firmware/main.ino +++ b/firmware/main.ino @@ -91,7 +91,7 @@ int clients = 0; int routes = 0; #define WIFI_POLL_DELAY 500 -#define WIFI_POLL_TRIES 10 +#define WIFI_POLL_TRIES 20 char nodeAddress[ADDR_LENGTH*2 + 1] = {'\0'}; char ssid[100] = {'\0'}; @@ -115,9 +115,9 @@ void setupWiFi() #ifdef WIFI_SSID Serial.printf(" --> Connecting to WiFi \"%s\"\n", WIFI_SSID); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); for (int i = 0; i < WIFI_POLL_TRIES && WiFi.status() != WL_CONNECTED; i++) { + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); delay(WIFI_POLL_DELAY); } if (WiFi.status() == WL_CONNECTED) @@ -150,6 +150,14 @@ void setupWiFi() } } +void checkWiFi() { +#ifdef WIFI_SSID + if (WiFi.status() != WL_CONNECTED) { + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + } +#endif +} + void setupMDNS() { Serial.println("* Initializing mDNS responder..."); @@ -562,4 +570,10 @@ void loop() drawStatusBar(); } } + // reconnect only in WiFi client mode +#ifdef WIFI_SSID + if (!useBLE) { + checkWiFi(); + } +#endif } diff --git a/firmware/secrets.H b/firmware/secrets.H new file mode 100644 index 0000000..7fafdb1 --- /dev/null +++ b/firmware/secrets.H @@ -0,0 +1,7 @@ +/* + * Copy this file to 'secrets.h' and place SSIDs, passwords etc in that file, + * it will not be tracked by git + */ + +//#define WIFI_SSID "WIFI_SSID" +//#define WIFI_PASSWORD "WIFI_PASSWORD"