OpenSprinkler › Forums › Hardware Questions › OpenSprinkler › Starting OS from Data from Thingspeak › Reply To: Starting OS from Data from Thingspeak
February 19, 2018 at 2:01 am
#49138
gt244
Participant
Hi Mike,
Still having some trouble hopefully you can look at the below and see how I am going wrong. Just tacked your code on at the end.
#!/usr/bin/python3
from time import localtime, strftime
import serial
import time
import thingspeak
import requests
channel_id = ()
write_key = ()
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=900)
#ser = serial.Serial('/dev/cu.usbmodem1421', 9600, timeout=900)
while True:
line=ser.readline()
if len(line)==0:
print("Time Out")
sys.exit()
try:
line=line.decode("utf-8")
except:
line=""
print ("unreadable character received")
print (line)
print (len(line.split(",")))
try:
start_char = line.split(",")[0]
write_key = line.split(",")[1]
field_1 = line.split(",")[2]
field_2 = line.split(",")[3]
field_3 = line.split(",")[4]
field_4 = line.split(",")[5]
v_batt = (line.split(",")[6])
temperature = line.split(",")[7]
humidity = line.split(",")[8]
aux = line.split(",")[9]
stop_char = line.split(",")[10]
except:
if start_char != "$":
print ("no start character detected")
try:
channel = thingspeak.Channel(id=channel_id,write_key=write_key)
print (write_key, field_1, field_2, field_3, field_4, v_batt, temperature , humidity, aux)
response = channel.update({1:field_1, 2:field_2, 3:field_3, 4:field_4, 5:v_batt, 6:temperature, 7:humidity,})
print (strftime("%a, %d %b %Y %H:%M:%S", localtime()))
print (response)
except: print ("connection failed",)
if min(temperature) < 25.00:
#Manually start an OpenSprinkler program
r = requests.get('http://122.60.XXX.XXX:8080/mp?pw=a6d82bced638de3def1XXXXbb4983225c&pid=0&uwt=0)
Cheers,
Ben