9
9
#include < Adafruit_GFX.h>
10
10
#include < Adafruit_SSD1306.h>
11
11
#include < Adafruit_I2CDevice.h>
12
+ #include < SoftwareSerial.h>
12
13
13
14
#include " config.h"
14
15
@@ -18,7 +19,14 @@ extern "C"
18
19
#include " freertos/timers.h"
19
20
}
20
21
21
- #define Sprintf (f, ...) ({ char * s; asprintf (&s, f, __VA_ARGS__); String r = s; free (s); r; })
22
+ #define Sprintf (f, ...) ( \
23
+ { \
24
+ char *s; \
25
+ asprintf (&s, f, __VA_ARGS__); \
26
+ String r = s; \
27
+ free (s); \
28
+ r; \
29
+ })
22
30
#define DEVICE_ID (Sprintf(" %06" PRIx64, ESP.getEfuseMac() >> 24 )) // unique device ID
23
31
#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds
24
32
@@ -318,76 +326,80 @@ void setupOTA()
318
326
ArduinoOTA
319
327
.setHostname (WiFiSettings.hostname .c_str ())
320
328
.setPassword (WiFiSettings.password .c_str ())
321
- .onStart ([]() {
322
- isUpdating = true ;
323
-
324
- String type;
325
-
326
- if (ArduinoOTA.getCommand () == U_FLASH)
327
- {
328
- type = " sketch" ;
329
- }
330
- else
331
- { // U_FS
332
- type = " filesystem" ;
333
- }
334
-
335
- // NOTE: if updating FS this would be the place to unmount FS using FS.end()
336
- Serial.println (" Start updating " + type);
337
-
338
- display.clearDisplay ();
339
- display.setTextSize (1 );
340
- display.print (" updating..." );
341
-
342
- display.display ();
343
- })
344
- .onEnd ([]() {
345
- Serial.println (" \n End" );
346
-
347
- isUpdating = false ;
348
- })
349
- .onProgress ([](unsigned int progress, unsigned int total) {
350
- unsigned int percentValue = progress / (total / 100 );
351
-
352
- Serial.printf (" Progress: %u%%\r " , percentValue);
353
-
354
- display.clearDisplay ();
355
-
356
- display.setCursor (0 , 0 );
357
- display.setTextSize (1 );
358
- display.print (" updating..." );
359
-
360
- display.setCursor (0 , 40 );
361
- display.setTextSize (2 );
362
- display.print (percentValue);
363
- display.print (" %" );
364
-
365
- display.display ();
366
- })
367
- .onError ([](ota_error_t error) {
368
- Serial.printf (" Error[%u]: " , error);
369
-
370
- if (error == OTA_AUTH_ERROR)
371
- {
372
- Serial.println (" Auth Failed" );
373
- }
374
- else if (error == OTA_BEGIN_ERROR)
375
- {
376
- Serial.println (" Begin Failed" );
377
- }
378
- else if (error == OTA_CONNECT_ERROR)
379
- {
380
- Serial.println (" Connect Failed" );
381
- }
382
- else if (error == OTA_RECEIVE_ERROR)
383
- {
384
- Serial.println (" Receive Failed" );
385
- }
386
- else if (error == OTA_END_ERROR)
387
- {
388
- Serial.println (" End Failed" );
389
- }
390
- })
329
+ .onStart ([]()
330
+ {
331
+ isUpdating = true ;
332
+
333
+ String type;
334
+
335
+ if (ArduinoOTA.getCommand () == U_FLASH)
336
+ {
337
+ type = " sketch" ;
338
+ }
339
+ else
340
+ { // U_FS
341
+ type = " filesystem" ;
342
+ }
343
+
344
+ // NOTE: if updating FS this would be the place to unmount FS using FS.end()
345
+ Serial.println (" Start updating " + type);
346
+
347
+ display.clearDisplay ();
348
+ display.setTextSize (1 );
349
+ display.print (" updating..." );
350
+
351
+ display.display ();
352
+ })
353
+ .onEnd ([]()
354
+ {
355
+ Serial.println (" \n End" );
356
+
357
+ isUpdating = false ;
358
+ })
359
+ .onProgress ([](unsigned int progress, unsigned int total)
360
+ {
361
+ unsigned int percentValue = progress / (total / 100 );
362
+
363
+ Serial.printf (" Progress: %u%%\r " , percentValue);
364
+
365
+ display.clearDisplay ();
366
+
367
+ display.setCursor (0 , 0 );
368
+ display.setTextSize (1 );
369
+ display.print (" updating..." );
370
+
371
+ display.setCursor (0 , 40 );
372
+ display.setTextSize (2 );
373
+ display.print (percentValue);
374
+ display.print (" %" );
375
+
376
+ display.display ();
377
+ })
378
+ .onError ([](ota_error_t error)
379
+ {
380
+ Serial.printf (" Error[%u]: " , error);
381
+
382
+ if (error == OTA_AUTH_ERROR)
383
+ {
384
+ Serial.println (" Auth Failed" );
385
+ }
386
+ else if (error == OTA_BEGIN_ERROR)
387
+ {
388
+ Serial.println (" Begin Failed" );
389
+ }
390
+ else if (error == OTA_CONNECT_ERROR)
391
+ {
392
+ Serial.println (" Connect Failed" );
393
+ }
394
+ else if (error == OTA_RECEIVE_ERROR)
395
+ {
396
+ Serial.println (" Receive Failed" );
397
+ }
398
+ else if (error == OTA_END_ERROR)
399
+ {
400
+ Serial.println (" End Failed" );
401
+ }
402
+ })
391
403
.begin ();
392
404
}
393
405
@@ -445,18 +457,21 @@ void setup()
445
457
WiFiSettings.password = PASSWORD;
446
458
447
459
// Set callbacks to start OTA when the portal is active
448
- WiFiSettings.onPortal = []() {
460
+ WiFiSettings.onPortal = []()
461
+ {
449
462
isPortalActive = true ;
450
463
451
464
Serial.println (" WiFi config portal active" );
452
465
453
466
setupOTA ();
454
467
};
455
- WiFiSettings.onPortalWaitLoop = []() {
468
+ WiFiSettings.onPortalWaitLoop = []()
469
+ {
456
470
ArduinoOTA.handle ();
457
471
};
458
472
459
- WiFiSettings.onConfigSaved = []() {
473
+ WiFiSettings.onConfigSaved = []()
474
+ {
460
475
ESP.restart ();
461
476
};
462
477
0 commit comments