Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import os
- import datetime
- import pymysql.cursors
- from time import sleep
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(18, GPIO.IN)
- dbHost = "localhost"
- dbUser = "root"
- dbPassword = "XXXX"
- dbName = "weather"
- def getFlag():
- connection = pymysql.connect(host=dbHost, user=dbUser, password=dbPassword, db=dbName)
- try:
- with connection.cursor() as cursor:
- sql = "SELECT flag FROM notice LIMIT 1"
- cursor.execute(sql)
- result = cursor.fetchall()
- return result[0][0]
- except:
- print("Access error")
- finally:
- connection.close()
- return None
- def updateFlag():
- connection = pymysql.connect(host=dbHost, user=dbUser, password=dbPassword, db=dbName)
- try:
- with connection.cursor() as cursor:
- sql = "UPDATE notice SET flag = 0"
- cursor.execute(sql)
- connection.commit()
- except:
- print("Access error")
- finally:
- connection.close()
- try:
- while True:
- result = GPIO.input(18)
- if result == 1 and getFlag() is 1:
- responce = os.system('php weather.php')
- updateFlag()
- print result
- sleep(0.5)
- except KeyboardInterrupt:
- pass
- GPIO.cleanup()
Add Comment
Please, Sign In to add comment