Skip to content

Commit df8dd8a

Browse files
Squashed commit of the following:
commit d7917ef Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 26 18:37:06 2020 +0200 WiFi lost STA fix commit 768bb7a Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 26 17:40:10 2020 +0200 wifi manual reconnect fix commit b75e271 Author: Emil Muratov <gpm@hotplug.ru> Date: Wed Nov 25 20:29:02 2020 +0300 WiFi status fix - fixed updating WiFi station variable (ESP32) - Interface frame size increased for ESP32 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 98d5eb1 Author: Emil Muratov <gpm@hotplug.ru> Date: Wed Nov 25 01:18:37 2020 +0300 Embed system settings vars/GUI - Add system-related vars to the embui initialization code - Predefined code for "settings' web-page - generic example changed to adopt predefined settings UI Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 86dc340 Author: Emil Muratov <gpm@hotplug.ru> Date: Thu Nov 19 16:55:27 2020 +0300 TimeLib: Workaround for newlib bug with <+-nn> timezone names local WA for both esp8266 and esp32 'till fixed in both core's Fix for 8266 already in master esp8266/Arduino#7702 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit a31bd32 Author: Emil Muratov <gpm@hotplug.ru> Date: Thu Nov 19 02:06:53 2020 +0300 WiFi: ESP32 DHCP WA, reconnection fix - implemented WA for the ESP32 issue espressif/arduino-esp32#2537 - Delayed reconnection, allows websocket to finish section transaction. Fix #1 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit b136f84 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Nov 6 18:47:48 2020 +0200 resources commit f276d20 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 18:21:44 2020 +0200 mqtt critical fix commit fee53ef Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 16:19:42 2020 +0200 mqtt fix commit 803c9b6 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 12:58:19 2020 +0200 resources fix commit be4bcb6 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 12:15:58 2020 +0200 Upload progress fix commit 7e83cfc Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Wed Nov 4 17:47:12 2020 +0200 resources commit 81b3d5c Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Tue Nov 3 14:33:29 2020 +0200 MQTT log fix commit 1584fd8 Author: Emil Muratov <gpm@hotplug.ru> Date: Tue Nov 3 12:13:44 2020 +0300 OTA: esp8266 fix for gzipped fw image Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 208e6ec Merge: 3eff570 da552d7 Author: Emil Muratov <gpm@hotplug.ru> Date: Sat Oct 31 15:24:11 2020 +0300 Merge branch 'dev' of github.com:DmytroKorniienko/EmbUI into emdev commit 3eff570 Author: Emil Muratov <gpm@hotplug.ru> Date: Sat Oct 31 15:21:22 2020 +0300 OTA fix for ESP32 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit da552d7 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 04:32:46 2020 +0200 bugfix mqtt commit cdaf07c Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 00:31:15 2020 +0200 bugfix commit 343649a Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 00:21:38 2020 +0200 getAPmac bugfix commit 0521889 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Oct 30 19:54:46 2020 +0200 bugfix commit 92f2907 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Oct 30 19:43:27 2020 +0200 Fix (lost changes)
1 parent 46519b1 commit df8dd8a

File tree

2 files changed

+314
-0
lines changed

2 files changed

+314
-0
lines changed

EmbUI/basicui.cpp

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
#include "basicui.h"
2+
3+
/**
4+
* Define configuration variables and controls handlers
5+
*
6+
* Variables has literal names and are kept within json-configuration file on flash
7+
* Control handlers are bound by literal name with a particular method. This method is invoked
8+
* by manipulating controls
9+
*
10+
* this method owerrides weak definition in framework
11+
*
12+
*/
13+
void BasicUI::add_sections(){
14+
LOG(println, F("UI: Creating webui vars"));
15+
16+
// variable for UI language (specific to basicui translations)
17+
embui.var_create(FPSTR(P_LANGUAGE), String((uint8_t)lang));
18+
19+
/**
20+
* обработчики действий
21+
*/
22+
// вывод BasicUI секций
23+
embui.section_handle_add(FPSTR(T_SETTINGS), section_settings_frame); // generate "settings" UI section
24+
embui.section_handle_add(FPSTR(T_SH_NETW), block_settings_netw); // generate "network settings" UI section
25+
embui.section_handle_add(FPSTR(T_SH_TIME), block_settings_time); // generate "time settings" UI section
26+
//embui.section_handle_add(FPSTR(T_SH_OTHER), show_settings_other);
27+
28+
// обработка базовых настроек
29+
embui.section_handle_add(FPSTR(T_SET_WIFI), set_settings_wifi); // обработка настроек WiFi Client
30+
embui.section_handle_add(FPSTR(T_SET_WIFIAP), set_settings_wifiAP); // обработка настроек WiFi AP
31+
embui.section_handle_add(FPSTR(T_SET_MQTT), set_settings_mqtt); // обработка настроек MQTT
32+
embui.section_handle_add(FPSTR(T_SET_TIME), set_settings_time); // установки даты/времени
33+
embui.section_handle_add(FPSTR(P_LANGUAGE), set_language); // смена языка интерфейса
34+
35+
//embui.section_handle_add(FPSTR(T_004B), set_settings_other);
36+
}
37+
38+
/**
39+
* This code adds "Settings" section to the MENU
40+
* it is up to you to properly open/close Interface menu json_section
41+
*/
42+
void BasicUI::opt_setup(Interface *interf, JsonObject *data){
43+
if (!interf) return;
44+
interf->option(FPSTR(T_SETTINGS), FPSTR(T_DICT[lang][TD::D_SETTINGS])); // пункт меню "настройки"
45+
}
46+
47+
/**
48+
* формирование секции "настроек",
49+
* вызывается либо по выбору из "меню" либо при вызове из
50+
* других блоков/обработчиков
51+
*
52+
*/
53+
void BasicUI::section_settings_frame(Interface *interf, JsonObject *data){
54+
if (!interf) return;
55+
interf->json_frame_interface(""); // саму секцию целиком не обрабатываем
56+
57+
interf->json_section_main(FPSTR(T_SETTINGS), FPSTR(T_DICT[lang][TD::D_SETTINGS]));
58+
59+
interf->select(FPSTR(P_LANGUAGE), String(lang), String(FPSTR(T_DICT[lang][TD::D_LANG])), true);
60+
interf->option("0", "Rus");
61+
interf->option("1", "Eng");
62+
interf->json_section_end();
63+
64+
interf->spacer();
65+
66+
interf->button(FPSTR(T_SH_NETW), FPSTR(T_DICT[lang][TD::D_WIFI_MQTT])); // кнопка перехода в настройки сети
67+
interf->button(FPSTR(T_SH_TIME), FPSTR(T_DICT[lang][TD::D_Time])); // кнопка перехода в настройки времени
68+
69+
interf->spacer();
70+
block_settings_update(interf, data); // добавляем блок интерфейса "обновления ПО"
71+
72+
interf->json_section_end();
73+
interf->json_frame_flush();
74+
}
75+
76+
/**
77+
* BasicUI блок интерфейса настроек WiFi/MQTT
78+
*/
79+
void BasicUI::block_settings_netw(Interface *interf, JsonObject *data){
80+
if (!interf) return;
81+
interf->json_frame_interface();
82+
83+
// Headline
84+
interf->json_section_main(FPSTR(T_OPT_NETW), FPSTR(T_DICT[lang][TD::D_WIFI_MQTT]));
85+
86+
// форма настроек Wi-Fi Client
87+
interf->json_section_hidden(FPSTR(T_SET_WIFI), FPSTR(T_DICT[lang][TD::D_WiFiClient]));
88+
interf->spacer(FPSTR(T_DICT[lang][TD::D_WiFiClientOpts]));
89+
interf->text(FPSTR(P_hostname), FPSTR(T_DICT[lang][TD::D_Hostname]));
90+
interf->text(FPSTR(P_WCSSID), WiFi.SSID(), FPSTR(T_DICT[lang][TD::D_WiFiSSID]), false);
91+
interf->password(FPSTR(P_WCPASS), "", FPSTR(T_DICT[lang][TD::D_Password]));
92+
interf->button_submit(FPSTR(T_SET_WIFI), FPSTR(T_DICT[lang][TD::D_CONNECT]), FPSTR(P_GRAY));
93+
interf->json_section_end();
94+
95+
// форма настроек Wi-Fi AP
96+
interf->json_section_hidden(FPSTR(T_SET_WIFIAP), FPSTR(T_DICT[lang][TD::D_WiFiAP]));
97+
interf->text(FPSTR(P_hostname), FPSTR(T_DICT[lang][TD::D_Hostname]));
98+
interf->spacer(FPSTR(T_DICT[lang][TD::D_WiFiAPOpts]));
99+
interf->comment(FPSTR(T_DICT[lang][TD::D_MSG_APOnly]));
100+
interf->checkbox(FPSTR(P_APonly), FPSTR(T_DICT[lang][TD::D_APOnlyMode]));
101+
interf->password(FPSTR(P_APpwd), FPSTR(T_DICT[lang][TD::D_MSG_APProtect]));
102+
interf->button_submit(FPSTR(T_SET_WIFIAP), FPSTR(T_DICT[lang][TD::D_SAVE]), FPSTR(P_GRAY));
103+
interf->json_section_end();
104+
105+
// форма настроек MQTT
106+
interf->json_section_hidden(FPSTR(T_SET_MQTT), FPSTR(T_DICT[lang][TD::D_MQTT]));
107+
interf->text(FPSTR(P_m_host), FPSTR(T_DICT[lang][TD::D_MQTT_Host]));
108+
interf->number(FPSTR(P_m_port), FPSTR(T_DICT[lang][TD::D_MQTT_Port]));
109+
interf->text(FPSTR(P_m_user), FPSTR(T_DICT[lang][TD::D_User]));
110+
interf->text(FPSTR(P_m_pass), FPSTR(T_DICT[lang][TD::D_Password]));
111+
interf->text(FPSTR(P_m_pref), FPSTR(T_DICT[lang][TD::D_MQTT_Topic]));
112+
interf->number(FPSTR(P_m_tupd), FPSTR(T_DICT[lang][TD::D_MQTT_Interval]));
113+
interf->button_submit(FPSTR(T_SET_MQTT), FPSTR(T_DICT[lang][TD::D_CONNECT]), FPSTR(P_GRAY));
114+
interf->json_section_end();
115+
116+
interf->spacer();
117+
interf->button(FPSTR(T_SETTINGS), FPSTR(T_DICT[lang][TD::D_EXIT]));
118+
119+
interf->json_section_end();
120+
121+
interf->json_frame_flush();
122+
}
123+
124+
/**
125+
* BasicUI блок загрузки обновлений ПО
126+
*/
127+
void BasicUI::block_settings_update(Interface *interf, JsonObject *data){
128+
if (!interf) return;
129+
interf->json_section_hidden(FPSTR(T_DO_OTAUPD), FPSTR(T_DICT[lang][TD::D_Update]));
130+
interf->spacer(FPSTR(T_DICT[lang][TD::D_FWLOAD]));
131+
interf->file(FPSTR(T_DO_OTAUPD), FPSTR(T_DO_OTAUPD), FPSTR(T_DICT[lang][TD::D_UPLOAD]));
132+
}
133+
134+
/**
135+
* BasicUI блок настройки даты/времени
136+
*/
137+
void BasicUI::block_settings_time(Interface *interf, JsonObject *data){
138+
if (!interf) return;
139+
interf->json_frame_interface();
140+
141+
// Headline
142+
interf->json_section_main(FPSTR(T_SET_TIME), FPSTR(T_DICT[lang][TD::D_DATETIME]));
143+
144+
interf->comment(FPSTR(T_DICT[lang][TD::D_MSG_TZSet01])); // комментарий-описание секции
145+
interf->text(FPSTR(P_TZSET), FPSTR(T_DICT[lang][TD::D_MSG_TZONE]));
146+
interf->text(FPSTR(P_userntp), FPSTR(T_DICT[lang][TD::D_NTP_Secondary]));
147+
interf->text(FPSTR(P_DTIME), "", FPSTR(T_DICT[lang][TD::D_MSG_DATETIME]), false);
148+
interf->button_submit(FPSTR(T_SET_TIME), FPSTR(T_DICT[lang][TD::D_SAVE]), FPSTR(P_GRAY));
149+
150+
interf->spacer();
151+
interf->button(FPSTR(T_SETTINGS), FPSTR(T_DICT[lang][TD::D_EXIT]));
152+
153+
interf->json_section_end();
154+
interf->json_frame_flush();
155+
}
156+
157+
/**
158+
* Обработчик настроек WiFi в режиме клиента
159+
*/
160+
void BasicUI::set_settings_wifi(Interface *interf, JsonObject *data){
161+
if (!data) return;
162+
163+
SETPARAM(FPSTR(P_hostname)); // сохраняем hostname в конфиг
164+
165+
const char *ssid = (*data)[FPSTR(P_WCSSID)]; // переменные доступа в конфиге не храним
166+
const char *pwd = (*data)[FPSTR(P_WCPASS)]; // фреймворк хранит последнюю доступную точку самостоятельно
167+
168+
if(ssid){
169+
embui.wifi_connect(ssid, pwd);
170+
} else {
171+
LOG(println, F("UI WiFi: No SSID defined!"));
172+
}
173+
174+
section_settings_frame(interf, data); // переходим в раздел "настройки"
175+
}
176+
177+
/**
178+
* Обработчик настроек WiFi в режиме AP
179+
*/
180+
void BasicUI::set_settings_wifiAP(Interface *interf, JsonObject *data){
181+
if (!data) return;
182+
183+
SETPARAM(FPSTR(P_hostname)); // эти переменные будут сохранены в конфиг-файл
184+
SETPARAM(FPSTR(P_APonly));
185+
SETPARAM(FPSTR(P_APpwd));
186+
187+
embui.save();
188+
embui.wifi_connect(); // иницируем WiFi-подключение с новыми параметрами
189+
190+
section_settings_frame(interf, data); // переходим в раздел "настройки"
191+
}
192+
193+
/**
194+
* Обработчик настроек MQTT
195+
*/
196+
void BasicUI::set_settings_mqtt(Interface *interf, JsonObject *data){
197+
if (!data) return;
198+
// сохраняем настройки в конфиг
199+
SETPARAM(FPSTR(P_m_host));
200+
SETPARAM(FPSTR(P_m_port));
201+
SETPARAM(FPSTR(P_m_user));
202+
SETPARAM(FPSTR(P_m_pass));
203+
SETPARAM(FPSTR(P_m_pref));
204+
SETPARAM(FPSTR(P_m_tupd));
205+
//SETPARAM(FPSTR(P_m_tupd), some_mqtt_object.semqtt_int((*data)[FPSTR(P_m_tupd)]));
206+
207+
embui.save();
208+
209+
section_settings_frame(interf, data);
210+
}
211+
212+
/**
213+
* Обработчик настроек даты/времени
214+
*/
215+
void BasicUI::set_settings_time(Interface *interf, JsonObject *data){
216+
if (!data) return;
217+
218+
String datetime=(*data)[FPSTR(P_DTIME)];
219+
if (datetime.length())
220+
embui.timeProcessor.setTime(datetime);
221+
SETPARAM(FPSTR(P_TZSET), embui.timeProcessor.tzsetup((*data)[FPSTR(P_TZSET)]));
222+
SETPARAM(FPSTR(P_userntp), embui.timeProcessor.setcustomntp((*data)[FPSTR(P_userntp)]));
223+
224+
section_settings_frame(interf, data);
225+
}
226+
227+
void BasicUI::set_language(Interface *interf, JsonObject *data){
228+
if (!data) return;
229+
230+
//lang = (*data)[FPSTR(P_LANGUAGE)].as<unsigned char>();
231+
SETPARAM(FPSTR(P_LANGUAGE), lang = (*data)[FPSTR(P_LANGUAGE)].as<unsigned char>() );
232+
233+
section_settings_frame(interf, data);
234+
}
235+
236+
void BasicUI::embuistatus(Interface *interf){
237+
if (!interf) return;
238+
interf->json_frame_value();
239+
interf->value(F("pTime"), embui.timeProcessor.getFormattedShortTime(), true);
240+
interf->value(F("pMem"), String(ESP.getFreeHeap()), true);
241+
interf->value(F("pUptime"), String(millis()/1000), true);
242+
interf->json_frame_flush();
243+
}

EmbUI/basicui.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Here is a set of predefined WebUI elements for system settings setup like WiFi, time, MQTT, etc...
3+
*/
4+
#pragma once
5+
6+
#include "ui.h"
7+
#include "i18n.h" // localized GUI text-strings
8+
9+
/**
10+
* List of UI languages in predefined i18n resources
11+
*/
12+
enum LANG : uint8_t {
13+
RU = (0U),
14+
EN = (1U),
15+
};
16+
17+
static uint8_t lang = LANG::RU; // default language for text resources
18+
19+
// UI blocks
20+
static const char T_SETTINGS[] PROGMEM = "settings";
21+
static const char T_OPT_NETW[] PROGMEM = "networking";
22+
23+
// UI handlers
24+
static const char T_DO_OTAUPD[] PROGMEM = "update";
25+
static const char T_SET_WIFI[] PROGMEM = "set_wifi";
26+
static const char T_SET_WIFIAP[] PROGMEM = "set_wifiAP";
27+
static const char T_SET_MQTT[] PROGMEM = "set_mqtt";
28+
static const char T_SET_TIME[] PROGMEM = "set_time";
29+
30+
static const char T_SH_NETW[] PROGMEM = "sh_netw";
31+
static const char T_SH_TIME[] PROGMEM = "sh_time";
32+
33+
/*
34+
A class with static functions to handle basic WebUI interface
35+
*/
36+
class BasicUI {
37+
38+
public:
39+
40+
/**
41+
* Define configuration variables and controls handlers
42+
*
43+
* Variables has literal names and are kept within json-configuration file on flash
44+
* Control handlers are bound by literal name with a particular method. This method is invoked
45+
* by manipulating controls
46+
*
47+
* this method owerrides weak definition in framework
48+
*
49+
*/
50+
static void add_sections();
51+
52+
/**
53+
* This code adds "Settings" section to the MENU
54+
* it is up to you to properly open/close Interface json_section
55+
*/
56+
static void opt_setup(Interface *interf, JsonObject *data);
57+
58+
static void block_settings_netw(Interface *interf, JsonObject *data);
59+
static void block_settings_update(Interface *interf, JsonObject *data);
60+
static void block_settings_time(Interface *interf, JsonObject *data);
61+
62+
static void section_settings_frame(Interface *interf, JsonObject *data);
63+
static void set_settings_wifi(Interface *interf, JsonObject *data);
64+
static void set_settings_wifiAP(Interface *interf, JsonObject *data);
65+
static void set_settings_mqtt(Interface *interf, JsonObject *data);
66+
static void set_settings_time(Interface *interf, JsonObject *data);
67+
static void set_language(Interface *interf, JsonObject *data);
68+
static void embuistatus(Interface *interf);
69+
70+
//uint8_t uploadProgress(size_t len, size_t total);
71+
};

0 commit comments

Comments
 (0)