add: random status sending to broker

This commit is contained in:
Tobias Reisinger 2020-08-25 11:42:05 +02:00
parent ce674a746a
commit db7eb6305c
2 changed files with 6 additions and 2 deletions

View file

@ -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)

View file

@ -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;