summaryrefslogtreecommitdiffstats
path: root/examples/clients
diff options
context:
space:
mode:
Diffstat (limited to 'examples/clients')
-rw-r--r--examples/clients/coap-client.py15
-rw-r--r--examples/clients/webiopi-client.py46
2 files changed, 61 insertions, 0 deletions
diff --git a/examples/clients/coap-client.py b/examples/clients/coap-client.py
new file mode 100644
index 0000000..eba80e9
--- /dev/null
+++ b/examples/clients/coap-client.py
@@ -0,0 +1,15 @@
1from webiopi.protocols.coap import *
2from time import sleep
3
4client = COAPClient()
5client.sendRequest(COAPPost("coap://224.0.1.123/GPIO/25/function/out"))
6state = True
7
8while True:
9 response = client.sendRequest(COAPPost("coap://224.0.1.123/GPIO/25/value/%d" % state))
10 if response:
11 print("Received response:\n%s" % response)
12 state = not state
13 else:
14 print("No response received")
15 sleep(0.5)
diff --git a/examples/clients/webiopi-client.py b/examples/clients/webiopi-client.py
new file mode 100644
index 0000000..c277682
--- /dev/null
+++ b/examples/clients/webiopi-client.py
@@ -0,0 +1,46 @@
1from webiopi.clients import *
2from time import sleep
3
4# Create a WebIOPi client
5client = PiHttpClient("192.168.1.234")
6#client = PiMixedClient("192.168.1.234")
7#client = PiCoapClient("192.168.1.234")
8#client = PiMulticastClient()
9
10client.setCredentials("webiopi", "raspberry")
11
12# RPi native GPIO
13gpio = NativeGPIO(client)
14gpio.setFunction(25, "out")
15state = True
16
17# DAC named "dac1"
18dac = DAC(client, "dac1")
19
20# ADC named "adc1"
21adc = ADC(client, "adc1")
22value = 0.0
23
24# Temperature sensor named "temp0"
25temp = Temperature(client, "temp0")
26
27while True:
28 # toggle digital state
29 state = not state
30 gpio.digitalWrite(25, state)
31
32 # increase analog value
33 value += 0.01
34 if value > 1.0:
35 value = 0.0
36 dac.writeFloat(0, value)
37
38 # DAC output 0 is wired to ADC input 1
39 val = adc.readFloat(1)
40 print("Analog = %.2f" % val)
41
42 # Retrieve temperature
43 t = temp.getCelsius()
44 print("Temperature = %.2f Celsius" % t)
45
46 sleep(1)