publish availability

This commit is contained in:
Siwat Sirichai 2023-12-03 00:37:24 +07:00
parent e3c07411cb
commit 192b1468f8
1 changed files with 7 additions and 2 deletions

View File

@ -32,6 +32,7 @@ WebServer otaserver(80);
#endif
bool standalone = true;
char MQTT_BASE_TOPIC[20];
char AVAILABILITY_TOPIC[40];
uint8_t base_topic_length = 0;
char STATE_REQUEST_TOPIC[40];
bool MQTT_USE_AUTH = false;
@ -237,6 +238,7 @@ void loop()
*/
void eeprom_retrieve_init()
{
// EEPROM Data Retrival
#ifdef ENABLE_CLIMATE_MODULE
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
@ -320,6 +322,8 @@ void eeprom_retrieve_init()
strcat(PWM_VALUE_TOPIC, "/pwm/00/value");
memcpy(INPUTS_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(INPUTS_TOPIC, "/input/00");
memcpy(AVAILABILITY_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(AVAILABILITY_TOPIC, "/availability");
#ifdef ENABLE_ANALOG_MODULE
memcpy(ADC_COMMAND_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(ADC_COMMAND_TOPIC, "/adc/00/set/state");
@ -567,13 +571,14 @@ void mqtt_connect()
Serial.print("MQTT not connected, connecting . . .\n");
lcd_send_stop_bit();
if (MQTT_USE_AUTH)
mqtt.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD);
mqtt.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD, AVAILABILITY_TOPIC, 0, true, "offline");
else
mqtt.connect(HOSTNAME);
mqtt.connect(HOSTNAME, AVAILABILITY_TOPIC, 0, true, "offline");
if (mqtt.connected())
{
mqtt_subscribe();
Serial.print("MQTT connected\n");
mqtt.publish(AVAILABILITY_TOPIC, "online", true);
lcd_send_stop_bit();
publish_pwm_states();
publish_input_states();