From a6aaad3d933f51d5f4a06b837dbdb88bd4412f4d Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 3 Oct 2023 03:44:31 +0700 Subject: [PATCH] robustness --- src/user_code.cpp | 11 +++++------ src/user_code.hpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/user_code.cpp b/src/user_code.cpp index 93ffdc2..f2296b2 100644 --- a/src/user_code.cpp +++ b/src/user_code.cpp @@ -45,6 +45,10 @@ Peripheral Initialization Routine void user_pre_init() { nexInit(); + memcpy(AC_LOCK_TOPIC, MQTT_BASE_TOPIC, 20); + strcat(AC_LOCK_TOPIC, "/ac/set/lock"); + memcpy(AC_LOCK_REPORT_TOPIC, MQTT_BASE_TOPIC, 20); + strcat(AC_LOCK_REPORT_TOPIC, "/ac/lock"); } /* @@ -54,10 +58,6 @@ void user_init() { elcd.print("page dashboard"); elcd_sendstop(); - memcpy(AC_LOCK_TOPIC, MQTT_BASE_TOPIC, 20); - strcat(AC_LOCK_TOPIC, "/ac/set/lock"); - memcpy(AC_LOCK_REPORT_TOPIC, MQTT_BASE_TOPIC, 20); - strcat(AC_LOCK_REPORT_TOPIC, "/ac/lock"); ac_lock = ESPMega_FRAM.read8(AC_LOCK_ADDRESS); ac_lock = ac_lock > 1 ? 0 : ac_lock; elcd.print("dashboard.pic="); @@ -273,7 +273,7 @@ void ac_lock_callback(String topic, String payload) } void ac_lock_report() { - //mqtt_client.publish(AC_LOCK_REPORT_TOPIC,ac_lock?"lock":"unlock"); + mqtt_client.publish(AC_LOCK_REPORT_TOPIC,ac_lock?"lock":"unlock"); } void elcd_sendstop() { @@ -295,7 +295,6 @@ void pwm_update_lcd() { } void mqtt_connected_user_callback() { - Serial.println("User Subscribing"); mqtt.subscribe(String(AC_LOCK_TOPIC), ac_lock_callback); ac_lock_report(); } diff --git a/src/user_code.hpp b/src/user_code.hpp index 43e2bc4..4ef6b50 100644 --- a/src/user_code.hpp +++ b/src/user_code.hpp @@ -91,4 +91,4 @@ extern uint8_t ac_get_fan_speed(); extern bool standalone; extern PubSubClient mqtt_client; extern PubSubClientTools mqtt; -extern char MQTT_BASE_TOPIC[]; +extern char MQTT_BASE_TOPIC[]; \ No newline at end of file