forked from airgradienthq/arduino
Local storage mode using esp32 as AP
This commit is contained in:
@ -149,7 +149,7 @@ String LocalServer::htmlDashboard(String timestamp) {
|
|||||||
page += " margin: 10px 0;";
|
page += " margin: 10px 0;";
|
||||||
page += " }";
|
page += " }";
|
||||||
page += " .datetime-container input[type=\"datetime-local\"] {";
|
page += " .datetime-container input[type=\"datetime-local\"] {";
|
||||||
page += " margin-right: 10px;";
|
page += " margin-left: 10px;";
|
||||||
page += " padding: 5px;";
|
page += " padding: 5px;";
|
||||||
page += " font-size: 14px;";
|
page += " font-size: 14px;";
|
||||||
page += " }";
|
page += " }";
|
||||||
@ -174,8 +174,8 @@ String LocalServer::htmlDashboard(String timestamp) {
|
|||||||
page += " <button type=\"submit\">Download Measurements</button>";
|
page += " <button type=\"submit\">Download Measurements</button>";
|
||||||
page += " </form>";
|
page += " </form>";
|
||||||
page += " <form id=\"timestampForm\" method=\"POST\" action=\"/timestamp\">";
|
page += " <form id=\"timestampForm\" method=\"POST\" action=\"/timestamp\">";
|
||||||
page += " <button type=\"submit\">Set Timestamp</button>";
|
page += " <input type=\"datetime-local\" id=\"timestampInput\" required>";
|
||||||
page += " <input type=\"datetime-local\" id=\"timestampInput\" required>";
|
page += " <button type=\"submit\">Set Timestamp</button>";
|
||||||
page += " <input type=\"hidden\" name=\"timestamp\" id=\"epochInput\">";
|
page += " <input type=\"hidden\" name=\"timestamp\" id=\"epochInput\">";
|
||||||
page += " </form>";
|
page += " </form>";
|
||||||
page += " <div class=\"spacer\"></div>";
|
page += " <div class=\"spacer\"></div>";
|
||||||
|
@ -137,7 +137,7 @@ void setup() {
|
|||||||
delay(100); /** For bester show log */
|
delay(100); /** For bester show log */
|
||||||
|
|
||||||
// Set timezone to UTC
|
// Set timezone to UTC
|
||||||
setenv("TZ", "UTC+0", 1);
|
setenv("TZ", "UTC", 1);
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
/** Print device ID into log */
|
/** Print device ID into log */
|
||||||
@ -187,38 +187,20 @@ void setup() {
|
|||||||
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
|
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
oledDisplay.setText("Offline Storage Mode", "Connecting to", "default WiFi");
|
// Connect to Wi-Fi network with SSID and password
|
||||||
|
Serial.print("Setting AP (Access Point)…");
|
||||||
|
// Remove the password parameter, if you want the AP (Access Point) to be open
|
||||||
|
WiFi.softAP("airgradient", "cleanair");
|
||||||
|
IPAddress IP = WiFi.softAPIP();
|
||||||
|
Serial.print("AP IP address: ");
|
||||||
|
Serial.println(IP);
|
||||||
|
|
||||||
// Attempt connect to default wifi
|
oledDisplay.setText("", "Offline Storage Mode", "");
|
||||||
Serial.println("Connecting to default wifi " + String(wifiConnector.defaultSsid));
|
|
||||||
WiFi.begin(wifiConnector.defaultSsid, wifiConnector.defaultPassword);
|
|
||||||
|
|
||||||
/** Wait for wifi connect to AP */
|
delay(3000);
|
||||||
int count = 0;
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(1000);
|
|
||||||
count++;
|
|
||||||
if (count >= 10) {
|
|
||||||
Serial.println("Try connect to default wifi \"" + String(wifiConnector.defaultSsid) +
|
|
||||||
"\"failed, ignore");
|
|
||||||
Serial.println();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify and wait
|
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
|
||||||
Serial.println("WiFi connected");
|
|
||||||
oledDisplay.setText("WiFi connected", "", "");
|
|
||||||
mdnsInit();
|
mdnsInit();
|
||||||
localServer.begin();
|
localServer.begin();
|
||||||
isLocalServerInitialized = true;
|
|
||||||
} else {
|
|
||||||
Serial.println("WiFi not connect");
|
|
||||||
oledDisplay.setText("WiFi not connect", "", "");
|
|
||||||
}
|
|
||||||
delay(3000);
|
|
||||||
|
|
||||||
// Update display and led bar after finishing setup to show dashboard
|
// Update display and led bar after finishing setup to show dashboard
|
||||||
updateDisplayAndLedBar();
|
updateDisplayAndLedBar();
|
||||||
}
|
}
|
||||||
@ -264,15 +246,8 @@ void loop() {
|
|||||||
|
|
||||||
watchdogFeedSchedule.run();
|
watchdogFeedSchedule.run();
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED && !isLocalServerInitialized) {
|
// /** Check for handle WiFi reconnect */
|
||||||
Serial.println("WiFi connected and local server has not initialized, initializing...");
|
// wifiConnector.handle();
|
||||||
mdnsInit();
|
|
||||||
localServer.begin();
|
|
||||||
isLocalServerInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check for handle WiFi reconnect */
|
|
||||||
wifiConnector.handle();
|
|
||||||
|
|
||||||
/** factory reset handle */
|
/** factory reset handle */
|
||||||
factoryConfigReset();
|
factoryConfigReset();
|
||||||
@ -928,13 +903,8 @@ 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
|
||||||
if (wifiConnector.isConnected()) {
|
stateMachine.displayHandle(AgStateMachineNormal);
|
||||||
stateMachine.displayHandle(AgStateMachineNormal);
|
// stateMachine.handleLeds(AgStateMachineNormal);
|
||||||
} else {
|
|
||||||
stateMachine.displayHandle(AgStateMachineWiFiLost);
|
|
||||||
}
|
|
||||||
// stateMachine.handleLeds(AgStateMachineNormal);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user