stash
This commit is contained in:
parent
55dad602c9
commit
b7a995e94b
2 changed files with 12 additions and 7 deletions
|
@ -81,7 +81,7 @@ namespace fiatlux {
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
gpio_enable(2, GPIO_OUTPUT);
|
gpio_enable(2, GPIO_OUTPUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace relais {
|
namespace relais {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue