OpenSprinkler › Forums › Hardware Questions › OpenSprinkler › Starting OS from Data from Thingspeak
- This topic has 11 replies, 3 voices, and was last updated 6 years, 7 months ago by Ray.
-
AuthorPosts
-
January 26, 2018 at 2:59 pm #48774
gt244ParticipantHi All,
I have an moisture and temp sensor setup that sends data to Thingspeak.
I would like to have OS start when the Temp is at and certain level (This would be for frost protection when water is sprayed over trees and freezes on the buds which creates latent heat) and also when the moisture is at an certain KPA reading.
I have all this data in ThingSpeak but how do I get OS to start when these conditions are meet?
Any ideas much appreciated? I was thinking something with IFTTT but not sure where to start.
Many Thanks,
Ben
January 26, 2018 at 3:38 pm #48775
MikeParticipantI upload soil moisture readings to ThingSpeak and use the readings to start a zone on my OS. I included the command to start the irrigation in the Python script that uploads the readings to my ThingSpeak account. The OS API covers how to use the commands. Since I don’t want to miss an irrigation cycle if my internet connection is lost, I make sure to start watering even if the upload to ThingSpeak fails.
Mike
January 26, 2018 at 4:35 pm #48776
gt244ParticipantHi Mike,
Thanks for that.
Are you able to provide an copy of the code that you are using? Or point me towards the correct place in the OS API.
I am running an RPI that picks up data from the sensor stations. The RPI then uploads this data to thingspeak.
So I should just be able to add the command to start the OS in my script that uploads to thingspeak.
It will be starting an program.
Cheers,
Ben
January 26, 2018 at 5:13 pm #48779
MikeParticipantIf you’re starting a program, take a look at section 12. Manually Start a Program. That’s the same way I’m doing it.
January 27, 2018 at 3:19 pm #48783
gt244ParticipantHi Mike,
Thanks for your help.
Still a little confused. You include the code in section 12 in your python script that uploads to Thingspeak. But how does that talk to the OS?
Thanks,
Ben
January 29, 2018 at 6:56 am #48794
MikeParticipantBen,
The lines of code in my Python script that turn on the irrigation look like this:
import requests <snip> if min(SoilMoistureReadings) < WateringThreshold: #Manually start an OpenSprinkler program r = requests.get('http://127.0.0.1:8080/mp?pw=' + MD5_PW + '&pid=' + pid + '&uwt=' + uwt)
You’ll need to substitute your own values in – like the IP address of your OS. Does this help?
Mike
January 31, 2018 at 6:50 pm #48820
gt244ParticipantCheers Mike!
Will give that a go.
February 19, 2018 at 2:01 am #49138
gt244ParticipantHi 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
February 19, 2018 at 11:30 am #49141
RayKeymaster@gt244: when you said “Still having some trouble” — can you be more specific? Does the Python script report any error? Generally you have to do a bit of debugging work to figure out what’s going wrong.
February 19, 2018 at 1:57 pm #49159
gt244ParticipantHi Ray,
Just need some time to get my head around it.
I think with the min function I need an list.
Thanks,
Ben
February 20, 2018 at 8:07 pm #49172
gt244ParticipantThanks all for the help it is all up and going and here is the code below if anyone else is having trouble.
list1 = (line.split(",")[7]) frost = str(30) if (list1 < frost): #Manually start an OpenSprinkler program r = requests.get('http://12X.60.XXX.2X5/mp?pw=a6d82bcedXXXef1e9bbXXX83225c&pid=0&uwt=0') print (r.text)
May 17, 2018 at 10:12 am #50043
RayKeymasterThanks for sharing.
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › Hardware Questions › OpenSprinkler › Starting OS from Data from Thingspeak