-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgpio.py
More file actions
40 lines (33 loc) · 1.01 KB
/
gpio.py
File metadata and controls
40 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
from util_funct import check_internet, tweet_message
from util_dbase import write_to_dbase
def interrupt_handler(channel):
""" Interrupt based GPIO handler
write to dbase event
send a tweet
"""
json_body = [{
"measurement": "Door",
"tags": {"Location": "Main Input"},
"fields": {"value": 1} }]
if check_internet()==True:
tweet_message("Hop Hop..")
write_to_dbase(json_body,"gpio")
if __name__ == "__main__":
''' detect gpio 5
'''
state = 1
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM) #set up GPIO using BCM numbering
GPIO.setup(5, GPIO.IN) #, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
GPIO.add_event_detect(5, GPIO.FALLING,
callback=interrupt_handler,
bouncetime=200)
while (True):
time.sleep(5)