Once RF24Gateway and RF24Ethernet are configured, standard tools can be used to interact with the sensor nodes.
Example of scheduled LED/Lighting control using a Python script.
1
2"""
3TMRh20 - 2015
4A simple example of controlling a RF24Ethernet based sensor node via a python script
5Turn a light on in the evening and off in the morning according to a schedule
6"""
7
8from datetime import datetime
9import syslog
10import time
11from urllib.error import HTTPError, URLError
12from urllib.request import urlopen
13
14
15
16scheduleON = 21
17scheduleOFF = 6
18sensorIP = "10.10.2.4"
19
20
21
22requestON = "http://" + sensorIP + ":1000/ON"
23requestOFF = "http://" + sensorIP + ":1000/OFF"
24lightState = 2
25
26while 1:
27
28 currentHour = datetime.now().hour
29
30
31 if (currentHour >= scheduleON or currentHour < scheduleOFF) and lightState != 1:
32 result = 0
33
34 try:
35 response = urlopen(requestOFF, None, 15)
36 result = response.getcode()
37 except HTTPError as e:
38 syslog.syslog("HTTPError = " + str(e.code))
39 except URLError as e:
40 syslog.syslog("URLError = " + str(e.reason))
41 except Exception:
42 import traceback
43
44 syslog.syslog("generic exception: " + traceback.format_exc())
45
46 if result == 200:
47 syslog.syslog("Light off at %s\n" % datetime.now())
48
49 lightState = 1
50
51
52 elif currentHour >= scheduleOFF and lightState != 0:
53 result = 0
54
55 try:
56 response = urlopen(requestON, None, 15)
57 result = response.getcode()
58 except HTTPError as e:
59 syslog.syslog("HTTPError = " + str(e.code))
60 except URLError as e:
61 syslog.syslog("URLError = " + str(e.reason))
62 except Exception:
63 import traceback
64
65 syslog.syslog("generic exception: " + traceback.format_exc())
66
67 if result == 200:
68 syslog.syslog("Light on at %s\n" % datetime.now())
69
70 lightState = 0
71
72
73 time.sleep(60)