Skip to content

Commit 208e6ec

Browse files
committed
Merge branch 'dev' of github.com:DmytroKorniienko/EmbUI into emdev
2 parents 3eff570 + da552d7 commit 208e6ec

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

EmbUI/EmbUI.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
#include "MemoryInfo.h"
1111
#endif
1212

13+
#ifndef MAX_WS_CLIENTS
1314
#define MAX_WS_CLIENTS 4
15+
#endif
16+
#ifndef PUB_PERIOD
1417
#define PUB_PERIOD 10000 // Publication period, ms
18+
#endif
1519
#define SECONDARY_PERIOD 300U // second handler timer, ms
1620

1721
// Update defs
@@ -391,8 +395,8 @@ void EmbUI::handle(){
391395
MDNS.update();
392396
#endif
393397
//_connected();
394-
//mqtt_handle();
395-
//udpLoop();
398+
mqtt_handle();
399+
udpLoop();
396400

397401
static unsigned long timer = 0;
398402
if (timer + SECONDARY_PERIOD > millis()) return;

EmbUI/EmbUI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class EmbUI
193193

194194
public:
195195
EmbUI() : cfg(__CFGSIZE), section_handle(), server(80), ws("/ws"){
196-
*mc='\0';
196+
memset(mc,0,sizeof(mc));
197197
}
198198
BITFIELDS sysData;
199199
AsyncWebServer server;

EmbUI/mqtt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ void emptyFunction(const String &, const String &){}
3939

4040
void EmbUI::mqtt(const String &pref, const String &host, int port, const String &user, const String &pass, void (*mqttFunction) (const String &topic, const String &payload), bool remotecontrol){
4141
if (host.length()==0){
42-
Serial.println(F("MQTT host is empty - disabled!"));
43-
return; // выходим если host не задан
42+
LOG(println, PSTR("UI: MQTT host is empty - disabled!"));
43+
return; // выходим если host не задан
4444
}
4545
String m_pref=param(FPSTR(P_m_pref));
4646
String m_host=param(FPSTR(P_m_host));
@@ -56,7 +56,7 @@ void EmbUI::mqtt(const String &pref, const String &host, int port, const String
5656
if(m_user == FPSTR(P_null)) var(FPSTR(P_m_user), user);
5757
if(m_pass == FPSTR(P_null)) var(FPSTR(P_m_pass), pass);
5858

59-
//Serial.println(F("MQTT Init completed"));
59+
LOG(println, PSTR("UI: MQTT Init completed"));
6060

6161
if (remotecontrol) embui.sysData.mqtt_remotecontrol = true;
6262
mqt = mqttFunction;

EmbUI/ui.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
void Interface::frame(const String &id, const String &value){
99
StaticJsonDocument<256> obj;
10+
obj[FPSTR(P_html)] = F("iframe");;
11+
obj[FPSTR(P_type)] = F("frame");
1012
obj[FPSTR(P_id)] = id;
1113
obj[FPSTR(P_value)] = value;
1214

@@ -15,6 +17,18 @@ void Interface::frame(const String &id, const String &value){
1517
}
1618
}
1719

20+
void Interface::frame2(const String &id, const String &value){
21+
StaticJsonDocument<256> obj;
22+
obj[FPSTR(P_html)] = F("iframe2");;
23+
obj[FPSTR(P_type)] = F("frame");
24+
obj[FPSTR(P_id)] = id;
25+
obj[FPSTR(P_value)] = value;
26+
27+
if (!json_frame_add(obj.as<JsonObject>())) {
28+
frame2(id, value);
29+
}
30+
}
31+
1832
void Interface::hidden(const String &id, const String &value){
1933
StaticJsonDocument<256> obj;
2034
obj[FPSTR(P_html)] = FPSTR(P_hidden);

EmbUI/ui.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class Interface {
105105
void json_section_end();
106106

107107
void frame(const String &id, const String &value);
108+
void frame2(const String &id, const String &value);
108109
void value(const String &id, bool html = false);
109110
void value(const String &id, const String &val, bool html = false);
110111
void hidden(const String &id);

EmbUI/wi-fi.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ void EmbUI::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) // , WiFiEventI
111111
void EmbUI::wifi_init(){
112112
String hn = param(FPSTR(P_hostname));
113113
String appwd = param(FPSTR(P_APpwd));
114-
114+
getAPmac();
115115
if (!hn.length()){
116-
getAPmac();
117116
hn = String(__IDPREFIX) + mc;
118117
var(FPSTR(P_hostname), hn, true);
119118
}
@@ -187,13 +186,18 @@ void EmbUI::setup_mDns(){
187186
void EmbUI::getAPmac(){
188187
if(*mc) return;
189188

190-
uint8_t _mac[6];
189+
uint8_t _mac[7];
191190

192191
#ifdef ESP32
192+
// uint64_t chipid = ESP.getEfuseMac();
193+
// memset(_mac,0,sizeof(_mac));
194+
// memcpy(_mac,&chipid,6);
195+
193196
if(WiFi.getMode() == WIFI_MODE_NULL)
194197
WiFi.mode(WIFI_MODE_AP);
195198
#endif
196199
WiFi.softAPmacAddress(_mac);
197200

201+
LOG(printf_P,PSTR("UI MAC:%02X%02X%02X\n"), _mac[3], _mac[4], _mac[5]);
198202
sprintf_P(mc, PSTR("%02X%02X%02X"), _mac[3], _mac[4], _mac[5]);
199-
}
203+
}

0 commit comments

Comments
 (0)