From b7a995e94b5f1ff2e4560296c4e55c7c8204f292 Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 16 Feb 2023 10:04:40 +0100 Subject: [PATCH] stash --- firmware/lux.cpp | 2 +- firmware/mqtt.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/firmware/lux.cpp b/firmware/lux.cpp index 90d3edd..75f937f 100644 --- a/firmware/lux.cpp +++ b/firmware/lux.cpp @@ -81,7 +81,7 @@ namespace fiatlux { void setup() { gpio_enable(2, GPIO_OUTPUT); - } + } } namespace relais { diff --git a/firmware/mqtt.cpp b/firmware/mqtt.cpp index a6afa93..84d49aa 100644 --- a/firmware/mqtt.cpp +++ b/firmware/mqtt.cpp @@ -36,16 +36,20 @@ bool is_on = true; 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) { TickType_t xLastWakeTime = xTaskGetTickCount(); - char msg[PUB_MSG_LEN]; while (1) { - vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_PERIOD_MS); - 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"); - } + vTaskDelayUntil(&xLastWakeTime, 20000 / portTICK_PERIOD_MS); + publish_state(); } } @@ -209,6 +213,7 @@ static void topic_received(mqtt_message_data_t *md) { printf("expected ',' or '}'\n"); return; } + publish_state(); } static const char *get_my_id(void) {