77
88#include < ESPForm.h>
99
10- // For HTML content
10+ // For HTML content
1111#include " html.h"
1212
13- // Your WiFi SSID and Password
13+ // Your WiFi SSID and Password
1414#define WIFI_SSID " Your_WiFi_SSID"
1515#define WIFI_PASSWORD " Your_WiFi_Password"
1616
17- // The AP
17+ // The AP
1818String apSSID = " ESPForm" ;
1919String apPSW = " 12345678" ;
2020
@@ -34,7 +34,7 @@ void formElementEventCallback(ESPFormClass::HTMLElementItem element)
3434 Serial.println (" ***********************************" );
3535 Serial.println ();
3636
37- // If first knob value changed
37+ // If first knob value changed
3838 if (element.id == " clear-btn" )
3939 {
4040 ESPForm.runScript (" clearData()" );
@@ -44,7 +44,7 @@ void formElementEventCallback(ESPFormClass::HTMLElementItem element)
4444void serverTimeoutCallback ()
4545{
4646
47- // If server timeout (no client connected within specific time)
47+ // If server timeout (no client connected within specific time)
4848 Serial.println (" ***********************************" );
4949 Serial.println (" Server timed out" );
5050 Serial.println (" ***********************************" );
@@ -63,10 +63,10 @@ void setup()
6363 WiFi.disconnect (true );
6464 WiFi.persistent (false );
6565
66- // Set WiFi mode to STA (create ESP own network) or AP + STA (create ESP own network and join the WiFi network)
66+ // Set WiFi mode to STA (create ESP own network) or AP + STA (create ESP own network and join the WiFi network)
6767 WiFi.mode (WIFI_AP_STA);
6868
69- // For STA only or AP + STA mode
69+ // For STA only or AP + STA mode
7070 WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
7171 Serial.print (" Connecting to Wi-Fi" );
7272 while (WiFi.status () != WL_CONNECTED)
@@ -79,54 +79,58 @@ void setup()
7979 Serial.println (WiFi.localIP ());
8080 Serial.println ();
8181
82- // generate seed numbers
82+ // generate seed numbers
83+ #if defined(ESP32)
84+ randomSeed (analogRead (34 ));
85+ #elif defined(ESP8266)
8386 randomSeed (analogRead (0 ));
87+ #endif
8488
85- // Set the system time via NTP server
89+ // Set the system time via NTP server
8690 Serial.println (" ***********************************" );
8791 Serial.println (" Set up time..." );
8892 ESPForm.setClock (timezone);
8993 Serial.println (" ***********************************" );
9094 Serial.println ();
9195
92- // FLASH_FS is defined in ESPFormFS.h
96+ // DEFAULT_FLASH_FS is defined in ESPFormFS.h
9397#if defined(ESP32)
94- FLASH_FS .begin (true );
98+ DEFAULT_FLASH_FS .begin (true );
9599#elif defined(ESP8266)
96- FLASH_FS .begin ();
100+ DEFAULT_FLASH_FS .begin ();
97101#endif
98102
99- // Element Event Config existed?
100- if (!FLASH_FS .exists (" /chart-test.json" ))
103+ // Element Event Config existed?
104+ if (!DEFAULT_FLASH_FS .exists (" /chart-test.json" ))
101105 {
102106
103- // Add html element event listener, id "knob1" for onchange event
107+ // Add html element event listener, id "knob1" for onchange event
104108 ESPForm.addElementEventListener (" clear-btn" , ESPFormClass::EVENT_ON_CLICK);
105109
106110 /*
107111 If the id of html elements changed, please update the ElementEventListener config
108112 */
109113
110- // Save notification config
114+ // Save notification config
111115 ESPForm.saveElementEventConfig (" /chart-test.json" , esp_form_storage_flash);
112116 }
113117 else
114118 {
115- // Load notification config
119+ // Load notification config
116120 ESPForm.loadElementEventConfig (" /chart-test.json" , esp_form_storage_flash);
117121 }
118122
119- // Add the html contents (in html.h) for the web page rendering
123+ // Add the html contents (in html.h) for the web page rendering
120124
121- // flash uint8_t array, file name, size of array, gzip compression
125+ // flash uint8_t array, file name, size of array, gzip compression
122126 ESPForm.addFileData (index_html_gz, " index.html" , sizeof (index_html_gz), true );
123127 ESPForm.addFileData (main_js_gz, " main.js" , sizeof (main_js_gz), true );
124128 ESPForm.addFileData (highcharts_js_gz, " highcharts.js" , sizeof (highcharts_js_gz), true );
125129
126- // If AP only or AP + STA mode, set the AP's SSID and Password
130+ // If AP only or AP + STA mode, set the AP's SSID and Password
127131 ESPForm.setAP (apSSID.c_str (), apPSW.c_str ());
128132
129- // Start ESPForm's Webserver
133+ // Start ESPForm's Webserver
130134 ESPForm.begin (formElementEventCallback, serverTimeoutCallback, serverTimeout, true );
131135
132136 ESPForm.startServer ();
@@ -143,7 +147,7 @@ void setup()
143147
144148void loop ()
145149{
146- // If a client existed
150+ // If a client existed
147151 if (ESPForm.getClientCount () > 0 )
148152 {
149153
0 commit comments