Skip to content

Commit b75e271

Browse files
committed
WiFi status fix
- fixed updating WiFi station variable (ESP32) - Interface frame size increased for ESP32 Signed-off-by: Emil Muratov <gpm@hotplug.ru>
1 parent 98d5eb1 commit b75e271

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

EmbUI/ui.cpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#include "ui.h"
77

8+
#define IFACE_STA_JSON_SIZE 256
9+
810
void Interface::frame(const String &id, const String &value){
9-
StaticJsonDocument<256> obj;
11+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
1012
obj[FPSTR(P_html)] = F("iframe");;
1113
obj[FPSTR(P_type)] = F("frame");
1214
obj[FPSTR(P_id)] = id;
@@ -18,7 +20,7 @@ void Interface::frame(const String &id, const String &value){
1820
}
1921

2022
void Interface::frame2(const String &id, const String &value){
21-
StaticJsonDocument<256> obj;
23+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
2224
obj[FPSTR(P_html)] = F("iframe2");;
2325
obj[FPSTR(P_type)] = F("frame");
2426
obj[FPSTR(P_id)] = id;
@@ -30,7 +32,7 @@ void Interface::frame2(const String &id, const String &value){
3032
}
3133

3234
void Interface::hidden(const String &id, const String &value){
33-
StaticJsonDocument<256> obj;
35+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
3436
obj[FPSTR(P_html)] = FPSTR(P_hidden);
3537
obj[FPSTR(P_id)] = id;
3638
obj[FPSTR(P_value)] = value;
@@ -45,7 +47,7 @@ void Interface::hidden(const String &id){
4547
}
4648

4749
void Interface::constant(const String &id, const String &value, const String &label){
48-
StaticJsonDocument<256> obj;
50+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
4951
obj[FPSTR(P_html)] = F("const");
5052
obj[FPSTR(P_id)] = id;
5153
obj[FPSTR(P_value)] = value;
@@ -61,7 +63,7 @@ void Interface::constant(const String &id, const String &label){
6163
}
6264

6365
void Interface::text(const String &id, const String &value, const String &label, bool directly){
64-
StaticJsonDocument<256> obj;
66+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
6567
obj[FPSTR(P_html)] = FPSTR(P_input);
6668
obj[FPSTR(P_type)] = F("text");
6769
obj[FPSTR(P_id)] = id;
@@ -80,7 +82,7 @@ void Interface::text(const String &id, const String &label, bool directly){
8082
}
8183

8284
void Interface::number(const String &id, int value, const String &label, int min, int max){
83-
StaticJsonDocument<256> obj;
85+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
8486
obj[FPSTR(P_html)] = FPSTR(P_input);
8587
obj[FPSTR(P_type)] = FPSTR(P_number);
8688
obj[FPSTR(P_id)] = id;
@@ -99,7 +101,7 @@ void Interface::number(const String &id, const String &label, int min, int max){
99101
}
100102

101103
void Interface::number(const String &id, float value, const String &label, float step, int min, int max){
102-
StaticJsonDocument<256> obj;
104+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
103105
obj[FPSTR(P_html)] = FPSTR(P_input);
104106
obj[FPSTR(P_type)] = FPSTR(P_number);
105107
obj[FPSTR(P_id)] = id;
@@ -119,7 +121,7 @@ void Interface::number(const String &id, const String &label, float step, int mi
119121
}
120122

121123
void Interface::time(const String &id, const String &value, const String &label){
122-
StaticJsonDocument<256> obj;
124+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
123125
obj[FPSTR(P_html)] = FPSTR(P_input);
124126
obj[FPSTR(P_type)] = FPSTR(P_time);
125127
obj[FPSTR(P_id)] = id;
@@ -136,7 +138,7 @@ void Interface::time(const String &id, const String &label){
136138
}
137139

138140
void Interface::date(const String &id, const String &value, const String &label){
139-
StaticJsonDocument<256> obj;
141+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
140142
obj[FPSTR(P_html)] = FPSTR(P_input);
141143
obj[FPSTR(P_type)] = FPSTR(P_date);
142144
obj[FPSTR(P_id)] = id;
@@ -153,7 +155,7 @@ void Interface::date(const String &id, const String &label){
153155
}
154156

155157
void Interface::datetime(const String &id, const String &value, const String &label){
156-
StaticJsonDocument<256> obj;
158+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
157159
obj[FPSTR(P_html)] = FPSTR(P_input);
158160
obj[FPSTR(P_type)] = F("datetime-local");
159161
obj[FPSTR(P_id)] = id;
@@ -170,7 +172,7 @@ void Interface::datetime(const String &id, const String &label){
170172
}
171173

172174
void Interface::range(const String &id, int value, int min, int max, float step, const String &label, bool directly){
173-
StaticJsonDocument<256> obj;
175+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
174176
obj[FPSTR(P_html)] = FPSTR(P_input);
175177
obj[FPSTR(P_type)] = F("range");
176178
obj[FPSTR(P_id)] = id;
@@ -192,7 +194,7 @@ void Interface::range(const String &id, int min, int max, float step, const Stri
192194
}
193195

194196
void Interface::email(const String &id, const String &value, const String &label){
195-
StaticJsonDocument<256> obj;
197+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
196198
obj[FPSTR(P_html)] = FPSTR(P_input);
197199
obj[FPSTR(P_type)] = F("email");
198200
obj[FPSTR(P_id)] = id;
@@ -209,7 +211,7 @@ void Interface::email(const String &id, const String &label){
209211
}
210212

211213
void Interface::password(const String &id, const String &value, const String &label){
212-
StaticJsonDocument<256> obj;
214+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
213215
obj[FPSTR(P_html)] = FPSTR(P_input);
214216
obj[FPSTR(P_type)] = FPSTR(P_password);
215217
obj[FPSTR(P_id)] = id;
@@ -226,7 +228,7 @@ void Interface::password(const String &id, const String &label){
226228
}
227229

228230
void Interface::option(const String &value, const String &label){
229-
StaticJsonDocument<256> obj;
231+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
230232
obj[FPSTR(P_label)] = label;
231233
obj[FPSTR(P_value)] = value;
232234

@@ -236,7 +238,7 @@ void Interface::option(const String &value, const String &label){
236238
}
237239

238240
void Interface::select(const String &id, const String &value, const String &label, bool directly, bool skiplabel){
239-
StaticJsonDocument<256> obj;
241+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
240242
obj[FPSTR(P_html)] = F("select");
241243
obj[FPSTR(P_id)] = id;
242244
obj[FPSTR(P_value)] = value;
@@ -256,7 +258,7 @@ void Interface::select(const String &id, const String &label, bool directly, boo
256258
}
257259

258260
void Interface::checkbox(const String &id, const String &value, const String &label, bool directly){
259-
StaticJsonDocument<256> obj;
261+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
260262
obj[FPSTR(P_html)] = FPSTR(P_input);
261263
obj[FPSTR(P_type)] = F("checkbox");
262264
obj[FPSTR(P_id)] = id;
@@ -274,7 +276,7 @@ void Interface::checkbox(const String &id, const String &label, bool directly){
274276
}
275277

276278
void Interface::color(const String &id, const String &value, const String &label){
277-
StaticJsonDocument<256> obj;
279+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
278280
obj[FPSTR(P_html)] = FPSTR(P_input);
279281
obj[FPSTR(P_type)] = FPSTR(P_color);
280282
obj[FPSTR(P_id)] = id;
@@ -291,7 +293,7 @@ void Interface::color(const String &id, const String &label){
291293
}
292294

293295
void Interface::file(const String &name, const String &action, const String &label){
294-
StaticJsonDocument<256> obj;
296+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
295297
obj[FPSTR(P_html)] = FPSTR(P_file);
296298
obj[F("name")] = name;
297299
obj[F("action")] = action;
@@ -303,7 +305,7 @@ void Interface::file(const String &name, const String &action, const String &lab
303305
}
304306

305307
void Interface::button(const String &id, const String &label, const String &color){
306-
StaticJsonDocument<256> obj;
308+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
307309
obj[FPSTR(P_html)] = FPSTR(P_button);
308310
obj[FPSTR(P_id)] = id;
309311
obj[FPSTR(P_color)] = color;
@@ -315,7 +317,7 @@ void Interface::button(const String &id, const String &label, const String &colo
315317
}
316318

317319
void Interface::button_submit(const String &section, const String &label, const String &color){
318-
StaticJsonDocument<256> obj;
320+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
319321
obj[FPSTR(P_html)] = FPSTR(P_button);
320322
obj[FPSTR(P_submit)] = section;
321323
obj[FPSTR(P_color)] = color;
@@ -327,7 +329,7 @@ void Interface::button_submit(const String &section, const String &label, const
327329
}
328330

329331
void Interface::button_submit_value(const String &section, const String &value, const String &label, const String &color){
330-
StaticJsonDocument<256> obj;
332+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
331333
obj[FPSTR(P_html)] = FPSTR(P_button);
332334
obj[FPSTR(P_submit)] = section;
333335
obj[FPSTR(P_color)] = color;
@@ -340,7 +342,7 @@ void Interface::button_submit_value(const String &section, const String &value,
340342
}
341343

342344
void Interface::spacer(const String &label){
343-
StaticJsonDocument<256> obj;
345+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
344346
obj[FPSTR(P_html)] = F("spacer");
345347
if (label != "") obj[FPSTR(P_label)] = label;
346348

@@ -350,7 +352,7 @@ void Interface::spacer(const String &label){
350352
}
351353

352354
void Interface::comment(const String &label){
353-
StaticJsonDocument<512> obj;
355+
StaticJsonDocument<IFACE_STA_JSON_SIZE * 2> obj;
354356
obj[FPSTR(P_html)] = F("comment");
355357
if (label != "") obj[FPSTR(P_label)] = label;
356358

@@ -360,7 +362,7 @@ void Interface::comment(const String &label){
360362
}
361363

362364
void Interface::textarea(const String &id, const String &value, const String &label){
363-
StaticJsonDocument<256> obj;
365+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
364366
obj[FPSTR(P_html)] = F("textarea");
365367
obj[FPSTR(P_id)] = id;
366368
obj[FPSTR(P_value)] = value;
@@ -376,7 +378,7 @@ void Interface::textarea(const String &id, const String &label){
376378
}
377379

378380
void Interface::value(const String &id, const String &val, bool html){
379-
StaticJsonDocument<256> obj;
381+
StaticJsonDocument<IFACE_STA_JSON_SIZE> obj;
380382
obj[FPSTR(P_id)] = id;
381383
obj[FPSTR(P_value)] = val;
382384
if (html) obj[FPSTR(P_html)] = true;
@@ -417,7 +419,7 @@ bool Interface::json_frame_add(JsonObject obj) {
417419
LOG(printf_P, PSTR("UI: OK [%u]\tMEM: %u\n"), section_stack.end()->idx, ESP.getFreeHeap());
418420
return true;
419421
}
420-
LOG(printf_P, PSTR("UI: BAD MEM: %u\n"), ESP.getFreeHeap());
422+
LOG(printf_P, PSTR("UI: Frame full, mem: %u\n"), ESP.getFreeHeap());
421423

422424
json_frame_send();
423425
json_frame_next();

EmbUI/ui.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
#include "EmbUI.h"
1010

11+
#ifdef ESP8266
12+
#define IFACE_DYN_JSON_SIZE 3073
13+
#elif defined ESP32
14+
#define IFACE_DYN_JSON_SIZE 8192
15+
#endif
16+
17+
1118
class frameSend {
1219
public:
1320
virtual ~frameSend(){};
@@ -66,15 +73,15 @@ class Interface {
6673
EmbUI *embui;
6774

6875
public:
69-
Interface(EmbUI *j, AsyncWebSocket *server, size_t size = 3000): json(size), section_stack(){
76+
Interface(EmbUI *j, AsyncWebSocket *server, size_t size = IFACE_DYN_JSON_SIZE): json(size), section_stack(){
7077
embui = j;
7178
send_hndl = new frameSendAll(server);
7279
}
73-
Interface(EmbUI *j, AsyncWebSocketClient *client, size_t size = 3000): json(size), section_stack(){
80+
Interface(EmbUI *j, AsyncWebSocketClient *client, size_t size = IFACE_DYN_JSON_SIZE): json(size), section_stack(){
7481
embui = j;
7582
send_hndl = new frameSendClient(client);
7683
}
77-
Interface(EmbUI *j, AsyncWebServerRequest *request, size_t size = 3000): json(size), section_stack(){
84+
Interface(EmbUI *j, AsyncWebServerRequest *request, size_t size = IFACE_DYN_JSON_SIZE): json(size), section_stack(){
7885
embui = j;
7986
send_hndl = new frameSendHttp(request);
8087
}

EmbUI/wi-fi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void EmbUI::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
100100
}
101101

102102
embuischedw.detach();
103+
sysData.wifi_sta = true;
103104
setup_mDns();
104105
if(_cb_STAGotIP)
105106
_cb_STAGotIP(); // execule callback
@@ -114,6 +115,7 @@ void EmbUI::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
114115
embuischedw.detach();} );
115116
}
116117

118+
sysData.wifi_sta = false;
117119
if(_cb_STADisconnected)
118120
_cb_STADisconnected(); // execule callback
119121
break;

0 commit comments

Comments
 (0)