Local storage mode using esp32 as AP

This commit is contained in:
samuelbles07
2024-12-07 05:39:59 +07:00
parent 67b71f583b
commit 83a4eddc37
2 changed files with 18 additions and 48 deletions

View File

@ -149,7 +149,7 @@ String LocalServer::htmlDashboard(String timestamp) {
page += " margin: 10px 0;";
page += " }";
page += " .datetime-container input[type=\"datetime-local\"] {";
page += " margin-right: 10px;";
page += " margin-left: 10px;";
page += " padding: 5px;";
page += " font-size: 14px;";
page += " }";
@ -174,8 +174,8 @@ String LocalServer::htmlDashboard(String timestamp) {
page += " <button type=\"submit\">Download Measurements</button>";
page += " </form>";
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 += " </form>";
page += " <div class=\"spacer\"></div>";

View File

@ -137,7 +137,7 @@ void setup() {
delay(100); /** For bester show log */
// Set timezone to UTC
setenv("TZ", "UTC+0", 1);
setenv("TZ", "UTC", 1);
tzset();
/** Print device ID into log */
@ -187,38 +187,20 @@ void setup() {
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
Serial.println("Connecting to default wifi " + String(wifiConnector.defaultSsid));
WiFi.begin(wifiConnector.defaultSsid, wifiConnector.defaultPassword);
oledDisplay.setText("", "Offline Storage Mode", "");
/** Wait for wifi connect to AP */
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", "", "");
delay(3000);
mdnsInit();
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
updateDisplayAndLedBar();
}
@ -264,15 +246,8 @@ void loop() {
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 */
wifiConnector.handle();
// /** Check for handle WiFi reconnect */
// wifiConnector.handle();
/** factory reset handle */
factoryConfigReset();
@ -928,13 +903,8 @@ static void updateDisplayAndLedBar(void) {
if (configuration.isOfflineMode()) {
// Ignore network related status when in offline mode
if (wifiConnector.isConnected()) {
stateMachine.displayHandle(AgStateMachineNormal);
} else {
stateMachine.displayHandle(AgStateMachineWiFiLost);
}
// stateMachine.handleLeds(AgStateMachineNormal);
stateMachine.displayHandle(AgStateMachineNormal);
// stateMachine.handleLeds(AgStateMachineNormal);
return;
}