Branch | Travis |
---|---|
master | |
dev |
This is a client application that runs on RPi and streams sensors data to gateway.
The client will read each sensor's state every X
ms. After reading, it will report on each change of state immediately or at least once every Y
seconds (even if the state wasn't changed) to the gateway. This will provide an efficient way of getting real-time state of sensors and track of online/offline clients (due to network or other issues).
For each sensor a separated thread is spinned, so the IO operations won't block reporting of different sensors.
The following parts required:
- Raspberry Pi board
- WiFi dongle (optional if there is LAN socket)
- If the WiFi dongle used at least 2A power adapter is required.
- Breadboard (optional)
- One LED connected to wPi=0 or BCM=17 pin. The LED has 4 states:
- On - client launched, but no request is sent to gateway
- Slow blinking - latest request were successfull
- Fast blinking - latest request wasn't sent due error (timeout, network errors, etc)
- Off - client terminated
- 2 reed switches connected to wPi=5,7 or BCM=4,24.
All parts should be connected in the following way:
The only prerequisite is to have environment variables which defines the endpoint of API and a security token.
Those can be defined either simply in /etc/environment
:
ENTTOI_ENDPOINT="[gateway endpoint URI]"
ENTTOI_CLIENT_TOKEN="[client's token]"
Since GPIO requires elevations, environment variables needs to be added for sudo
sudo visudo
then add:
Defaults env_keep +="ENTTOI_ENDPOINT"
Defaults env_keep +="ENTTOI_CLIENT_TOKEN"
Deploy the /
folder into Raspberry Pi and start client from terminal:
sudo python app.py
The client daemonized using Stephen's fairly painless trick.
Assuming that the project cloned into /home/pi/enttoi-client
(this can me changed in enttoi.sh
), copy init script to /etc/init.d
:
sudo cp enttoi.sh /etc/init.d
Make sure that both enttoi.sh
and service.py
are executable:
sudo chmod 755 /etc/init.d/enttoi.sh
chmod 755 service.py
At this stage you can start and stop service:
sudo /etc/init.d/enttoi.sh start
sudo /etc/init.d/enttoi.sh status
sudo /etc/init.d/enttoi.sh stop
See log file at /tmp/entoi-client.log
for info or errors.
Now, add it to boot sequence:
sudo update-rc.d enttoi.sh defaults