robustness

This commit is contained in:
Siwat Sirichai 2023-10-03 03:44:31 +07:00
parent 4ebafa7cb7
commit a6aaad3d93
2 changed files with 6 additions and 7 deletions

View File

@ -45,6 +45,10 @@ Peripheral Initialization Routine
void user_pre_init() void user_pre_init()
{ {
nexInit(); 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.print("page dashboard");
elcd_sendstop(); 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 = ESPMega_FRAM.read8(AC_LOCK_ADDRESS);
ac_lock = ac_lock > 1 ? 0 : ac_lock; ac_lock = ac_lock > 1 ? 0 : ac_lock;
elcd.print("dashboard.pic="); elcd.print("dashboard.pic=");
@ -273,7 +273,7 @@ void ac_lock_callback(String topic, String payload)
} }
void ac_lock_report() { 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() { void elcd_sendstop() {
@ -295,7 +295,6 @@ void pwm_update_lcd() {
} }
void mqtt_connected_user_callback() { void mqtt_connected_user_callback() {
Serial.println("User Subscribing");
mqtt.subscribe(String(AC_LOCK_TOPIC), ac_lock_callback); mqtt.subscribe(String(AC_LOCK_TOPIC), ac_lock_callback);
ac_lock_report(); ac_lock_report();
} }

View File

@ -91,4 +91,4 @@ extern uint8_t ac_get_fan_speed();
extern bool standalone; extern bool standalone;
extern PubSubClient mqtt_client; extern PubSubClient mqtt_client;
extern PubSubClientTools mqtt; extern PubSubClientTools mqtt;
extern char MQTT_BASE_TOPIC[]; extern char MQTT_BASE_TOPIC[];