Merge pull request #97 from grisu48/wificlient

Improve Wifi client mode
This commit is contained in:
grant_____
2020-10-10 22:09:37 -04:00
committed by GitHub
3 changed files with 36 additions and 2 deletions

View File

@@ -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:

View File

@@ -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
}

7
firmware/secrets.H Normal file
View File

@@ -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"