Add discovery

This commit is contained in:
fvanroie 2021-04-25 03:09:12 +02:00
parent 8017be47db
commit 40c905687d
2 changed files with 10 additions and 2 deletions

View File

@ -42,8 +42,8 @@ extern uint8_t hasp_sleep_state;
dispatch_conf_t dispatch_setings = {.teleperiod = 300};
uint32_t dispatchLastMillis;
uint8_t nCommands = 0;
uint32_t dispatchLastMillis = -3000000; // force discovery
uint8_t nCommands = 0;
haspCommand_t commands[18];
struct moodlight_t

View File

@ -253,6 +253,13 @@ int mqtt_send_state(const __FlashStringHelper* subtopic, const char* payload)
return mqttPublish(tmp_topic, payload, strlen(payload), false);
}
int mqtt_send_discovery(const char* payload)
{
char tmp_topic[20];
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR(MQTT_PREFIX "/discovery"));
return mqttPublish(tmp_topic, payload, strlen(payload), false);
}
int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload)
{
char tmp_topic[strlen(mqttNodeTopic) + 20];
@ -268,6 +275,7 @@ static void onConnect(void* context)
printf("Successful connection\n");
mqtt_subscribe(mqtt_client, TOPIC "command/#");
mqtt_subscribe(mqtt_client, TOPIC "config/#");
// mqtt_subscribe(mqtt_client, TOPIC "command");
mqtt_subscribe(mqtt_client, TOPIC "light/#");
mqtt_subscribe(mqtt_client, TOPIC "brightness/#");