diff options
| -rw-r--r-- | examples/scripts/gas/script.py | 104 | ||||
| -rw-r--r-- | examples/scripts/icmp/script.py | 60 | ||||
| -rw-r--r-- | htdocs/app/gas-control/index.html | 120 | ||||
| -rw-r--r-- | htdocs/dev.html | 25 | ||||
| -rw-r--r-- | htdocs/index.html | 15 |
5 files changed, 254 insertions, 70 deletions
diff --git a/examples/scripts/gas/script.py b/examples/scripts/gas/script.py new file mode 100644 index 0000000..4ac95d0 --- /dev/null +++ b/examples/scripts/gas/script.py | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | import webiopi | ||
| 2 | |||
| 3 | webiopi.setDebug() | ||
| 4 | |||
| 5 | GPIO = webiopi.GPIO | ||
| 6 | |||
| 7 | ICMP_DEVICE = "icmp0" | ||
| 8 | GAS_PORT = 0 | ||
| 9 | SLEEP = 1 | ||
| 10 | |||
| 11 | class State(object): | ||
| 12 | def __init__(self, name, checks, expr, func): | ||
| 13 | self.name = name | ||
| 14 | self.checks = checks | ||
| 15 | self.cnt = 0 | ||
| 16 | self.enabled = True | ||
| 17 | self.expr = expr | ||
| 18 | self.func = func | ||
| 19 | |||
| 20 | def incr(self, duration): | ||
| 21 | if not self.expr(duration): | ||
| 22 | self.cnt = 0 | ||
| 23 | return | ||
| 24 | if self.cnt_reached(): | ||
| 25 | return | ||
| 26 | self.cnt += 1 | ||
| 27 | if self.cnt_reached() and self.enabled: | ||
| 28 | self.trigger() | ||
| 29 | |||
| 30 | def trigger(self): | ||
| 31 | webiopi.debug("GAS script - %s triggered" % (self.name)) | ||
| 32 | self.func() | ||
| 33 | |||
| 34 | def cnt_reached(self): | ||
| 35 | return self.cnt >= self.checks | ||
| 36 | |||
| 37 | def __str__(self): | ||
| 38 | enabled = "enabled" if self.enabled else "disabled" | ||
| 39 | return "%s(%s) %d/%d" % (self.name, enabled, self.cnt, | ||
| 40 | self.checks) | ||
| 41 | |||
| 42 | _online = State('Online', 5, lambda x: x > 0 and x < 300, | ||
| 43 | lambda: GPIO.digitalWrite(GAS_PORT, GPIO.LOW)) | ||
| 44 | _offline = State('Offline', 30, lambda x: not _online.expr(x), | ||
| 45 | lambda: GPIO.digitalWrite(GAS_PORT, GPIO.HIGH)) | ||
| 46 | STATES = [ _online, _offline ] | ||
| 47 | |||
| 48 | def setup(): | ||
| 49 | webiopi.debug("GAS script - setup") | ||
| 50 | GPIO.setFunction(GAS_PORT, GPIO.OUT) | ||
| 51 | GPIO.digitalWrite(GAS_PORT, GPIO.HIGH) | ||
| 52 | |||
| 53 | def loop(): | ||
| 54 | icmp = webiopi.deviceInstance(ICMP_DEVICE) | ||
| 55 | if icmp is not None: | ||
| 56 | duration = icmp.getMilliseconds() | ||
| 57 | webiopi.debug("GAS script - %s: %dms" % (ICMP_DEVICE, duration)) | ||
| 58 | for s in STATES: | ||
| 59 | s.incr(duration) | ||
| 60 | webiopi.debug("GAS script - %s" % (s)) | ||
| 61 | webiopi.sleep(SLEEP) | ||
| 62 | |||
| 63 | def destroy(): | ||
| 64 | webiopi.debug("GAS script - destroy") | ||
| 65 | GPIO.setFunction(GAS_PORT, GPIO.OUT) | ||
| 66 | GPIO.digitalWrite(GAS_PORT, GPIO.HIGH) | ||
| 67 | |||
| 68 | @webiopi.macro | ||
| 69 | def gas_getPort(): | ||
| 70 | global GAS_PORT | ||
| 71 | return str(GAS_PORT) | ||
| 72 | |||
| 73 | _force = None | ||
| 74 | |||
| 75 | @webiopi.macro | ||
| 76 | def gas_getForce(): | ||
| 77 | global _force | ||
| 78 | if _force is None: | ||
| 79 | return "" | ||
| 80 | return _force.name | ||
| 81 | |||
| 82 | @webiopi.macro | ||
| 83 | def gas_setForce(state = None): | ||
| 84 | global _force | ||
| 85 | webiopi.debug("GAS script - forcing state %s" % (state)) | ||
| 86 | |||
| 87 | if state is None: | ||
| 88 | _force = None | ||
| 89 | for s in STATES: | ||
| 90 | s.enabled = True | ||
| 91 | # trigger again if mode is automatic | ||
| 92 | if s.cnt_reached(): | ||
| 93 | s.trigger() | ||
| 94 | else: | ||
| 95 | for s in STATES: | ||
| 96 | if s.name == state: | ||
| 97 | _force = s | ||
| 98 | break | ||
| 99 | if _force is not None: | ||
| 100 | for s in STATES: | ||
| 101 | s.enabled = False | ||
| 102 | _force.trigger() | ||
| 103 | |||
| 104 | return gas_getForce() | ||
diff --git a/examples/scripts/icmp/script.py b/examples/scripts/icmp/script.py deleted file mode 100644 index 41de666..0000000 --- a/examples/scripts/icmp/script.py +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | import webiopi | ||
| 2 | |||
| 3 | webiopi.setDebug() | ||
| 4 | |||
| 5 | GPIO = webiopi.GPIO | ||
| 6 | |||
| 7 | ICMP_DEVICE = "icmp0" | ||
| 8 | GAS_PORT = 0 | ||
| 9 | SLEEP = 1 | ||
| 10 | |||
| 11 | class State(object): | ||
| 12 | def __init__(self, name, checks, expr, func): | ||
| 13 | self.name = name | ||
| 14 | self.checks = checks | ||
| 15 | self.cur = 0 | ||
| 16 | self.expr = expr | ||
| 17 | self.func = func | ||
| 18 | |||
| 19 | def set(self, duration): | ||
| 20 | if not self.expr(duration): | ||
| 21 | self.cur = 0 | ||
| 22 | return | ||
| 23 | if (self.cur >= self.checks): | ||
| 24 | return | ||
| 25 | self.cur += 1 | ||
| 26 | if (self.cur == self.checks): | ||
| 27 | webiopi.debug("ICMP script - State(%s) triggered" % (self.name)) | ||
| 28 | self.func() | ||
| 29 | |||
| 30 | def __str__(self): | ||
| 31 | return "State(%s) %d/%d" % (self.name, self.cur, self.checks) | ||
| 32 | |||
| 33 | online = State('Online', 2, lambda x: x > 0 and x < 300, | ||
| 34 | lambda: GPIO.digitalWrite(GAS_PORT, GPIO.LOW)) | ||
| 35 | offline = State('Offline', 30, lambda x: not online.expr(x), | ||
| 36 | lambda: GPIO.digitalWrite(GAS_PORT, GPIO.HIGH)) | ||
| 37 | STATES = [ online, offline ] | ||
| 38 | |||
| 39 | def setup(): | ||
| 40 | webiopi.debug("ICMP script - setup") | ||
| 41 | GPIO.setFunction(GAS_PORT, GPIO.OUT) | ||
| 42 | GPIO.digitalWrite(GAS_PORT, GPIO.HIGH) | ||
| 43 | |||
| 44 | def loop(): | ||
| 45 | icmp0 = webiopi.deviceInstance(ICMP_DEVICE) | ||
| 46 | if icmp0 is None: | ||
| 47 | webiopi.sleep(SLEEP) | ||
| 48 | return | ||
| 49 | |||
| 50 | duration = icmp0.getMilliseconds() | ||
| 51 | webiopi.debug("ICMP script - %s: %dms" % (ICMP_DEVICE, duration)) | ||
| 52 | for s in STATES: | ||
| 53 | s.set(duration) | ||
| 54 | webiopi.debug("ICMP script - %s" % (s)) | ||
| 55 | webiopi.sleep(SLEEP) | ||
| 56 | |||
| 57 | def destroy(): | ||
| 58 | webiopi.debug("ICMP script - destroy") | ||
| 59 | GPIO.setFunction(GAS_PORT, GPIO.OUT) | ||
| 60 | GPIO.digitalWrite(GAS_PORT, GPIO.HIGH) | ||
diff --git a/htdocs/app/gas-control/index.html b/htdocs/app/gas-control/index.html new file mode 100644 index 0000000..0e9b3a1 --- /dev/null +++ b/htdocs/app/gas-control/index.html | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| 2 | <html> | ||
| 3 | <head> | ||
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 5 | <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> | ||
| 6 | <title>WebIOPi | Gas Control</title> | ||
| 7 | <script type="text/javascript" src="/webiopi.js"></script> | ||
| 8 | <script type="text/javascript"> | ||
| 9 | webiopi().ready(function() { | ||
| 10 | var GAS_PORT = 0; | ||
| 11 | webiopi().callMacro("gas_getPort", [ ], function(macro, args, data) { | ||
| 12 | GAS_PORT = parseInt(data) | ||
| 13 | }); | ||
| 14 | |||
| 15 | |||
| 16 | var valveButton = w().createGPIOButton(GAS_PORT, "Gas Ventil: unbekannt"); | ||
| 17 | valveButton.unbind("click"); | ||
| 18 | valve_old_value = -1 | ||
| 19 | valveButton.on("updateValue", function(event, gpio, old_value, value) { | ||
| 20 | if (valve_old_value != value) { | ||
| 21 | valveButton.text(value == 0 ? "Gas Ventil auf" : "Gas Ventil zu"); | ||
| 22 | valve_old_value = value | ||
| 23 | } | ||
| 24 | }); | ||
| 25 | $("#valve").html(valveButton); | ||
| 26 | |||
| 27 | |||
| 28 | var forceModes = [ "", "Online", "Offline" ]; | ||
| 29 | var forceMode = forceModes[0]; | ||
| 30 | var forceButton; | ||
| 31 | var onForce = function(macro, args, data) { | ||
| 32 | forceMode = data; | ||
| 33 | |||
| 34 | var style = (forceMode == "") ? "automatic" : forceMode; | ||
| 35 | var text = "Automatisch"; | ||
| 36 | switch(forceMode) | ||
| 37 | { | ||
| 38 | case forceModes[0]: | ||
| 39 | break; | ||
| 40 | case forceModes[1]: | ||
| 41 | text = "Gas Ventil auf"; | ||
| 42 | break; | ||
| 43 | case forceModes[2]: | ||
| 44 | text = "Gas Ventil zu"; | ||
| 45 | break; | ||
| 46 | } | ||
| 47 | |||
| 48 | forceButton.attr("class", style.toUpperCase()); | ||
| 49 | forceButton.text(text); | ||
| 50 | } | ||
| 51 | |||
| 52 | forceButton = webiopi().createButton("force", "Unbekannt", function() { | ||
| 53 | var i; | ||
| 54 | for (i = 0; i < forceModes.length; i++) { | ||
| 55 | if (forceModes[i] == forceMode) | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | i = (i == forceModes.length - 1) ? 0 : i + 1; | ||
| 59 | webiopi().callMacro("gas_setForce", [ forceModes[i] ], onForce); | ||
| 60 | }); | ||
| 61 | $("#force").html(forceButton); | ||
| 62 | |||
| 63 | |||
| 64 | w().refreshGPIO(true); | ||
| 65 | |||
| 66 | var forceRefresh = function() { | ||
| 67 | webiopi().callMacro("gas_getForce", [ ], onForce); | ||
| 68 | setTimeout(function() { forceRefresh() }, 1000); | ||
| 69 | }; | ||
| 70 | forceRefresh(); | ||
| 71 | }); | ||
| 72 | </script> | ||
| 73 | <style type="text/css"> | ||
| 74 | body { | ||
| 75 | margin: 50px 0px; | ||
| 76 | padding: 0px; | ||
| 77 | } | ||
| 78 | |||
| 79 | #content { | ||
| 80 | width: 300pt; | ||
| 81 | margin: 0px auto; | ||
| 82 | text-align: left; | ||
| 83 | padding: 15px; | ||
| 84 | border: 1px dashed #333; | ||
| 85 | background-color: #eee; | ||
| 86 | line-height: 35pt; | ||
| 87 | } | ||
| 88 | |||
| 89 | button { | ||
| 90 | width: auto; | ||
| 91 | } | ||
| 92 | |||
| 93 | .LOW { | ||
| 94 | background-color: red; | ||
| 95 | } | ||
| 96 | |||
| 97 | .HIGH { | ||
| 98 | background-color: green; | ||
| 99 | } | ||
| 100 | |||
| 101 | .ONLINE { | ||
| 102 | background-color: red; | ||
| 103 | } | ||
| 104 | |||
| 105 | .OFFLINE { | ||
| 106 | background-color: green; | ||
| 107 | } | ||
| 108 | |||
| 109 | .AUTOMATIC { | ||
| 110 | background-color: gray; | ||
| 111 | } | ||
| 112 | </style> | ||
| 113 | </head> | ||
| 114 | <body> | ||
| 115 | <div id="content"> | ||
| 116 | Ventil: <span id="valve"></span><br /> | ||
| 117 | Automatik: <span id="force"></span<br /> | ||
| 118 | </div> | ||
| 119 | </body> | ||
| 120 | </html> | ||
diff --git a/htdocs/dev.html b/htdocs/dev.html new file mode 100644 index 0000000..68c49c9 --- /dev/null +++ b/htdocs/dev.html | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| 2 | <html> | ||
| 3 | <head> | ||
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 5 | <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> | ||
| 6 | <title>WebIOPi | Raspberry Pi IoT Framework</title> | ||
| 7 | </head> | ||
| 8 | <body> | ||
| 9 | |||
| 10 | <h1>WebIOPi Main Menu</h1> | ||
| 11 | |||
| 12 | <h2><a href="/app/gpio-header">GPIO Header</a></h2> | ||
| 13 | <p>Control and Debug the Raspberry Pi GPIO with a display which looks like the physical header.</p> | ||
| 14 | |||
| 15 | <h2><a href="/app/gpio-list">GPIO List</a></h2> | ||
| 16 | <p>Control and Debug the Raspberry Pi GPIO ordered in a single column.</p> | ||
| 17 | |||
| 18 | <h2><a href="/app/serial-monitor">Serial Monitor</a></h2> | ||
| 19 | <p>Use the browser to play with Serial interfaces configured in WebIOPi.</p> | ||
| 20 | |||
| 21 | <h2><a href="/app/devices-monitor">Devices Monitor</a></h2> | ||
| 22 | <p>Control and Debug devices and circuits wired to your Pi and configured in WebIOPi.</p> | ||
| 23 | |||
| 24 | </body> | ||
| 25 | </html> | ||
diff --git a/htdocs/index.html b/htdocs/index.html index 68c49c9..a1671bb 100644 --- a/htdocs/index.html +++ b/htdocs/index.html | |||
| @@ -4,22 +4,17 @@ | |||
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> | 5 | <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> |
| 6 | <title>WebIOPi | Raspberry Pi IoT Framework</title> | 6 | <title>WebIOPi | Raspberry Pi IoT Framework</title> |
| 7 | <meta http-equiv="refresh" content="0; url=/app/gas-control" /> | ||
| 7 | </head> | 8 | </head> |
| 8 | <body> | 9 | <body> |
| 9 | 10 | ||
| 10 | <h1>WebIOPi Main Menu</h1> | 11 | <h1>WebIOPi Main Menu</h1> |
| 11 | 12 | ||
| 12 | <h2><a href="/app/gpio-header">GPIO Header</a></h2> | 13 | <h2><a href="/app/gas-control">Gas Control</a></h2> |
| 13 | <p>Control and Debug the Raspberry Pi GPIO with a display which looks like the physical header.</p> | 14 | <p>Gas Control.</p> |
| 14 | 15 | ||
| 15 | <h2><a href="/app/gpio-list">GPIO List</a></h2> | 16 | <h2><a href="/dev.html">Developer tools</a></h2> |
| 16 | <p>Control and Debug the Raspberry Pi GPIO ordered in a single column.</p> | 17 | <p>Developer tools.</p> |
| 17 | |||
| 18 | <h2><a href="/app/serial-monitor">Serial Monitor</a></h2> | ||
| 19 | <p>Use the browser to play with Serial interfaces configured in WebIOPi.</p> | ||
| 20 | |||
| 21 | <h2><a href="/app/devices-monitor">Devices Monitor</a></h2> | ||
| 22 | <p>Control and Debug devices and circuits wired to your Pi and configured in WebIOPi.</p> | ||
| 23 | 18 | ||
| 24 | </body> | 19 | </body> |
| 25 | </html> | 20 | </html> |
