Last active
August 29, 2015 14:04
-
-
Save LuisFDuarte/113447fbf28762664503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pifacedigitalio #Library for pifacedigitalio #Library for delays | |
from ubidots import ApiClient #Library for Ubidots | |
pifacedigital = pifacedigitalio.PiFaceDigital() #Declare piface object | |
##Connect to Ubidots | |
try: | |
api = ApiClient("1fc7a56bf4b539725ace7a3f4aa623e9e9620612") #Don't forget to put your own Apikey | |
valve = api.get_variable('53cd4cb07625425b70f5c21e') #Put here your valve ID's | |
valveState = api.get_variable("53ce95547625420403d81468") #Put here your realy state ID's | |
except: | |
print("cant connect") #Check your Apikey, variable's ID and internet connection | |
while(True): | |
lastValue = valve.get_values(1) #Get the last value of valve from Ubidots | |
rele = pifacedigital.relays[0].value #Save relay state | |
valveState.save_value({'value':rele}) #Send relay state to Ubidots | |
for a in lastValue: | |
print a['value'] | |
if(a['value']): #Turn on or off the relay | |
pifacedigital.output_pins[0].turn_on() | |
else: | |
pifacedigital.output_pins[0].turn_off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not seem to be working, when I run this with Python 3 I get the below:
File "/usr/share/doc/python3-pifacedigitalio/examples/valve.py", line 19
print a['value']
^
SyntaxError: invalid syntax
(not sure if this wil lmess up the alignment, in console that carat points at the letter 'a')
If I run this as Python2/Python I get this:
ImportError: No module named ubidots