forked from airgradienthq/arduino
WiFi reconnection with indicator
This commit is contained in:
@ -15,7 +15,8 @@
|
|||||||
- ssid ➝ `airgradient`
|
- ssid ➝ `airgradient`
|
||||||
- password ➝ `cleanair`
|
- password ➝ `cleanair`
|
||||||
2. Maximum measurements file is around 113kb. If assume each measurements is 60 bytes, with write schedule 2 minutes, SPIFFS will be full in around 5 days
|
2. Maximum measurements file is around 113kb. If assume each measurements is 60 bytes, with write schedule 2 minutes, SPIFFS will be full in around 5 days
|
||||||
3. Tips. If monitor already connected to wifi once on boot, no need to restart the monitor for reconnection, it will automatically connect to AP once it is available
|
3. WiFi connection attempt on boot wait for 10s before considering timeout, and continue
|
||||||
|
4. Tips. If monitor not connected to wifi on boot, no need to restart the monitor for reconnection, it will automatically connect to AP once it is available
|
||||||
|
|
||||||
### Local Storage Endpoinds
|
### Local Storage Endpoinds
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
|||||||
|
|
||||||
static bool ledBarButtonTest = false;
|
static bool ledBarButtonTest = false;
|
||||||
static String fwNewVersion;
|
static String fwNewVersion;
|
||||||
|
static bool isLocalServerInitialized = false;
|
||||||
|
|
||||||
static void boardInit(void);
|
static void boardInit(void);
|
||||||
static void failedHandler(String msg);
|
static void failedHandler(String msg);
|
||||||
@ -193,8 +194,6 @@ void setup() {
|
|||||||
|
|
||||||
// Attempt connect to default wifi
|
// Attempt connect to default wifi
|
||||||
Serial.println("Connecting to default wifi " + String(wifiConnector.defaultSsid));
|
Serial.println("Connecting to default wifi " + String(wifiConnector.defaultSsid));
|
||||||
WiFi.begin();
|
|
||||||
/** Set wifi connect */
|
|
||||||
WiFi.begin(wifiConnector.defaultSsid, wifiConnector.defaultPassword);
|
WiFi.begin(wifiConnector.defaultSsid, wifiConnector.defaultPassword);
|
||||||
|
|
||||||
/** Wait for wifi connect to AP */
|
/** Wait for wifi connect to AP */
|
||||||
@ -202,7 +201,7 @@ void setup() {
|
|||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
count++;
|
count++;
|
||||||
if (count >= 15) {
|
if (count >= 10) {
|
||||||
Serial.println("Try connect to default wifi \"" + String(wifiConnector.defaultSsid) +
|
Serial.println("Try connect to default wifi \"" + String(wifiConnector.defaultSsid) +
|
||||||
"\"failed, ignore");
|
"\"failed, ignore");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@ -212,10 +211,13 @@ void setup() {
|
|||||||
|
|
||||||
// Notify and wait
|
// Notify and wait
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
Serial.println("WiFi connected");
|
||||||
oledDisplay.setText("WiFi connected", "", "");
|
oledDisplay.setText("WiFi connected", "", "");
|
||||||
mdnsInit();
|
mdnsInit();
|
||||||
localServer.begin();
|
localServer.begin();
|
||||||
|
isLocalServerInitialized = true;
|
||||||
} else {
|
} else {
|
||||||
|
Serial.println("WiFi not connect");
|
||||||
oledDisplay.setText("WiFi not connect", "", "");
|
oledDisplay.setText("WiFi not connect", "", "");
|
||||||
}
|
}
|
||||||
delay(3000);
|
delay(3000);
|
||||||
@ -265,6 +267,13 @@ void loop() {
|
|||||||
|
|
||||||
watchdogFeedSchedule.run();
|
watchdogFeedSchedule.run();
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_CONNECTED && !isLocalServerInitialized) {
|
||||||
|
Serial.println("WiFi connected and local server has not initialized, initializing...");
|
||||||
|
mdnsInit();
|
||||||
|
localServer.begin();
|
||||||
|
isLocalServerInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Check for handle WiFi reconnect */
|
/** Check for handle WiFi reconnect */
|
||||||
wifiConnector.handle();
|
wifiConnector.handle();
|
||||||
|
|
||||||
@ -921,8 +930,13 @@ static void updateDisplayAndLedBar(void) {
|
|||||||
|
|
||||||
if (configuration.isOfflineMode()) {
|
if (configuration.isOfflineMode()) {
|
||||||
// Ignore network related status when in offline mode
|
// Ignore network related status when in offline mode
|
||||||
stateMachine.displayHandle(AgStateMachineNormal);
|
if (wifiConnector.isConnected()) {
|
||||||
|
stateMachine.displayHandle(AgStateMachineNormal);
|
||||||
|
} else {
|
||||||
|
stateMachine.displayHandle(AgStateMachineWiFiLost);
|
||||||
|
}
|
||||||
stateMachine.handleLeds(AgStateMachineNormal);
|
stateMachine.handleLeds(AgStateMachineNormal);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1182,17 +1196,17 @@ int calculateMaxPeriod(int updateInterval) {
|
|||||||
void offlineStorageUpdate() {
|
void offlineStorageUpdate() {
|
||||||
if (measurements.saveLocalStorage(*ag)) {
|
if (measurements.saveLocalStorage(*ag)) {
|
||||||
// blue
|
// blue
|
||||||
ag->ledBar.setColor(0, 0, 255, 0);
|
ag->ledBar.setColor(0, 0, 255, 0);
|
||||||
ag->ledBar.show();
|
ag->ledBar.show();
|
||||||
delay(250);
|
delay(250);
|
||||||
ag->ledBar.setColor(0, 0, 0, 0);
|
ag->ledBar.setColor(0, 0, 0, 0);
|
||||||
ag->ledBar.show();
|
ag->ledBar.show();
|
||||||
delay(250);
|
delay(250);
|
||||||
ag->ledBar.setColor(0, 0, 255, 0);
|
ag->ledBar.setColor(0, 0, 255, 0);
|
||||||
ag->ledBar.show();
|
ag->ledBar.show();
|
||||||
delay(250);
|
delay(250);
|
||||||
ag->ledBar.setColor(0, 0, 0, 0);
|
ag->ledBar.setColor(0, 0, 0, 0);
|
||||||
ag->ledBar.show();
|
ag->ledBar.show();
|
||||||
} else {
|
} else {
|
||||||
// red
|
// red
|
||||||
ag->ledBar.setColor(255, 0, 0, 0);
|
ag->ledBar.setColor(255, 0, 0, 0);
|
||||||
|
Reference in New Issue
Block a user