From 343722086b547c5c56e17420969557b36b0be620 Mon Sep 17 00:00:00 2001 From: arofarn Date: Wed, 22 Apr 2020 01:44:21 +0200 Subject: [PATCH] Add delay before publishing brightness change --- code/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/main.py b/code/main.py index 82f8579..5390cea 100644 --- a/code/main.py +++ b/code/main.py @@ -209,6 +209,7 @@ MqttMultiPublish(data) time.sleep(1) +BRIGHTN_DATA = None while True: @@ -217,8 +218,9 @@ while True: if BRIGHTN != ENCODER.value: print(ENCODER.value) BRIGHTN = ENCODER.value - MqttMultiPublish([['brightness/date', now(rtc), True, 1], - ['brightness/value', "{}".format(BRIGHTN), True, 0]]) + MQTT_TIMER = time.ticks_add(time.ticks_ms(), MQTT_DELAY * 1000) + BRIGHTN_DATA = [['brightness/date', now(rtc), True, 1], + ['brightness/value', "{}".format(BRIGHTN), True, 0]] # Mise à jour des LED light_modes.update_neopixel(CURRENT_MODE, @@ -232,3 +234,8 @@ while True: PWR, CURRENT_MODE) BUTTN_STATE = ENC_BUT.value() + + # On n'envoie les données de luminosité qu'une fois stabilisée (MQTT_DELAY) + if BRIGHTN_DATA is not None and time.ticks_diff(time.ticks_ms(), MQTT_TIMER) >= 0: + MqttMultiPublish(BRIGHTN_DATA) + BRIGHTN_DATA = None