diff --git a/.gitignore b/.gitignore index a4a37ad..8b617f4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ .vscode/ .vscode/settings.json firmware/ -release/ \ No newline at end of file +release/ +.vscode/extensions.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ee32b37..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "C_Cpp.errorSquiggles": "enabled", - "files.associations": { - "*.cps": "javascript", - "string": "cpp", - "optional": "cpp", - "istream": "cpp", - "ostream": "cpp", - "system_error": "cpp", - "array": "cpp", - "functional": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "*.d": "cpp", - "*.html": "cpp", - "*.tcc": "cpp", - "regex": "cpp" - }, - "C_Cpp_Runner.msvcBatchPath": "", - "C_Cpp_Runner.cCompilerPath": "gcc", - "C_Cpp_Runner.cppCompilerPath": "g++", - "C_Cpp_Runner.debuggerPath": "gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false, - "cmake.sourceDirectory": "D:/Git/iot-firmware/.pio/libdeps/full/Adafruit BusIO" -} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index dcf9353..af7a9cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { stages { stage('Build') { steps { - git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git' + git branch: 'lcd_upload', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git' sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio' sh '/usr/bin/python3 gen_release.py' stash includes: 'release/**/*', name: 'release_binaries' diff --git a/gen_release.py b/gen_release.py index 2c07d5e..24fa03b 100644 --- a/gen_release.py +++ b/gen_release.py @@ -89,10 +89,6 @@ for environment in environments: else: config[f'env:{environment}']['build_flags'] = config[f'env:{environment}']['build_flags'] + f' -DFW_VERSION=\\"{git_branch}_{environment}_{commit_hash}\\"' -# Write the platformio.ini file -with open(os.path.join(firmware_folder, 'platformio.ini'), 'w') as configfile: - config.write(configfile) - # if argument is not supplied, build all environments listed in platformio.ini if len(sys.argv) == 1: subprocess.run([f'{platformio_path}', 'run','-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir) diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 0472888..1135a0f 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -47,7 +47,6 @@ uint8_t utc_offset = 7; float current_room_temp = 0; float current_room_humid = 0; #endif -bool pwm_report_enable = true; // Inputs #define VINT_COUNT 16 @@ -70,7 +69,6 @@ const float pwm_linear_scaling_c[PWM_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255}; char PWM_SET_STATE_TOPIC[70]; char PWM_SET_VALUE_TOPIC[70]; -char PWM_REPORT_ENABLE_TOPIC[70]; #ifdef ENABLE_INTERNAL_LCD // LCD @@ -251,20 +249,18 @@ void loop() */ void fram_retrieve_init() { -#ifdef ENABLE_WEBUI + #ifdef ENABLE_WEBUI ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32); ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32); - if (strlen(WEBUI_USERNAME) == 0) - { - strcpy(WEBUI_USERNAME, "admin"); + if(strlen(WEBUI_USERNAME)==0) { + strcpy(WEBUI_USERNAME,"admin"); ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32); } - if (strlen(WEBUI_PASSWORD) == 0) - { - strcpy(WEBUI_PASSWORD, "admin"); + if(strlen(WEBUI_PASSWORD)==0) { + strcpy(WEBUI_PASSWORD,"admin"); ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32); } -#endif + #endif // FRAM Data Retrival #ifdef ENABLE_CLIMATE_MODULE ac_mode = ESPMega_FRAM.read8(FRAM_ADDRESS_AC_MODE); @@ -324,8 +320,6 @@ void fram_retrieve_init() strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state"); memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20); strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value"); - memcpy(PWM_REPORT_ENABLE_TOPIC, MQTT_BASE_TOPIC, 20); - strcat(PWM_REPORT_ENABLE_TOPIC, "/pwm/report_enable"); #ifdef ENABLE_CLIMATE_MODULE memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20); strcat(AC_SET_MODE_TOPIC, "/ac/set/mode"); @@ -401,11 +395,11 @@ void ota_begin() 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; -#ifdef FW_VERSION + #ifdef FW_VERSION otabuffer+=ota_part2_1+"Firmware"+ota_part2_2+FW_VERSION+ota_part2_3; -#else + #else otabuffer+=ota_part2_1+"Firmware"+ota_part2_2+"Out of Tree"+ota_part2_3; -#endif + #endif 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; @@ -553,6 +547,24 @@ void ota_begin() } } }); + otaserver.on("/lcd_update",HTTP_POST,[]() { + otaserver.sendHeader("Connection","close"); + },[](){ + for(int i=0;i(payload_nt), delimiter); - while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH) - { - ir_buffer[ir_buffer_length++] = atoi(token); - token = strtok(nullptr, delimiter); + const char* delimiter = ","; + char* token = strtok(const_cast(payload_nt), delimiter); + while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH) { + ir_buffer[ir_buffer_length++] = atoi(token); + token = strtok(nullptr, delimiter); } - IrSender.sendRaw(ir_buffer, ir_buffer_length, NEC_KHZ); + IrSender.sendRaw(ir_buffer,ir_buffer_length ,NEC_KHZ); } #endif else if (!strcmp(topic, STATE_REQUEST_TOPIC)) @@ -796,7 +802,7 @@ void thread_initialization() * @param payload The message payload. * @param payload_length The length of the message payload. */ -IRAM_ATTR void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length) +void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length) { int a = topic[5] - '0'; int b = topic[6] - '0'; @@ -822,7 +828,7 @@ IRAM_ATTR void pwm_state_callback(char *topic, uint8_t topic_length, char *paylo * @param payload The message payload. * @param payload_length The length of the message payload. */ -IRAM_ATTR void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length) +void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length) { int a = topic[5] - '0'; int b = topic[6] - '0'; @@ -881,7 +887,6 @@ void publish_pwm_states() for (int i = 0; i < PWM_COUNT; i++) { publish_pwm_state(i); - publish_pwm_value(i); } } @@ -892,11 +897,12 @@ void publish_pwm_states() */ void publish_pwm_state(int id) { - if (!pwm_report_enable) - return; int state = pwm_states[id]; + int value = pwm_values[id]; PWM_STATE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0'; PWM_STATE_TOPIC[base_topic_length + 5] = (id % 10) + '0'; + PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0'; + PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0'; if (state == 1) { mqtt.publish(PWM_STATE_TOPIC, "on"); @@ -905,15 +911,6 @@ void publish_pwm_state(int id) { mqtt.publish(PWM_STATE_TOPIC, "off"); } -} - -void publish_pwm_value(int id) -{ - if (!pwm_report_enable) - return; - int value = pwm_values[id]; - PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0'; - PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0'; char temp[6]; itoa(value, temp, DEC); mqtt.publish(PWM_VALUE_TOPIC, temp); @@ -925,7 +922,7 @@ void publish_pwm_value(int id) * @param id The ID of the PWM pin. * @param state The new state of the PWM pin. */ -IRAM_ATTR void pwm_set_state(int id, int state) +void pwm_set_state(int id, int state) { if (state != pwm_states[id]) { @@ -949,7 +946,7 @@ IRAM_ATTR void pwm_set_state(int id, int state) * @param id The id of the PWM pin. * @param value The value to set the PWM pin to. */ -IRAM_ATTR void pwm_set_value(int id, int value) +void pwm_set_value(int id, int value) { pwm_values[id] = value; int pwm_state = pwm_states[id]; @@ -960,7 +957,7 @@ IRAM_ATTR void pwm_set_value(int id, int value) else if (lcd_current_page == 5 && id == lcd_pwmAdj_id) panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]); #endif - publish_pwm_value(id); + publish_pwm_state(id); pwm_changed_user_callback(id); } @@ -1076,11 +1073,6 @@ void publish_input_state(int id, int state) mqtt.publish(INPUTS_TOPIC, state ? "1" : "0"); } -void pwm_set_publish_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length) -{ - pwm_report_enable = !strcmp(payload, "on"); -} - /** * @brief Callback function to request the current state of the device. * @@ -1091,7 +1083,6 @@ void state_request_callback() { publish_input_states(); publish_pwm_states(); - pwm_report_enable = true; #ifdef ENABLE_CLIMATE_MODULE publish_ac_state(); publish_env_state(); @@ -1268,8 +1259,6 @@ void ac_set_state(int mode, int temperature, int fan_speed) */ void publish_env_state() { - if(!pwm_report_enable) - return; int errorCode = env_sensor.read(); yield(); switch (errorCode) @@ -1920,10 +1909,10 @@ void factory_reset() set_ip("192.168.0.10"); set_gw("192.168.0.1"); set_netmask("255.255.255.0"); -#ifdef ENABLE_WEBUI + #ifdef ENABLE_WEBUI set_webui_username("admin"); set_webui_password("admin"); -#endif + #endif // Reboot #ifdef ENABLE_INTERNAL_LCD @@ -1977,7 +1966,7 @@ void disable_adc(int id) /** * Publishes the state of an ADC (Analog-to-Digital Converter) to the MQTT broker. - * + * * @param id The ID of the ADC. */ void publish_adc_state(int id) @@ -1989,7 +1978,7 @@ void publish_adc_state(int id) /** * @brief Publishes the ADC states. - * + * * This function iterates over the ADC channels and publishes the state of each channel. */ void publish_adc_states() @@ -2079,7 +2068,7 @@ void publish_adc_values() /** * Publishes the state of a DAC (Digital-to-Analog Converter) to the MQTT broker. - * + * * @param id The ID of the DAC. */ void publish_dac_state(int id) @@ -2091,7 +2080,7 @@ void publish_dac_state(int id) /** * Publishes the DAC value for a given ID. - * + * * @param id The ID of the DAC value to publish. */ void publish_dac_value(int id) @@ -2183,9 +2172,9 @@ void dac_set_state(int id, bool state) /** * @brief Publishes the states of all DACs. - * + * * This function iterates through all DACs and publishes their states. - * + * * @return void */ void publish_dac_states() @@ -2198,9 +2187,9 @@ void publish_dac_states() /** * @brief Publishes the DAC values. - * + * * This function iterates through all the DAC channels and publishes their values. - * + * * @return void */ void publish_dac_values() @@ -2255,7 +2244,7 @@ void dac_set_state_callback(char *topic, uint8_t topic_length, char *payload, un /** * @brief Get the ADC value for the specified ID. - * + * * @param id The ID of the ADC channel. * @return The ADC value. */ @@ -2265,7 +2254,7 @@ uint16_t adc_get_value(int id) } /** * @brief Get the state of the ADC with the specified ID. - * + * * @param id The ID of the ADC. * @return true if the ADC is enabled, false otherwise. */ @@ -2275,7 +2264,7 @@ bool adc_get_state(int id) } /** * @brief Get the value of a DAC channel. - * + * * @param id The ID of the DAC channel. * @return The value of the DAC channel. */ @@ -2285,7 +2274,7 @@ uint16_t dac_get_value(int id) } /** * @brief Get the state of the DAC with the specified ID. - * + * * @param id The ID of the DAC. * @return The state of the DAC. */ @@ -2296,10 +2285,8 @@ bool dac_get_state(int id) #endif -void virtual_interrupt_preload() -{ - for (int i = 0; i < 16; i++) - { +void virtual_interrupt_preload() { + for (int i = 0; i < 16; i++) { virtual_interupt_state[i] = ESPMega_digitalRead(virtual_interrupt_pins[i]); } } \ No newline at end of file diff --git a/src/espmega_iot_core.hpp b/src/espmega_iot_core.hpp index fb6afc7..f7cd015 100644 --- a/src/espmega_iot_core.hpp +++ b/src/espmega_iot_core.hpp @@ -43,7 +43,7 @@ #endif #include "espmega_iot_timer.hpp" -IRAM_ATTR void mqtt_callback(char* topic, byte* payload, unsigned int length); +void mqtt_callback(char* topic, byte* payload, unsigned int length); void virtual_interrupt_loop(); void virtual_interrupt_callback(int pin, int state); void virtual_interrupt_preload(); @@ -51,8 +51,8 @@ void network_begin(); void mqtt_connect(); void mqtt_subscribe(); void thread_initialization(); -IRAM_ATTR void pwm_state_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); -IRAM_ATTR void pwm_value_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); +void pwm_state_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); +void pwm_value_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); void state_request_callback(); void io_begin(); void ir_loop(); @@ -61,9 +61,8 @@ void ota_begin(); void publish_pwm_states(); void publish_pwm_state(int id); -void publish_pwm_value(int id); -IRAM_ATTR void pwm_set_state(int id, int state); -IRAM_ATTR void pwm_set_value(int id, int value); +void pwm_set_state(int id, int state); +void pwm_set_value(int id, int value); void pwm_toggle(int id); void pwm_toggle(int id1, int id2); void pwm_cycle_value(int id); @@ -158,6 +157,4 @@ void publish_adc_states(); uint16_t adc_get_value(int id); bool adc_get_state(int id); uint16_t dac_get_value(int id); -bool dac_get_state(int id); - -void pwm_set_publish_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length); \ No newline at end of file +bool dac_get_state(int id); \ No newline at end of file diff --git a/src/espmega_iot_lcd.cpp b/src/espmega_iot_lcd.cpp index 1f03338..0628433 100644 --- a/src/espmega_iot_lcd.cpp +++ b/src/espmega_iot_lcd.cpp @@ -1,9 +1,11 @@ #include #include +int lcd_byte_counter = 0; + /** * @brief Sends stop bit to LCD. - * + * * This function sends a stop bit to the LCD. It is only enabled if the ENABLE_INTERNAL_LCD macro is defined. */ void lcd_send_stop_bit() @@ -17,7 +19,7 @@ void lcd_send_stop_bit() /** * Sends a command to the LCD display. - * + * * @param command The command to send to the LCD display. */ void lcd_send_command(String command) @@ -31,9 +33,9 @@ void lcd_send_command(String command) /** * @brief Resets the LCD display. - * + * * If ENABLE_INTERNAL_LCD is defined, sends a reset command to the LCD display. - * + * */ void lcd_reset() { @@ -57,7 +59,7 @@ void lcd_init() /** * @brief Starts the upload process to the LCD. - * + * * @param size The size of the data to be uploaded. * @return true if the upload process started successfully, false otherwise. */ @@ -70,14 +72,16 @@ bool lcd_upload_start(size_t size) Serial.print("connect"); lcd_send_stop_bit(); delay(1000); - Serial.print("whmi-wri 1024,115200,res0"); + Serial.print("whmi-wri "); + Serial.print(size); + Serial.print(",115200,res0"); lcd_send_stop_bit(); - lcd_wait_ack(); + return lcd_wait_ack(); } /** * Writes data to the LCD upload buffer. - * + * * @param data Pointer to the data to be written. * @param size Size of the data to be written. * @return True if the write was successful, false otherwise. @@ -87,9 +91,15 @@ bool lcd_upload_write(uint8_t *data, size_t size) for (int i = 0; i < size; i++) { Serial.write(data[i]); + lcd_byte_counter++; + if (lcd_byte_counter == 4096) + { + lcd_wait_ack(); + lcd_byte_counter = 0; + } } + return true; } - /** * Waits for an acknowledgement signal from the LCD. * @return true if acknowledgement signal is received, false otherwise. @@ -97,12 +107,15 @@ bool lcd_upload_write(uint8_t *data, size_t size) bool lcd_wait_ack() { bool data_ok = false; - for (int i; i < 50; i++) + for (int i = 0; i < 50; i++) { - if (Serial.read() == 0x05) + if (Serial.available()) { - data_ok = true; - break; + if (Serial.read() == 0x05) + { + data_ok = true; + break; + } } delay(100); } diff --git a/src/ota_html/ota-part3.html b/src/ota_html/ota-part3.html index 4826dbf..4c7daee 100644 --- a/src/ota_html/ota-part3.html +++ b/src/ota_html/ota-part3.html @@ -23,11 +23,14 @@ R"=====(