From d0f2c82ee5dbd97cb496a2b074d12d45247539dc Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 7 Nov 2023 01:49:55 +0700 Subject: [PATCH 01/11] html design file form web config --- src/ota_html/config.html | 221 +++++++++++++++++++++++++++++++++++++++ src/ota_html/ota.html | 176 +++++++++++++++++++++++++++++++ 2 files changed, 397 insertions(+) create mode 100644 src/ota_html/config.html create mode 100644 src/ota_html/ota.html diff --git a/src/ota_html/config.html b/src/ota_html/config.html new file mode 100644 index 0000000..d5531ee --- /dev/null +++ b/src/ota_html/config.html @@ -0,0 +1,221 @@ + +
+

ESPMega PRO

+

Device Configurations

+

IP Address

+
+

Network Mask

+
+

Gateway

+
+

DNS Server

+
+

Hostname

+
+

BMS Server - IP Address

+
+

BMS Server - Port

+
+ +

BMS Server - Username

+
+

BMS Server - Password

+
+

BMS Server - Endpoint

+
+ + SIWAT SYSTEM 2023 +
+ + \ No newline at end of file diff --git a/src/ota_html/ota.html b/src/ota_html/ota.html new file mode 100644 index 0000000..fa3878d --- /dev/null +++ b/src/ota_html/ota.html @@ -0,0 +1,176 @@ + +
+

ESPMega PRO

+

Device Information

+

+ Hostname + ESPMegaDemo0 +

+

+ IP Address + 192.168.0.243 +

+

+ MAC Address + B0:A7:32:07:FC:B3 +

+

+ Device + ESPMega PRO R3.3b +

+

+ API Server + 192.168.0.26 +

+

+ API Endpoint + /facescan +

+

+ Centrally Managed + Yes +

+

+
+

Upload Software Package

+ + +

+
+
+
+
+
+
+ SIWAT SYSTEM 2023 +
+ + \ No newline at end of file From a90805b1719475c6e090a8a7e18d12f67b5223d6 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 7 Nov 2023 12:19:35 +0700 Subject: [PATCH 02/11] microcontroller mqtt auth storage --- src/espmega_iot_core.cpp | 62 ++++++++++++++++++++++++++++------------ src/espmega_iot_core.hpp | 9 +++++- src/ota_html/config.html | 2 +- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 5714960..60fe25f 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -18,11 +18,9 @@ bool standalone = true; char MQTT_BASE_TOPIC[20]; uint8_t base_topic_length = 0; char STATE_REQUEST_TOPIC[40]; -// #define MQTT_USE_AUTH -#ifdef MQTT_USE_AUTH -const char MQTT_USERNAME[] = "username"; -const char MQTT_PASSWORD[] = "password"; -#endif +bool MQTT_USE_AUTH = false; +char MQTT_USERNAME[32]; +char MQTT_PASSWORD[32]; uint8_t utc_offset = 7; float current_room_temp = 0; float current_room_humid = 0; @@ -73,19 +71,22 @@ char AC_ROOM_TEMPERATURE_TOPIC[75]; char AC_HUMIDITY_TOPIC[75]; // EEPROM ADDRESS -#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes -#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes -#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes -#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 -#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 -#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 -#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 -#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 -#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 -#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 -#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 -#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 -#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 +#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes +#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes +#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes +#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 +#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 +#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 +#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 +#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 +#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 +#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 +#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 +#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 +#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 +#define EEPROM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153 +#define EEPROM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185 +#define EEPROM_ADDRESS_MQTT_USEAUTH 186 // 1bytes char PWM_STATE_TOPIC[75]; char PWM_VALUE_TOPIC[75]; @@ -203,6 +204,9 @@ void eeprom_retrieve_init() MQTT_SERVER = eeprom_ip_retrieve(EEPROM_ADDRESS_MQTT_SERVER); eeprom_hostname_retrieve(); eeprom_mqtt_port_retrieve(); + eeprom_mqtt_useauth_retrieve(); + eeprom_mqtt_username_retrieve(); + eeprom_mqtt_password_retrieve(); mqtt_client.setServer(MQTT_SERVER, MQTT_PORT); eeprom_basetopic_retrieve(); base_topic_length = strlen(MQTT_BASE_TOPIC) + 1; @@ -1077,4 +1081,26 @@ uint8_t ac_get_mode() uint8_t ac_get_fan_speed() { return ac_fan_speed; +} + +void eeprom_mqtt_username_retrieve() { + ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32); +} +void eeprom_mqtt_password_retrieve() { + ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 32); +} +void set_mqtt_username(String username) { + username.toCharArray(MQTT_USERNAME,32); + ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 20); +} +void set_mqtt_password(String password) { + password.toCharArray(MQTT_PASSWORD,32); + ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20); +} +void eeprom_mqtt_useauth_retrieve() { + MQTT_USE_AUTH = ESPMega_FRAM.read8(EEPROM_ADDRESS_MQTT_USEAUTH); +} +void set_mqtt_useauth(bool use_auth) { + MQTT_USE_AUTH = use_auth; + ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH); } \ No newline at end of file diff --git a/src/espmega_iot_core.hpp b/src/espmega_iot_core.hpp index 6acc508..b19ace1 100644 --- a/src/espmega_iot_core.hpp +++ b/src/espmega_iot_core.hpp @@ -78,6 +78,7 @@ void trigger11(); void trigger12(); void trigger13(); void trigger14(); +void trigger15(); void eeprom_retrieve_init(); void eeprom_pwm_update(); @@ -97,4 +98,10 @@ void eeprom_hostname_retrieve(); void set_basetopic(String topic); void eeprom_basetopic_retrieve(); void mqtt_port_set(uint16_t port); -void eeprom_mqtt_port_retrieve(); \ No newline at end of file +void eeprom_mqtt_port_retrieve(); +void eeprom_mqtt_username_retrieve(); +void eeprom_mqtt_password_retrieve(); +void set_mqtt_username(String username); +void set_mqtt_password(String password); +void eeprom_mqtt_useauth_retrieve(); +void set_mqtt_useauth(bool use_auth); \ No newline at end of file diff --git a/src/ota_html/config.html b/src/ota_html/config.html index d5531ee..38bfdc3 100644 --- a/src/ota_html/config.html +++ b/src/ota_html/config.html @@ -17,7 +17,7 @@

BMS Server - Port


BMS Server - Username

From 897d8694e164415e4a301ba398570afa119c1bae Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 7 Nov 2023 15:49:11 +0700 Subject: [PATCH 03/11] mqtt authentication --- src/espmega_iot_core.cpp | 94 ++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 60fe25f..d336ada 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -71,22 +71,22 @@ char AC_ROOM_TEMPERATURE_TOPIC[75]; char AC_HUMIDITY_TOPIC[75]; // EEPROM ADDRESS -#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes -#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes -#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes -#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 -#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 -#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 -#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 -#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 -#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 -#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 -#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 -#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 -#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 -#define EEPROM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153 -#define EEPROM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185 -#define EEPROM_ADDRESS_MQTT_USEAUTH 186 // 1bytes +#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes +#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes +#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes +#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 +#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 +#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 +#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 +#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 +#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 +#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 +#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 +#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 +#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 +#define EEPROM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153 +#define EEPROM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185 +#define EEPROM_ADDRESS_MQTT_USEAUTH 186 // 1bytes char PWM_STATE_TOPIC[75]; char PWM_VALUE_TOPIC[75]; @@ -349,11 +349,10 @@ void mqtt_connect() { Serial.print("MQTT not connected, connecting . . .\n"); lcd_send_stop_bit(); -#ifdef MQTT_USE_AUTH - mqtt_client.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD); -#else - mqtt_client.connect(HOSTNAME); -#endif + if (MQTT_USE_AUTH) + mqtt_client.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD); + else + mqtt_client.connect(HOSTNAME); if (mqtt_client.connected()) { mqtt_subscribe(); @@ -835,10 +834,15 @@ void lcd_refresh() panel.writeStr("netmask_set.txt", SUBNET.toString()); panel.writeStr("gateway_set.txt", GATEWAY.toString()); panel.writeStr("dns_set.txt", DNS.toString()); - panel.writeStr("mqttsv_set.txt", MQTT_SERVER.toString()); panel.writeStr("host_set.txt", HOSTNAME); + break; + case 11: + panel.writeStr("mqttsv_set.txt", MQTT_SERVER.toString()); panel.writeNum("port_set.val", MQTT_PORT); panel.writeStr("topic_set.txt", MQTT_BASE_TOPIC); + panel.writeStr("user_set.txt", MQTT_USERNAME); + panel.writeStr("password_set.txt",MQTT_PASSWORD); + panel.writeNum("use_auth.val",MQTT_USE_AUTH); break; default: break; @@ -953,20 +957,30 @@ void trigger13() set_netmask(panel.readStr("netmask_set.txt")); set_gw(panel.readStr("gateway_set.txt")); set_dns(panel.readStr("dns_set.txt")); - set_mqtt_server(panel.readStr("mqttsv_set.txt")); set_hostname(panel.readStr("host_set.txt")); - set_basetopic(panel.readStr("topic_set.txt")); - uint16_t port = panel.readNumber("port_set.val"); - mqtt_port_set(port); delay(100); ESP.restart(); } -void trigger14() { +void trigger14() +{ Serial.print("page dashboard"); lcd_send_stop_bit(); } +void trigger15() +{ + set_mqtt_server(panel.readStr("mqttsv_set.txt")); + set_basetopic(panel.readStr("topic_set.txt")); + uint16_t port = panel.readNumber("port_set.val"); + mqtt_port_set(port); + set_mqtt_useauth(panel.readNumber("use_auth.val")); + set_mqtt_username(panel.readStr("user_set.txt")); + set_mqtt_password(panel.readStr("password_set.txt")); + delay(100); + ESP.restart(); +} + void eeprom_pwm_update() { if (memcmp(pwm_states, pwm_states_eeprom, 16)) @@ -1083,24 +1097,30 @@ uint8_t ac_get_fan_speed() return ac_fan_speed; } -void eeprom_mqtt_username_retrieve() { - ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32); +void eeprom_mqtt_username_retrieve() +{ + ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32); } -void eeprom_mqtt_password_retrieve() { +void eeprom_mqtt_password_retrieve() +{ ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 32); } -void set_mqtt_username(String username) { - username.toCharArray(MQTT_USERNAME,32); +void set_mqtt_username(String username) +{ + username.toCharArray(MQTT_USERNAME, 32); ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 20); } -void set_mqtt_password(String password) { - password.toCharArray(MQTT_PASSWORD,32); - ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20); +void set_mqtt_password(String password) +{ + password.toCharArray(MQTT_PASSWORD, 32); + ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20); } -void eeprom_mqtt_useauth_retrieve() { +void eeprom_mqtt_useauth_retrieve() +{ MQTT_USE_AUTH = ESPMega_FRAM.read8(EEPROM_ADDRESS_MQTT_USEAUTH); } -void set_mqtt_useauth(bool use_auth) { +void set_mqtt_useauth(bool use_auth) +{ MQTT_USE_AUTH = use_auth; ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH); } \ No newline at end of file From 1128de9297377a9cfd75dda0bb1601721ed8511d Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 7 Nov 2023 16:03:46 +0700 Subject: [PATCH 04/11] new OTA page --- src/espmega_iot_core.cpp | 11 +- src/espmega_iot_ota.cpp | 25 ++-- src/espmega_iot_ota.hpp | 9 +- src/ota_html/config copy.html | 188 ++++++++++++++++++++++++++++++ src/ota_html/config.html | 33 ------ src/ota_html/ota-part1.html | 6 +- src/ota_html/ota-part2-1_itr.html | 1 + src/ota_html/ota-part2-2_itr.html | 1 + src/ota_html/ota-part2-3_itr.html | 2 + src/ota_html/ota-part2.html | 5 - src/ota_html/ota-part3.html | 149 ++++++++++++++++++++++- src/ota_html/ota-part4.html | 5 - src/ota_html/ota-part5.html | 5 - src/ota_html/ota-part6.html | 5 - src/ota_html/ota-part7.html | 5 - src/ota_html/ota-part8.html | 125 -------------------- 16 files changed, 357 insertions(+), 218 deletions(-) create mode 100644 src/ota_html/config copy.html create mode 100644 src/ota_html/ota-part2-1_itr.html create mode 100644 src/ota_html/ota-part2-2_itr.html create mode 100644 src/ota_html/ota-part2-3_itr.html delete mode 100644 src/ota_html/ota-part2.html delete mode 100644 src/ota_html/ota-part4.html delete mode 100644 src/ota_html/ota-part5.html delete mode 100644 src/ota_html/ota-part6.html delete mode 100644 src/ota_html/ota-part7.html delete mode 100644 src/ota_html/ota-part8.html diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index d336ada..a7f2fae 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -245,12 +245,19 @@ void ota_begin() otaserver.on("/", HTTP_GET, []() { otaserver.sendHeader("Connection", "close"); - String otabuffer = ota_part1+HOSTNAME+ota_part2+IP.toString()+ota_part3+ETH.macAddress()+ota_part4+ESPMEGA_REV+ota_part5+MQTT_SERVER.toString()+ota_part6+String(MQTT_BASE_TOPIC)+ota_part7; + String otabuffer = ota_part1; + otabuffer+=ota_part2_1+"Hostname"+ota_part2_2+String(HOSTNAME)+ota_part2_3; + otabuffer+=ota_part2_1+"IP Address"+ota_part2_2+IP.toString()+ota_part2_3; + otabuffer+=ota_part2_1+"MAC Address"+ota_part2_2+ETH.macAddress()+ota_part2_3; + otabuffer+=ota_part2_1+"Device"+ota_part2_2+ESPMEGA_REV+ota_part2_3; + otabuffer+=ota_part2_1+"BMS Server"+ota_part2_2+MQTT_SERVER.toString()+ota_part2_3; + otabuffer+=ota_part2_1+"BMS Endpoint"+ota_part2_2+String(MQTT_BASE_TOPIC)+ota_part2_3; + otabuffer+=ota_part2_1+"Centrally Managed"+ota_part2_2; if(standalone) otabuffer+=String("No"); else otabuffer+=String("Yes"); - otabuffer+=ota_part8; + otabuffer+=ota_part2_3+ota_part3; otaserver.send(200, "text/html", otabuffer); }); otaserver.on( "/update", HTTP_POST, []() diff --git a/src/espmega_iot_ota.cpp b/src/espmega_iot_ota.cpp index 282ffd5..f3f1682 100644 --- a/src/espmega_iot_ota.cpp +++ b/src/espmega_iot_ota.cpp @@ -3,24 +3,15 @@ const String ota_part1 = { #include "ota_html/ota-part1.html" }; -const String ota_part2 = { -#include "ota_html/ota-part2.html" +const String ota_part2_1 = { +#include "ota_html/ota-part2-1_itr.html" +}; +const String ota_part2_2 = { +#include "ota_html/ota-part2-2_itr.html" +}; +const String ota_part2_3 = { +#include "ota_html/ota-part2-3_itr.html" }; const String ota_part3 = { #include "ota_html/ota-part3.html" -}; -const String ota_part4 = { -#include "ota_html/ota-part4.html" -}; -const String ota_part5 = { -#include "ota_html/ota-part5.html" -}; -const String ota_part6 = { -#include "ota_html/ota-part6.html" -}; -const String ota_part7 = { -#include "ota_html/ota-part7.html" -}; -const String ota_part8 = { -#include "ota_html/ota-part8.html" }; \ No newline at end of file diff --git a/src/espmega_iot_ota.hpp b/src/espmega_iot_ota.hpp index 8ca414b..01f62dd 100644 --- a/src/espmega_iot_ota.hpp +++ b/src/espmega_iot_ota.hpp @@ -1,10 +1,7 @@ #pragma once #include extern const String ota_part1; -extern const String ota_part2; +extern const String ota_part2_1; +extern const String ota_part2_2; +extern const String ota_part2_3; extern const String ota_part3; -extern const String ota_part4; -extern const String ota_part5; -extern const String ota_part6; -extern const String ota_part7; -extern const String ota_part8; \ No newline at end of file diff --git a/src/ota_html/config copy.html b/src/ota_html/config copy.html new file mode 100644 index 0000000..eaacb2f --- /dev/null +++ b/src/ota_html/config copy.html @@ -0,0 +1,188 @@ + +
+

ESPMega PRO

+

Device Configurations

+

IP Address

+
+

Network Mask

+
+

Gateway

+
+

DNS Server

+
+

Hostname

+
+

BMS Server - IP Address

+
+

BMS Server - Port

+
+ +

BMS Server - Username

+
+

BMS Server - Password

+
+

BMS Server - Endpoint

+
+ + SIWAT SYSTEM 2023 +
+ \ No newline at end of file diff --git a/src/ota_html/config.html b/src/ota_html/config.html index 38bfdc3..eaacb2f 100644 --- a/src/ota_html/config.html +++ b/src/ota_html/config.html @@ -29,32 +29,6 @@ SIWAT SYSTEM 2023 - )=====" \ No newline at end of file diff --git a/src/ota_html/ota-part4.html b/src/ota_html/ota-part4.html deleted file mode 100644 index 76b974c..0000000 --- a/src/ota_html/ota-part4.html +++ /dev/null @@ -1,5 +0,0 @@ -R"=====( -

-

- Device - )=====" \ No newline at end of file diff --git a/src/ota_html/ota-part5.html b/src/ota_html/ota-part5.html deleted file mode 100644 index d7745f3..0000000 --- a/src/ota_html/ota-part5.html +++ /dev/null @@ -1,5 +0,0 @@ -R"=====( -

-

- API Server - )=====" \ No newline at end of file diff --git a/src/ota_html/ota-part6.html b/src/ota_html/ota-part6.html deleted file mode 100644 index 743ba2a..0000000 --- a/src/ota_html/ota-part6.html +++ /dev/null @@ -1,5 +0,0 @@ -R"=====( -

-

- API Endpoint - )=====" \ No newline at end of file diff --git a/src/ota_html/ota-part7.html b/src/ota_html/ota-part7.html deleted file mode 100644 index 567deb3..0000000 --- a/src/ota_html/ota-part7.html +++ /dev/null @@ -1,5 +0,0 @@ -R"=====( -

-

- Centrally Managed - )=====" \ No newline at end of file diff --git a/src/ota_html/ota-part8.html b/src/ota_html/ota-part8.html deleted file mode 100644 index 4f94bee..0000000 --- a/src/ota_html/ota-part8.html +++ /dev/null @@ -1,125 +0,0 @@ -R"=====( -

- - - -

-
-
-
-
-
-
-SIWAT SYSTEM 2023 - - -)=====" \ No newline at end of file From 7ecd60107383c2e36e8f8e9a7821d6b1842102c2 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 7 Nov 2023 16:46:47 +0700 Subject: [PATCH 05/11] configuration page --- src/espmega_iot_core.cpp | 19 +++++++++ src/espmega_iot_ota.cpp | 31 +++++++++++++++ src/espmega_iot_ota.hpp | 10 +++++ src/ota_html/config-auth-part1.html | 2 + src/ota_html/config-auth-part2.html | 3 ++ src/ota_html/config-part1.html | 4 ++ .../{config copy.html => config-part2.html} | 39 +++++-------------- src/ota_html/config-textfield-part1.html | 1 + src/ota_html/config-textfield-part2.html | 2 + src/ota_html/config-textfield-part3.html | 1 + src/ota_html/config-textfield-part4.html | 1 + src/ota_html/config-textfield-part5.html | 1 + src/ota_html/config-textfield-part6.html | 1 + src/ota_html/config.html | 10 +++++ src/ota_html/ota-part3.html | 2 +- src/ota_html/ota.html | 2 +- 16 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 src/ota_html/config-auth-part1.html create mode 100644 src/ota_html/config-auth-part2.html create mode 100644 src/ota_html/config-part1.html rename src/ota_html/{config copy.html => config-part2.html} (58%) create mode 100644 src/ota_html/config-textfield-part1.html create mode 100644 src/ota_html/config-textfield-part2.html create mode 100644 src/ota_html/config-textfield-part3.html create mode 100644 src/ota_html/config-textfield-part4.html create mode 100644 src/ota_html/config-textfield-part5.html create mode 100644 src/ota_html/config-textfield-part6.html diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index a7f2fae..1975ded 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -259,6 +259,25 @@ void ota_begin() otabuffer+=String("Yes"); otabuffer+=ota_part2_3+ota_part3; otaserver.send(200, "text/html", otabuffer); }); + otaserver.on("/config", HTTP_GET, []() + { + otaserver.sendHeader("Connection", "close"); + String configbuffer = config_part1; + configbuffer += config_part1; + configbuffer+=config_txt_part1+"IP Address"+config_txt_part2+"text"+config_txt_part3+"dev_ip"+config_txt_part4+"dev_ip"+config_txt_part5+IP.toString()+config_txt_part6; + configbuffer+=config_txt_part1+"Network Mask"+config_txt_part2+"text"+config_txt_part3+"netmask"+config_txt_part4+"netmask"+config_txt_part5+IP.toString()+config_txt_part6; + configbuffer+=config_txt_part1+"Gateway"+config_txt_part2+"text"+config_txt_part3+"gateway"+config_txt_part4+"gateway"+config_txt_part5+GATEWAY.toString()+config_txt_part6; + configbuffer+=config_txt_part1+"DNS Server"+config_txt_part2+"text"+config_txt_part3+"dns"+config_txt_part4+"dns"+config_txt_part5+DNS.toString()+config_txt_part6; + configbuffer+=config_txt_part1+"Hostname"+config_txt_part2+"text"+config_txt_part3+"hostname"+config_txt_part4+"hostname"+config_txt_part5+String(HOSTNAME)+config_txt_part6; + configbuffer+=config_txt_part1+"BMS Server - IP Address"+config_txt_part2+"text"+config_txt_part3+"bms_ip"+config_txt_part4+"bms_ip"+config_txt_part5+MQTT_SERVER.toString()+config_txt_part6; + configbuffer+=config_txt_part1+"BMS Server - Port"+config_txt_part2+"text"+config_txt_part3+"bms_port"+config_txt_part4+"bms_port"+config_txt_part5+String(MQTT_PORT)+config_txt_part6; + configbuffer+=config_auth_part1+(MQTT_USE_AUTH?"yes":"no")+config_auth_part2; + configbuffer+=config_txt_part1+"BMS Server - Username"+config_txt_part2+"text"+config_txt_part3+"bms_username"+config_txt_part4+"bms_username"+config_txt_part5+String(MQTT_USERNAME)+config_txt_part6; + configbuffer+=config_txt_part1+"BMS Server - Password"+config_txt_part2+"password"+config_txt_part3+"bms_password"+config_txt_part4+"bms_password"+config_txt_part5+String(MQTT_PASSWORD)+config_txt_part6; + configbuffer+=config_txt_part1+"BMS Server - Endpoint"+config_txt_part2+"text"+config_txt_part3+"bms_endpoint"+config_txt_part4+"bms_endpoint"+config_txt_part5+String(MQTT_BASE_TOPIC)+config_txt_part6; + configbuffer+=config_part2; + otaserver.send(200, "text/html", configbuffer); }); + otaserver.on( "/update", HTTP_POST, []() { diff --git a/src/espmega_iot_ota.cpp b/src/espmega_iot_ota.cpp index f3f1682..3c67154 100644 --- a/src/espmega_iot_ota.cpp +++ b/src/espmega_iot_ota.cpp @@ -14,4 +14,35 @@ const String ota_part2_3 = { }; const String ota_part3 = { #include "ota_html/ota-part3.html" +}; + +const String config_part1 = { +#include "ota_html/config-part1.html" +}; +const String config_part2 = { +#include "ota_html/config-part2.html" +}; +const String config_txt_part1 = { +#include "ota_html/config-textfield-part1.html" +}; +const String config_txt_part2 = { +#include "ota_html/config-textfield-part2.html" +}; +const String config_txt_part3 = { +#include "ota_html/config-textfield-part3.html" +}; +const String config_txt_part4 = { +#include "ota_html/config-textfield-part4.html" +}; +const String config_txt_part5 = { +#include "ota_html/config-textfield-part5.html" +}; +const String config_txt_part6 = { +#include "ota_html/config-textfield-part6.html" +}; +const String config_auth_part1 = { +#include "ota_html/config-auth-part1.html" +}; +const String config_auth_part2 = { +#include "ota_html/config-auth-part2.html" }; \ No newline at end of file diff --git a/src/espmega_iot_ota.hpp b/src/espmega_iot_ota.hpp index 01f62dd..2bd7c4c 100644 --- a/src/espmega_iot_ota.hpp +++ b/src/espmega_iot_ota.hpp @@ -5,3 +5,13 @@ extern const String ota_part2_1; extern const String ota_part2_2; extern const String ota_part2_3; extern const String ota_part3; +extern const String config_part1; +extern const String config_part2; +extern const String config_txt_part1; +extern const String config_txt_part2; +extern const String config_txt_part3; +extern const String config_txt_part4; +extern const String config_txt_part5; +extern const String config_txt_part6; +extern const String config_auth_part1; +extern const String config_auth_part2; diff --git a/src/ota_html/config-auth-part1.html b/src/ota_html/config-auth-part1.html new file mode 100644 index 0000000..4e76dca --- /dev/null +++ b/src/ota_html/config-auth-part1.html @@ -0,0 +1,2 @@ +R"=====()=====" \ No newline at end of file diff --git a/src/ota_html/config-part1.html b/src/ota_html/config-part1.html new file mode 100644 index 0000000..f15e642 --- /dev/null +++ b/src/ota_html/config-part1.html @@ -0,0 +1,4 @@ +R"=====( +
+

ESPMega PRO

+

Device Configurations

)=====" \ No newline at end of file diff --git a/src/ota_html/config copy.html b/src/ota_html/config-part2.html similarity index 58% rename from src/ota_html/config copy.html rename to src/ota_html/config-part2.html index eaacb2f..8b5a3db 100644 --- a/src/ota_html/config copy.html +++ b/src/ota_html/config-part2.html @@ -1,32 +1,5 @@ - - -

ESPMega PRO

-

Device Configurations

-

IP Address

-
-

Network Mask

-
-

Gateway

-
-

DNS Server

-
-

Hostname

-
-

BMS Server - IP Address

-
-

BMS Server - Port

-
- -

BMS Server - Username

-
-

BMS Server - Password

-
-

BMS Server - Endpoint

-
- +R"=====( +

SIWAT SYSTEM 2023
\ No newline at end of file +)=====" \ No newline at end of file diff --git a/src/ota_html/config-textfield-part1.html b/src/ota_html/config-textfield-part1.html new file mode 100644 index 0000000..3c4da03 --- /dev/null +++ b/src/ota_html/config-textfield-part1.html @@ -0,0 +1 @@ +R"=====(

)=====" \ No newline at end of file diff --git a/src/ota_html/config-textfield-part2.html b/src/ota_html/config-textfield-part2.html new file mode 100644 index 0000000..69eaeed --- /dev/null +++ b/src/ota_html/config-textfield-part2.html @@ -0,0 +1,2 @@ +R"=====(

+
)=====" \ No newline at end of file diff --git a/src/ota_html/config.html b/src/ota_html/config.html index eaacb2f..703e086 100644 --- a/src/ota_html/config.html +++ b/src/ota_html/config.html @@ -27,9 +27,13 @@

BMS Server - Endpoint


+

SIWAT SYSTEM 2023