-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpico_follower_actor.py
50 lines (45 loc) · 1.24 KB
/
pico_follower_actor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import RPi.GPIO as GPIO
import time
import os
import sys
import thread
import requests
#import json
# this program reads pico status and put chiller on
# 20170530 by Ethen
chiller_relay = 4 #relay1
sparge_relay = 3 #relay2
chiller_step = "Chill"
sparge_step = "Heat to Boil"
# please change your device id here
url = "http://picofollower.anotherdream.tw:81/device/<device_id>/status"
#url = "http://www.ccsakura-net.com/up/pico.txt"
response = requests.get(url)
#data = response.json
data = response.text
#print data
# todo: error handeling
#bad_r.status_code
#http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
GPIO.setmode(GPIO.BCM)
#GPIO.cleanup()
GPIO.setup(chiller_relay, GPIO.OUT)
GPIO.setup(sparge_relay, GPIO.OUT)
sp = data.split(':');
#print len(sp)
if len(sp)==1:
print data+" action:reset"
GPIO.output(chiller_relay, GPIO.LOW)
GPIO.output(sparge_relay, GPIO.LOW)
sys.exit(0)
print sp[1].strip()
if sp[1].strip()==chiller_step:
print data+" action:enable chiller"
GPIO.output(chiller_relay, GPIO.HIGH)
elif sp[1].strip()==sparge_step:
print data+" action:enable sparge"
GPIO.output(sparge_relay, GPIO.HIGH)
else:
print data+" action:reset"
GPIO.output(chiller_relay, GPIO.LOW)
GPIO.output(sparge_relay, GPIO.LOW)