Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

GPIO Output update #31

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mqtt-gpio-monitor.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ MONITOR_PIN_NUMBERING = BOARD
MONITOR_OUT_INVERT = False
MONITOR_POLL = 0.1
MONITOR_REFRESH = mqtt-gpio-monitor/refresh
# specify output pins or leave blank for pfio
GPIO_OUTPUT_PINS =
18 changes: 11 additions & 7 deletions mqtt-gpio-monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

PFIO_MODULE = False
GPIO_MODULE = False
GPIO_OUTPUT_PINS = []

# Script name (without extension) used for config/logfile names
APPNAME = os.path.splitext(os.path.basename(__file__))[0]
Expand Down Expand Up @@ -53,6 +52,8 @@
MONITOR_POLL = config.getfloat("global", "monitor_poll")
MONITOR_REFRESH = config.get("global", "monitor_refresh")

GPIO_OUTPUT_PINS = config.get("global", "gpio_output_pins", raw=True)

# Initialise logging
LOGFORMAT = '%(asctime)-15s %(levelname)-5s %(message)s'

Expand Down Expand Up @@ -189,13 +190,16 @@ def on_message(mosq, obj, msg):

if GPIO_MODULE:
if pin not in GPIO_OUTPUT_PINS:
GPIO.setup(pin, GPIO.OUT, initial=GPIO.HIGH)
GPIO_OUTPUT_PINS.append(pin)

if value == 1:
datafx marked this conversation as resolved.
Show resolved Hide resolved
GPIO.output(pin, GPIO.LOW)
logging.debug("Initialising GPIO input pin %d..." % (pin))
if MONITOR_PINS_PUD == "UP":
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
elif MONITOR_PINS_PUD == "DOWN":
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
else:
GPIO.setup(pin, GPIO.IN)
else:
GPIO.output(pin, GPIO.HIGH)
logging.debug("Initialising GPIO output pin %d..." % (pin))
GPIO.setup(pin, GPIO.OUT)

# End of MQTT callbacks

Expand Down