I've been working on a doorbell script, this should trigger when the specific GPIO pin goes low.
Code: Select all
#!/usr/bin/python
# Doorbell py with read contact uitlezen,
# GPIO 18 to Ground when button is pushed
# Release 1
# Author J. Jeurissen / M. van Wijngaarden
# Copyright (c) 2015 J. Jeurissen / (c) 2017 M. van Wijngaarden
# Python 3
import urllib
#import urllib.request
import json
import RPi.GPIO as GPIO
import time
# Settings for the domoticz server
domoticzserver="192.168.2.100:8080"
domoticzusername = ""
domoticzpassword = ""
domoticzurl = 'http://'+domoticzserver+'/json.htm?type=command¶m=switchlight&idx=189&switchcmd=On'
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
response = urllib.urlopen(domoticzurl)
data = json.loads(response.read())
print data
time.sleep(5.0)
Here's my crontab:
Code: Select all
pi@raspberrypi:~$ crontab -e
@reboot /usr/bin/python /home/pi/domoticz/scripts/python/doorbellgpio.py >/home/pi/domoticz/scripts/python/logs/cronlog 2>&1
Code: Select all
@reboot /usr/bin/python /home/pi/domoticz/scripts/python/doorbellgpio.py
Here's how i start the script manually and the result when the doorbell (button pressed) rings.
Though, i have to say that i don't understand the line below "button pressed"... does that indicate an error?
Code: Select all
pi@raspberrypi:~$ python /home/pi/domoticz/scripts/python/doorbellgpio.py
Button Pressed
{u'status': u'ERROR', u'message': u'WRONG CODE', u'title': u'SwitchLight'}
Thanks in advance.
Marco