Skip to content
Enttoi Raspberry Pi Python client
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
docs
.gitignore
.travis.yml
LICENSE
README.md
app.py
client.py
enttoi.sh
gpio_input.py
gpio_output.py
pylintrc
service.py

README.md

Enttoi Raspberry Pi client

Branch Travis
master Build Status
dev Build Status

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.

Board schematic

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: Schematic

Application Configurations

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]"

Running as shell application

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

Running as daemon service

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
You can’t perform that action at this time.