diff --git a/.gitignore b/.gitignore index 8a9fb2f..89cc49c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch -.vs/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 69aa100..c66a10b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,8 +13,6 @@ "type_traits": "cpp", "utility": "cpp", "*.d": "cpp", - "*.html": "cpp", - "*.tcc": "cpp", - "regex": "cpp" + "*.html": "cpp" } } \ No newline at end of file diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index d6253ac..5384855 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -18,9 +18,11 @@ bool standalone = true; char MQTT_BASE_TOPIC[20]; uint8_t base_topic_length = 0; char STATE_REQUEST_TOPIC[40]; -bool MQTT_USE_AUTH = false; -char MQTT_USERNAME[32]; -char MQTT_PASSWORD[32]; +// #define MQTT_USE_AUTH +#ifdef MQTT_USE_AUTH +const char MQTT_USERNAME[] = "username"; +const char MQTT_PASSWORD[] = "password"; +#endif uint8_t utc_offset = 7; float current_room_temp = 0; float current_room_humid = 0; @@ -47,6 +49,12 @@ const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255}; char PWM_SET_STATE_TOPIC[70]; char PWM_SET_VALUE_TOPIC[70]; +// Infrared Transciever +#define IR_RECIEVE_PIN 35 +#define IR_SEND_PIN 17 +#define MARK_EXCESS_MICROS 20 +#define RAW_BUFFER_LENGTH 750 + // LCD int lcd_current_page = 1; int lcd_pwmAdj_id = 0; @@ -61,6 +69,8 @@ Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low uint8_t ac_mode = 0; uint8_t ac_fan_speed = 0; uint8_t ac_temperature = 25; +#define AC_MAX_TEMPERATURE 30 +#define AC_MIN_TEMPERATURE 18 char AC_SET_MODE_TOPIC[75]; char AC_SET_FAN_TOPIC[75]; char AC_SET_TEMPERATURE_TOPIC[75]; @@ -71,22 +81,19 @@ 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 char PWM_STATE_TOPIC[75]; char PWM_VALUE_TOPIC[75]; @@ -123,7 +130,6 @@ void setup() lcd_send_stop_bit(); lcd_init(); lcd_begin(); - check_boot_reset(); #ifdef ENABLE_EXTERNAL_LCD Serial2.print("rest"); Serial2.write(0xFF); @@ -138,8 +144,6 @@ void setup() lcd_send_command("boot_state.txt=\"Network Initializing . . .\""); network_begin(); lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\""); - mqtt_client.setSocketTimeout(1000); - eth.setTimeout(1); mqtt_connect(); lcd_send_command("boot_state.txt=\"Threads Initializing . . .\""); thread_initialization(); @@ -207,9 +211,6 @@ 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; @@ -248,81 +249,13 @@ void ota_begin() otaserver.on("/", HTTP_GET, []() { otaserver.sendHeader("Connection", "close"); - 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; + 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; if(standalone) otabuffer+=String("No"); else otabuffer+=String("Yes"); - otabuffer+=ota_part2_3+ota_part3; + otabuffer+=ota_part8; otaserver.send(200, "text/html", otabuffer); }); - otaserver.on("/config", HTTP_GET, []() - { - otaserver.sendHeader("Connection", "close"); - String 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+SUBNET.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?"checked=\"checked\"":"")+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("/save_config", HTTP_GET, []() - { - otaserver.sendHeader("Connection", "close"); - String configbuffer = "Configuration Saved. Rebooting . . ."; - otaserver.send(200, "text/html", configbuffer); - bool use_auth = false; - for(int i=0;i0;i--) { - if(digitalRead(2)==HIGH) { - lcd_send_command("boot_state.txt=\"Factory Reset Canceled, Restarting\""); - delay(5000); - ESP.restart(); - } - Serial.printf("boot_state.txt=\"Factory Reset in %d\"",i); - lcd_send_stop_bit(); - delay(1000); - } - lcd_send_command("boot_state.txt=\"Factory Reseting . . .\""); - // Format FRAM - for(int i=0;i<32768;i++) { - ESPMega_FRAM.write8(i,0); - } - // Load Default Values - set_ip("192.168.0.10"); - set_gw("192.168.0.1"); - // Reboot - lcd_send_stop_bit(); - lcd_send_command("boot_state.txt=\"Factory Reset OK. Release Button.\""); - delay(3000); - ESP.restart(); -} -void check_boot_reset() { - pinMode(2, INPUT_PULLUP); - if(digitalRead(2)==LOW) { - factory_reset(); - } } \ No newline at end of file diff --git a/src/espmega_iot_core.hpp b/src/espmega_iot_core.hpp index 23c32eb..19d97a2 100644 --- a/src/espmega_iot_core.hpp +++ b/src/espmega_iot_core.hpp @@ -77,8 +77,6 @@ void trigger10(); void trigger11(); void trigger12(); void trigger13(); -void trigger14(); -void trigger15(); void eeprom_retrieve_init(); void eeprom_pwm_update(); @@ -98,13 +96,4 @@ 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(); -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); - -void factory_reset(); -void check_boot_reset(); \ No newline at end of file +void eeprom_mqtt_port_retrieve(); \ No newline at end of file diff --git a/src/espmega_iot_ota.cpp b/src/espmega_iot_ota.cpp index 3c67154..282ffd5 100644 --- a/src/espmega_iot_ota.cpp +++ b/src/espmega_iot_ota.cpp @@ -3,46 +3,24 @@ const String ota_part1 = { #include "ota_html/ota-part1.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_part2 = { +#include "ota_html/ota-part2.html" }; const String ota_part3 = { #include "ota_html/ota-part3.html" }; - -const String config_part1 = { -#include "ota_html/config-part1.html" +const String ota_part4 = { +#include "ota_html/ota-part4.html" }; -const String config_part2 = { -#include "ota_html/config-part2.html" +const String ota_part5 = { +#include "ota_html/ota-part5.html" }; -const String config_txt_part1 = { -#include "ota_html/config-textfield-part1.html" +const String ota_part6 = { +#include "ota_html/ota-part6.html" }; -const String config_txt_part2 = { -#include "ota_html/config-textfield-part2.html" +const String ota_part7 = { +#include "ota_html/ota-part7.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" +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 2bd7c4c..8ca414b 100644 --- a/src/espmega_iot_ota.hpp +++ b/src/espmega_iot_ota.hpp @@ -1,17 +1,10 @@ #pragma once #include extern const String ota_part1; -extern const String ota_part2_1; -extern const String ota_part2_2; -extern const String ota_part2_3; +extern const String ota_part2; 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; +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/ir_codes.hpp b/src/ir_codes.hpp index 7dc00e4..8318594 100644 --- a/src/ir_codes.hpp +++ b/src/ir_codes.hpp @@ -1,13 +1,6 @@ #pragma once #include -// Infrared Transciever -#define IR_RECIEVE_PIN 35 -#define IR_SEND_PIN 17 -#define MARK_EXCESS_MICROS 20 -#define RAW_BUFFER_LENGTH 750 -#define AC_MAX_TEMPERATURE 30 -#define AC_MIN_TEMPERATURE 15 -extern const uint8_t ir_code_cool[3][16][750] = { +extern const uint16_t ir_code_cool[3][13][750] = { // Fan Speed High { {0}, // 18C @@ -58,9 +51,9 @@ extern const uint8_t ir_code_cool[3][16][750] = { {0} // 30C }}; -extern const uint8_t ir_code_fan[3][750] = { +extern const uint16_t ir_code_fan[3][750] = { {0}, // LOW {0}, // MED {0} // HIGH }; -extern const uint8_t ir_code_off[750] = {0}; \ No newline at end of file +extern const uint16_t ir_code_off[750] = {0}; \ No newline at end of file diff --git a/src/ota_html/config-auth-part1.html b/src/ota_html/config-auth-part1.html deleted file mode 100644 index ab970c0..0000000 --- a/src/ota_html/config-auth-part1.html +++ /dev/null @@ -1,2 +0,0 @@ -R"=====()=====" \ No newline at end of file diff --git a/src/ota_html/config-part1.html b/src/ota_html/config-part1.html deleted file mode 100644 index f15e642..0000000 --- a/src/ota_html/config-part1.html +++ /dev/null @@ -1,4 +0,0 @@ -R"=====( -
-

ESPMega PRO

-

Device Configurations

)=====" \ No newline at end of file diff --git a/src/ota_html/config-part2.html b/src/ota_html/config-part2.html deleted file mode 100644 index 8b5a3db..0000000 --- a/src/ota_html/config-part2.html +++ /dev/null @@ -1,167 +0,0 @@ -R"=====( -

- SIWAT SYSTEM 2023 -
-)=====" \ No newline at end of file diff --git a/src/ota_html/config-textfield-part1.html b/src/ota_html/config-textfield-part1.html deleted file mode 100644 index 3c4da03..0000000 --- a/src/ota_html/config-textfield-part1.html +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 69eaeed..0000000 --- a/src/ota_html/config-textfield-part2.html +++ /dev/null @@ -1,2 +0,0 @@ -R"=====(

-
)=====" \ No newline at end of file diff --git a/src/ota_html/config.html b/src/ota_html/config.html deleted file mode 100644 index 703e086..0000000 --- a/src/ota_html/config.html +++ /dev/null @@ -1,198 +0,0 @@ - -
-

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-part1.html b/src/ota_html/ota-part1.html index 1c0e261..a63d855 100644 --- a/src/ota_html/ota-part1.html +++ b/src/ota_html/ota-part1.html @@ -1,4 +1,8 @@ R"=====(

ESPMega PRO

-

Device Information

)=====" +

Software Management

+ +

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

)=====" diff --git a/src/ota_html/ota-part2-2_itr.html b/src/ota_html/ota-part2-2_itr.html deleted file mode 100644 index 7ff7dc6..0000000 --- a/src/ota_html/ota-part2-2_itr.html +++ /dev/null @@ -1 +0,0 @@ -R"=====()=====" diff --git a/src/ota_html/ota-part2-3_itr.html b/src/ota_html/ota-part2-3_itr.html deleted file mode 100644 index ce17711..0000000 --- a/src/ota_html/ota-part2-3_itr.html +++ /dev/null @@ -1,2 +0,0 @@ -R"=====( -

)=====" \ No newline at end of file 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 index 4826dbf..d92b7e1 100644 --- a/src/ota_html/ota-part3.html +++ b/src/ota_html/ota-part3.html @@ -1,144 +1,5 @@ -R"=====(

-


-

Upload Software Package

- - -

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

+

+ MAC Address + )=====" \ 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..76b974c --- /dev/null +++ b/src/ota_html/ota-part4.html @@ -0,0 +1,5 @@ +R"=====( +

+

+ Device + )=====" \ 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..d7745f3 --- /dev/null +++ b/src/ota_html/ota-part5.html @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..743ba2a --- /dev/null +++ b/src/ota_html/ota-part6.html @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..567deb3 --- /dev/null +++ b/src/ota_html/ota-part7.html @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..4f94bee --- /dev/null +++ b/src/ota_html/ota-part8.html @@ -0,0 +1,125 @@ +R"=====( +

+ + + +

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

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