From db7eb6305c5224fc7d18932217f52c6f46fb48df Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 25 Aug 2020 11:42:05 +0200 Subject: [PATCH] add: random status sending to broker --- CMakeLists.txt | 2 +- src/handlers/loop.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b738d89..d27cf5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project(controller - VERSION 0.3.3 + VERSION 0.3.4 LANGUAGES C) add_executable(controller src/main.c) diff --git a/src/handlers/loop.c b/src/handlers/loop.c index 76a5999..f2c6671 100644 --- a/src/handlers/loop.c +++ b/src/handlers/loop.c @@ -60,9 +60,13 @@ handler_loop(struct mg_connection *c_mqtt) sprintf(topic_buf, "controller/%s/relay/%u", controller_uid, i); sprintf(payload_buf, "%u", is_on); mg_mqtt_publish(c_mqtt, topic_buf, 0, MG_MQTT_QOS(0), payload_buf, strlen(payload_buf)); - relay->sent_to_broker = 1; + relay->sent_to_broker = (rand() % 45) + 15; LOGGER_DEBUG("sent relay %d status (%d) to mqtt broker\n", i, is_on); } + if(relay->sent_to_broker) + { + --relay->sent_to_broker; + } relay->is_on = is_on; relay->is_on_schedule = is_on_schedule;