This commit is contained in:
j3d1 2023-02-16 10:04:40 +01:00
parent 55dad602c9
commit b7a995e94b
2 changed files with 12 additions and 7 deletions

View file

@ -36,16 +36,20 @@ bool is_on = true;
QueueHandle_t publish_queue; QueueHandle_t publish_queue;
static void publish_state(){
char msg[PUB_MSG_LEN];
snprintf(msg, PUB_MSG_LEN, R"({"state":"%s", "brightness":%d})", is_on ? "ON" : "OFF", light_value >> 4);
if(xQueueSend(publish_queue, (void *) msg, 0) == pdFALSE) {
printf("Publish queue overflow.\r\n");
}
}
extern "C" void beat_task(void *pvParameters) { extern "C" void beat_task(void *pvParameters) {
TickType_t xLastWakeTime = xTaskGetTickCount(); TickType_t xLastWakeTime = xTaskGetTickCount();
char msg[PUB_MSG_LEN];
while (1) { while (1) {
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_PERIOD_MS); vTaskDelayUntil(&xLastWakeTime, 20000 / portTICK_PERIOD_MS);
snprintf(msg, PUB_MSG_LEN, R"({"state":"%s", "brightness":%d})", is_on ? "ON" : "OFF", light_value >> 4); publish_state();
if(xQueueSend(publish_queue, (void *) msg, 0) == pdFALSE) {
printf("Publish queue overflow.\r\n");
}
} }
} }
@ -209,6 +213,7 @@ static void topic_received(mqtt_message_data_t *md) {
printf("expected ',' or '}'\n"); printf("expected ',' or '}'\n");
return; return;
} }
publish_state();
} }
static const char *get_my_id(void) { static const char *get_my_id(void) {