· 9 years ago · Nov 19, 2016, 02:44 AM
1
2import time
3import grovepi
4import math
5import sys
6import twython from TWYTHON
7
8APP_KEY = 'jgv6yK6miS6nLhqbhfTYPBO5a' # Customer Key here
9APP_SECRET = 'XlhigYvHSz4CVrCwI4v4Wxf2jYxKmIcSXPjAJUOro82z0IjK1s' # Customer secret here
10OAUTH_TOKEN = '765360661425590272-7uNwRu2G2O0DDBw9NVGLBKgaC6svLAN' # Access Token here
11OAUTH_TOKEN_SECRET = 'prAWU5hVfDqWoK6KBeBXUA1qxtdOMrGyEt6qFKXrgj1KN' # Access Token Secret here
12
13twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
14
15
16# Connections
17light_sensor = 1 # port A1
18
19# Connect to Twitter
20threshold = 10
21
22while True:
23 try:
24 print ("Checking")
25 # Get sensor value
26 sensor_value = grovepi.analogRead(light_sensor)
27
28 # Calculate resistance of sensor in K
29 resistance = (float)(1023 - sensor_value) * 10 / sensor_value
30 # If / Else statment to tweet if the milk needs filling
31 if resistance > threshold:
32 # Tweeting to Fill Milk
33 twitter.update_status(status="The Milk Needs Filling" + time.strftime)
34 #print("The Milk Needs Filling")
35 else:
36 # Print following to command line
37 print("The Milk Does Not Need Filling At This Time")
38 print("Waiting")
39 time.sleep(60
40
41 except IOError:
42 print("Error")
43 except KeyboardInterrupt:
44 exit()
45 except:
46 print("Duplicate Tweet or Twitter Refusal")