Skip to content

Commit

Permalink
port_io: set mqtt status topic when toggled via push button
Browse files Browse the repository at this point in the history
  • Loading branch information
mattzzw committed Jan 20, 2019
1 parent f053c05 commit 4021d40
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions obi_socket/port_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import utime
from . import obi_tools
from . import config as cfg
from . import obi_mqtt

class Button:
"""
Expand All @@ -25,8 +26,14 @@ def button_on_off_callback(pin):
# toggle relay on releasing the button
if pin.value():
toggle_output(cfg.RELAY)
# set LED according to output
s = get_output(cfg.RELAY)
set_output(cfg.LED_R, s)
# publish mqtt get_status
if (s):
obi_mqtt.publish_status(obi_mqtt.mqtt_client, obi_tools.load_cfg(), 'on')
else:
obi_mqtt.publish_status(obi_mqtt.mqtt_client, obi_tools.load_cfg(), 'off')
else:
# check for long_press
pr_time = utime.ticks_ms()
Expand Down

0 comments on commit 4021d40

Please sign in to comment.