Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
script.py
Go to the documentation of this file.
1 import webiopi
2 GPIO = webiopi.GPIO # Helper for LOW/HIGH values
3 HEATER = 7 # Heater plugged on the Expander Pin 7
4 MIN = 22 # Minimum temperature in celsius
5 MAX = 24 # Maximum temperature in celsius
6 AUTO = True
7 
8 # setup function is automatically called at WebIOPi startup
9 def setup():
10  mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration
11  mcp.setFunction(HEATER, GPIO.OUT)
12 
13 # loop function is repeatedly called by WebIOPi
14 def loop():
15  if (AUTO):
16  tmp = webiopi.deviceInstance("tmp") # retrieve the device named "tmp" in the configuration
17  mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration
18 
19  celsius = tmp.getCelsius() # retrieve current temperature
20  print("Temperature: %f" % celsius)
21 
22  # Turn ON heater when passing below the minimum temperature
23  if (celsius < MIN):
24  mcp.digitalWrite(HEATER, GPIO.HIGH)
25 
26  # Turn OFF heater when reaching maximum temperature
27  if (celsius >= MAX):
28  mcp.digitalWrite(HEATER, GPIO.LOW)
29 
30  # gives CPU some time before looping again
31  webiopi.sleep(1)
32 
33 # destroy function is called at WebIOPi shutdown
34 def destroy():
35  mcp = webiopi.deviceInstance("mcp") # retrieve the device named "mcp" in the configuration
36  mcp.digitalWrite(HEATER, GPIO.LOW) # turn off to avoid over heating
37 
38 # a simple macro to return heater mode
39 @webiopi.macro
40 def getMode():
41  if (AUTO):
42  return "auto"
43  return "manual"
44 
45 # simple macro to set and return heater mode
46 @webiopi.macro
47 def setMode(mode):
48  global AUTO
49  if (mode == "auto"):
50  AUTO = True
51  elif (mode == "manual"):
52  AUTO = False
53  return getMode()
54 
55 
def getMode
Definition: script.py:40
def loop
Definition: script.py:28
def setMode
Definition: script.py:47
def destroy
Definition: script.py:28
def setup
Definition: script.py:15