66#include " lcd.h"
77#include " debug.h"
88#include " emonesp.h"
9-
9+ # include " web_server.h "
1010#include < MongooseHttpClient.h>
1111#include < Update.h>
1212
@@ -79,7 +79,9 @@ bool http_update_start(String source, size_t total)
7979
8080 lcd.display (F (" Updating WiFi" ), 0 , 0 , 10 * 1000 , LCD_CLEAR_LINE | LCD_DISPLAY_NOW);
8181 lcd.display (F (" " ), 0 , 1 , 10 * 1000 , LCD_CLEAR_LINE | LCD_DISPLAY_NOW);
82-
82+ StaticJsonDocument<128 > event;
83+ event[" ota" ] = " started" ;
84+ web_server_event (event);
8385 return true ;
8486 }
8587
@@ -110,6 +112,11 @@ bool http_update_write(uint8_t *data, size_t len)
110112 lcd.display (text, 0 , 1 , 10 * 1000 , LCD_DISPLAY_NOW);
111113
112114 DEBUG_PORT.printf (" Update: %d%%\n " , percent);
115+
116+ StaticJsonDocument<128 > event;
117+ event[" ota_progress" ] = percent;
118+ web_server_event (event);
119+ yield ();
113120 lastPercent = percent;
114121 }
115122 }
@@ -127,9 +134,17 @@ bool http_update_end()
127134 {
128135 DBUGF (" Update Success: %u" , update_position);
129136 lcd.display (F (" Complete" ), 0 , 1 , 10 * 1000 , LCD_CLEAR_LINE | LCD_DISPLAY_NOW);
137+ StaticJsonDocument<128 > event;
138+ event[" ota" ] = " completed" ;
139+ web_server_event (event);
140+ yield ();
130141 return true ;
131142 } else {
132143 DBUGF (" Update failed: %d" , Update.getError ());
144+ StaticJsonDocument<128 > event;
145+ event[" ota" ] = " failed" ;
146+ web_server_event (event);
147+ yield ();
133148 lcd.display (F (" Error" ), 0 , 1 , 10 * 1000 , LCD_CLEAR_LINE | LCD_DISPLAY_NOW);
134149 }
135150
0 commit comments