2 Problems : Timezone & AP mode #454
-
Hello! problem1: I need to save the timezone setting made on the timezone page to reload the same setting after shutting down my esp32 and repower it. Now i found that the timezone setting is lost every time the esp is shutted down. (the dates and time that i see in my main page of the browser shows a date and time around 1970 after every restart. I made some tests to create a txt file saved with spiffs with the timezone configuration and try to read it at every restart but with no success( see code below) problem2: I have problems with the access point mode. When i first power on ESP32 after programming it, it's correctly configured as access point and with a mobile device a set the correct information (settings) of my wireless network. Then when the network is not available anymore i need to get the access point mode working again after a set timeout but i can't get this working. I tried also to change the autoReconnect option from true to false but didn't understood well how this function works. I hope to solve this! Thank you in advance! #if defined(ARDUINO_ARCH_ESP8266) String tz; static const char AUX_TIMEZONE[] PROGMEM = R"( typedef struct { static const Timezone_t TZ[] = { #if defined(ARDUINO_ARCH_ESP8266) AutoConnect Portal(Server); "<p style="padding-top:15px;text-align:center">" AUTOCONNECT_LINK(COG_24) "" "" ""; static const char *wd[7] = { "Dom","Lun","Mar","Mer","Gio","Ven","Sab" }; struct tm *tm; time_t t; char dateTime[26]; t = time(NULL); } void startPage() { Serial.println("tz"); for (uint8_t n = 0; n < sizeof(TZ) / sizeof(Timezone_t); n++) { } // The /start page just constitutes timezone, void setup() { // Enable saved past credential by autoReconnect option, Config.autoReconnect = false; Portal.config(Config); // Load aux. page Portal.join({ Timezone }); // Register aux. page // Behavior a root path of ESP8266WebServer. Serial.println("Creating portal and trying to connect..."); } void loop() { if (tz!=tz1){ while (file22.available()) file22.print(tz); } } |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 16 replies
-
It's a Q&A, not an issue, move it to the Discussions and hope for the answer. |
Beta Was this translation helpful? Give feedback.
-
@belu40 First, I answer from the AutoConnect's custom web page adopts the ESP Arduino core's WebServer class programming model. According to this model, all procedures that should be written by the user are treated as part of the event handler. It is a typical example of a server-side model. One thing to keep in mind with server-side programs is that the only opportunity to perform the processing you program in your sketch only exists in response to a request from the client. (Of course, in a real server component, a resident process runs in the background, but that's the service, not a server-side model) But the documentation of the ESP8266 Arduino core and the ESP32 Arduino core does not explain it clearly, which may cause confusion to the implementors of the sketches. To compensate for that a bit, I described it as a custom web page programming model in the AutoConnect documentation. Please refer it. Turning to the your sketch modification, I find that the modification does not conform to the server-side programming model. Your approach is to detect a change in time zone selection and save it to SPIFFS, but this kind of task should be done in an event handler. (i.e. it's a custom web page handler)
So, we have the modification that you want as followings:
That's it. |
Beta Was this translation helpful? Give feedback.
-
There is already documentation about it. |
Beta Was this translation helpful? Give feedback.
-
Ok, I tried with the suggestions but no success... i think the problem is in the setup() // Enable saved past credential by autoReconnect option, Config.autoReconnect = true; //abilita Access point se perde connessione al wifi //altre config //abilita upload programma da rete Portal.config(Config); // Recover timezone setting Portal.join({ Timezone }); // Register aux. page // Behavior a root path of ESP8266WebServer. Serial.println("Creating portal and trying to connect..."); } the problem is that i think that the part from //load aux page is not good... because for some reason it doesn't receive the timezone received from spiffs... am i correct? many thanks in advance |
Beta Was this translation helpful? Give feedback.
@belu40 First, I answer from the
Simple.ino
improvements that you failed.AutoConnect's custom web page adopts the ESP Arduino core's WebServer class programming model. According to this model, all procedures that should be written by the user are treated as part of the event handler.
It is a typical example of a server-side model. One thing to keep in mind with server-side programs is that the only opportunity to perform the processing you program in your sketch only exists in response to a request from the client. (Of course, in a real server component, a resident process runs in the background, but that's the service, not a server-side model)
AutoConnect's custom web pages assume the E…