diff --git a/.vscode/settings.json b/.vscode/settings.json index d54d5a5..c66a10b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "C_Cpp.errorSquiggles": "enabled", "files.associations": { + "*.cps": "javascript", "string": "cpp", "optional": "cpp", "istream": "cpp", @@ -11,6 +12,7 @@ "tuple": "cpp", "type_traits": "cpp", "utility": "cpp", - "*.d": "cpp" + "*.d": "cpp", + "*.html": "cpp" } } \ No newline at end of file diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 54c1f0d..bb1001b 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -1,7 +1,8 @@ #include // OS Configuration -//#define FASTBOOT +// #define FASTBOOT +#define ESPMEGA_REV "ESPMega PRO R3.3b" // Network Connectivity char HOSTNAME[15]; @@ -115,9 +116,9 @@ StaticThreadController<2> lcd_thread_controller(&top_bar_updater, &page_updater) void setup() { Serial.begin(115200); - #ifdef ENABLE_EXTERNAL_LCD - Serial2.begin(115200,SERIAL_8N1,RXD2,TXD2); - #endif +#ifdef ENABLE_EXTERNAL_LCD + Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2); +#endif panel.begin(115200); Serial.println("ESPMega R3 Initializing"); ESPMega_begin(); @@ -127,12 +128,12 @@ void setup() lcd_send_stop_bit(); lcd_init(); lcd_begin(); - #ifdef ENABLE_EXTERNAL_LCD +#ifdef ENABLE_EXTERNAL_LCD Serial2.print("rest"); Serial2.write(0xFF); Serial2.write(0xFF); Serial2.write(0xFF); - #endif +#endif lcd_send_command("boot_state.txt=\"Core Initializing . . .\""); Serial.println("Initializing Infrared . . ."); lcd_send_command("boot_state.txt=\"Infrared Initializing . . .\""); @@ -149,7 +150,6 @@ void setup() Serial.println("Jumping to User Code."); user_init(); lcd_send_command("page dashboard"); - } void loop() @@ -211,7 +211,7 @@ void eeprom_retrieve_init() eeprom_mqtt_port_retrieve(); mqtt_client.setServer(MQTT_SERVER, MQTT_PORT); eeprom_basetopic_retrieve(); - base_topic_length = strlen(MQTT_BASE_TOPIC)+1; + base_topic_length = strlen(MQTT_BASE_TOPIC) + 1; memcpy(STATE_REQUEST_TOPIC, MQTT_BASE_TOPIC, 20); strcat(STATE_REQUEST_TOPIC, "/requeststate"); memcpy(PWM_SET_STATE_TOPIC, MQTT_BASE_TOPIC, 20); @@ -242,34 +242,54 @@ void eeprom_retrieve_init() strcat(INPUTS_TOPIC, "/input/00"); } -void ota_begin() { - otaserver.on("/", HTTP_GET, []() { +void ota_begin() +{ + otaserver.on("/", HTTP_GET, []() + { otaserver.sendHeader("Connection", "close"); - otaserver.send(200, "text/html", ota_upload_page); - }); - otaserver.on("/update", HTTP_POST, []() { + String otabuffer = ota_part1+HOSTNAME+ota_part2+IP.toString()+ota_part3+ESPMEGA_REV+ota_part4+MQTT_SERVER.toString()+ota_part5+String(MQTT_BASE_TOPIC)+ota_part6; + if(standalone) + otabuffer+=String("No"); + else + otabuffer+=String("Yes"); + otabuffer+=ota_part7; + otaserver.send(200, "text/html", otabuffer); }); + otaserver.on( + "/update", HTTP_POST, []() + { otaserver.sendHeader("Connection", "close"); otaserver.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); - ESP.restart(); - }, []() { - HTTPUpload& upload = otaserver.upload(); - if (upload.status == UPLOAD_FILE_START) { - Serial.printf("Update: %s\n", upload.filename.c_str()); - if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { - Update.printError(Serial); - } - } else if (upload.status == UPLOAD_FILE_WRITE) { - if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { - Update.printError(Serial); - } - } else if (upload.status == UPLOAD_FILE_END) { - if (Update.end(true)) { - Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); - } else { - Update.printError(Serial); - } - } - }); + ESP.restart(); }, + []() + { + HTTPUpload &upload = otaserver.upload(); + if (upload.status == UPLOAD_FILE_START) + { + Serial.printf("Update: %s\n", upload.filename.c_str()); + if (!Update.begin(UPDATE_SIZE_UNKNOWN)) + { + Update.printError(Serial); + } + } + else if (upload.status == UPLOAD_FILE_WRITE) + { + if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) + { + Update.printError(Serial); + } + } + else if (upload.status == UPLOAD_FILE_END) + { + if (Update.end(true)) + { + Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); + } + else + { + Update.printError(Serial); + } + } + }); otaserver.begin(); } @@ -286,7 +306,7 @@ void network_begin() ETH.begin(); ETH.setHostname(HOSTNAME); ETH.config(IP, GATEWAY, SUBNET, DNS, DNS); - #ifndef FASTBOOT +#ifndef FASTBOOT delay(1000); lcd_send_command("boot_state.txt=\"Ethernet Core Initializing \""); delay(500); @@ -298,10 +318,10 @@ void network_begin() delay(500); lcd_send_command("boot_state.txt=\"NTP Core Initializing . . .\""); delay(500); - #endif +#endif char ntp[19]; - MQTT_SERVER.toString().toCharArray(ntp,19); - ESPMega_configNTP(utc_offset*3600,0,ntp); + MQTT_SERVER.toString().toCharArray(ntp, 19); + ESPMega_configNTP(utc_offset * 3600, 0, ntp); ESPMega_updateTimeFromNTP(); Serial.println(); } @@ -791,7 +811,7 @@ void lcd_top_bar_update() { char time_buffer[15]; rtctime_t time = ESPMega_getTime(); - sprintf(time_buffer, "%02d:%02d",time.hours,time.minutes); + sprintf(time_buffer, "%02d:%02d", time.hours, time.minutes); panel.writeStr("time.txt", time_buffer); panel.writeNum("server.pic", standalone ? 4 : 5); panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2); @@ -993,24 +1013,30 @@ void eeprom_mqtt_port_retrieve() memcpy(&MQTT_PORT, port_arr, 2); } -boolean pwm_get_state(int id) { +boolean pwm_get_state(int id) +{ return pwm_states[id]; } -uint16_t pwm_get_value(int id) { +uint16_t pwm_get_value(int id) +{ return pwm_values[id]; } -boolean input_get_state(int id) { +boolean input_get_state(int id) +{ return virtual_interupt_state[id]; } -uint8_t ac_get_temperature() { +uint8_t ac_get_temperature() +{ return ac_temperature; } -uint8_t ac_get_mode() { +uint8_t ac_get_mode() +{ return ac_mode; } -uint8_t ac_get_fan_speed() { +uint8_t ac_get_fan_speed() +{ return ac_fan_speed; } \ No newline at end of file diff --git a/src/espmega_iot_ota.cpp b/src/espmega_iot_ota.cpp index b1be6de..20444fa 100644 --- a/src/espmega_iot_ota.cpp +++ b/src/espmega_iot_ota.cpp @@ -1,56 +1,23 @@ #include "espmega_iot_ota.hpp" -/* Style */ -String ota_style = -""; - -/* Server Index Page */ -String ota_upload_page = -"" -"
" -"

ESPMega PRO

" -"

Programming Tool

" -"" -"" -"" -"

" -"
" -"

" -"" + ota_style; \ No newline at end of file + +const String ota_part1 = { +#include "ota_html/ota-part1.html" +}; +const String ota_part2 = { +#include "ota_html/ota-part2.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" +}; \ No newline at end of file diff --git a/src/espmega_iot_ota.hpp b/src/espmega_iot_ota.hpp index 9531b86..6147e2e 100644 --- a/src/espmega_iot_ota.hpp +++ b/src/espmega_iot_ota.hpp @@ -1,4 +1,9 @@ #pragma once #include -extern String ota_upload_page; -extern String ota_style; \ No newline at end of file +extern const String ota_part1; +extern const String ota_part2; +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; \ No newline at end of file diff --git a/src/ota_html/ota-part1.html b/src/ota_html/ota-part1.html new file mode 100644 index 0000000..70f5d26 --- /dev/null +++ b/src/ota_html/ota-part1.html @@ -0,0 +1,8 @@ +R"=====( +
+

ESPMega PRO

+

Programming Tool

+ +

+ Hostname + )=====" diff --git a/src/ota_html/ota-part2.html b/src/ota_html/ota-part2.html new file mode 100644 index 0000000..40f097f --- /dev/null +++ b/src/ota_html/ota-part2.html @@ -0,0 +1,5 @@ +R"=====( +

+

+ IP Address + )=====" diff --git a/src/ota_html/ota-part3.html b/src/ota_html/ota-part3.html new file mode 100644 index 0000000..76b974c --- /dev/null +++ b/src/ota_html/ota-part3.html @@ -0,0 +1,5 @@ +R"=====( +

+

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

+

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

+

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

+

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

+ + + +

+
+
+
+
+
+
+SIWAT SYSTEM 2023 +
+ +)=====" \ No newline at end of file