1515 * - Timer test and some other Arduino basic functions.
1616 *
1717 * by lxyzn from HelTec AutoMation, ChengDu, China
18- * 成都惠利特自动化科技有限公司
18+ * 成都惠利特自动化科技有限公司¸
1919 * www.heltec.cn
2020 *
2121 * This project is also available on GitHub:
2929#include " HT_SSD1306Wire.h"
3030
3131
32+
3233/* ********************************************* WIFI Client *********************************
34+
3335 * wifi client
3436 */
3537const char * ssid = " xxxxxx" ; // replace "xxxxxx" with your WIFI's ssid
3638const char * password = " xxxxxx" ; // replace "xxxxxx" with your WIFI's password
3739
40+
3841// WiFi&OTA
3942// #define HOSTNAME "HelTec_OTA_OLED"
4043#define PASSWORD " HT.123456" // the password for OTA upgrade, can set it in any char you want
4144
4245/* *********************************************** *********************************
4346 * Whether to use static IP
4447 */
48+
4549#define USE_STATIC_IP false
4650#if USE_STATIC_IP
4751 IPAddress staticIP (192 ,168 ,1 ,22 );
@@ -54,6 +58,7 @@ const char* password = "xxxxxx"; //replace "xxxxxx" with your WIFI's password
5458/* ******************************************************************
5559 * OLED Arguments
5660 */
61+
5762// #define RST_OLED 16 //OLED Reset pin, requires manual reset, otherwise it will not be displayed
5863#define OLED_UPDATE_INTERVAL 500 // OLED screen refresh interval ms
5964// SSD1306 display(0x3C, 4, 15); //Pins 4 and 5 are bound to the motherboard of Kit 32 and cannot be used for other purposes
@@ -62,6 +67,7 @@ static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, R
6267
6368/* *******************************************************************
6469 * OTA upgrade configuration
70+
6571 */
6672void setupOTA ()
6773{
@@ -80,11 +86,14 @@ void setupOTA()
8086
8187 ArduinoOTA.onStart ([]()
8288 {
89+
8390 display.clear ();
8491 display.setFont (ArialMT_Plain_10); // Set font size
8592 display.setTextAlignment (TEXT_ALIGN_LEFT);// Set font alignment
8693 display.drawString (0 , 0 , " Start Updating...." );
8794
95+
96+
8897 Serial.printf (" Start Updating....Type:%s\n " , (ArduinoOTA.getCommand () == U_FLASH) ? " sketch" : " filesystem" );
8998 });
9099
@@ -169,22 +178,28 @@ void setupWIFI()
169178 display.drawString (0 , 10 , String (ssid));
170179 display.display ();
171180
181+
172182 // Connect to WiFi, delete old configuration, turn off WiFi, prepare to reconfigure
183+
173184 WiFi.disconnect (true );
174185 delay (1000 );
175186
176187 WiFi.mode (WIFI_STA);
177188 // WiFi.onEvent(WiFiEvent);
178189 WiFi.setAutoConnect (true );
190+
179191 WiFi.setAutoReconnect (true ); // Automatically reconnect after disconnecting WiFi ESP32 is not available
192+
180193 // WiFi.setHostname(HOSTNAME);
181194 WiFi.begin (ssid, password);
182195#if USE_STATIC_IP
183196 WiFi.config (staticIP, gateway, subnet);
184197#endif
185198
199+
186200 // Wait for 5000ms, if not connected, continue
187201
202+
188203 byte count = 0 ;
189204 while (WiFi.status () != WL_CONNECTED && count < 10 )
190205 {
@@ -234,12 +249,14 @@ void loop()
234249 unsigned long ms = millis ();
235250 if (ms % 1000 == 0 )
236251 {
237- Serial.println (" hello,OTA now" );
252+ Serial.println (" hello,OTA now" );
238253 }
239254}
240255
241256/* ***************************************************
257+
242258 * [Universal Function] ESP32 WiFi Kit 32 Event Handling
259+
243260 */
244261void WiFiEvent (WiFiEvent_t event)
245262{
0 commit comments