Collects measurement reports from various sensors and send them to the station-monitoring-service.
Project description
Station client
Scripts to read one or multiple sensors connected to the I2C bus on a Raspberry Pi and submit them to the station-monitoring-service.
Prerequisites
Before you can install and connect the sensors, make sure of the following:
- Optional: copy your public SSH key to your Pi for Passwordless SSH access
- I2C must be enabled. See Enabling I2C
- The station-monitoring-service is running. See running the Station Monitoring Service
- The station exists in the service and contains the sensors that you plan to connect to it.
Installation
Learn how to connect the sensor and install the Station Client.
-
Login to your Pi via SSH
-
Create virtual env
The virtual env will contain all the software needed to run the station-client in a nicely isolated and dedicated environment, so it won't interfere with anything else on the system.
cd ~ mkdir rcm && cd rcm python3 -m venv venv source venv/bin/activate
(1): Optional: Navigate to the home folder, just in case you were in another directory unintentionally.
(2): Creates the directory
rcm
and navigate into it. This will be the folder containing everything related to the Residential Climate Monitoring project.(3): Create a virtual env with the name
venv
. All the necessary python package will end up here.(4): Activate the virtual env.
-
Install Station Client
To install the package:
pip install rcm-station-client
Alternatively, you can also directly clone it if you have a fork or want to make customizations:
git clone https://gitlab.com/residential-climate-monitoring/station-client.git cd station-client pip install -r requirements.txt
Configuration
The Station Client requires some configuration settings before it will work.
-
Create .env file
All the configuration will be read from a
.env
file. Create it in the root of the "rcm" folder you created during installation. After this step your directory structure should look like this:rcm/ - .env - venv/
Note: if you cloned the repo, you must edit the .env file of the project: "rcm/station-client/.env" directly.
-
Configure station settings
Copy and paste the following into the file:
station-name=test sensors=SHT31-D measurements-report-endpoint=https://raspberrypi.local:8080/measurement-reports
station-name
- Configure the name of the station, typically the location where it is located. E.g. 'living-room'. This must match with the name of the station as it is registered in the Station Monitoring Service.sensors
- A comma separated list of the sensors connected to the station. Change this to match the setup of your station.measurements-report-endpoint
- The endpoint where the measurements need to be submitted to. Change "raspberry" to the hostname or change "raspberry.local" to the IP address of the raspberry that runs the Station Monitoring Service. -
Configure security settings
Security is enabled by default on both the client and server side. You can create a free account on Auth0 to obtain the necessary settings, or disable security. If you have an Auth0 account you will need your application client id, client secret, audience and tenant + zone.
To disable security, add the following:
auth-enabled=false
To configure with Auth0, add the following:
auth-client-id= auth-client-secret= auth-audience= auth-token-endpoint=https://${auth0-tenant}.${auth0-region}.auth0.com/oauth/token
auth-client-id
- In Auth0 you'll have to create an application, which will represent the Residential Climate Monitoring system. Put the client-id here.auth-client-secret
- This is the secret, make sure this token is safe and access to the file and system is limited to "authorized personnel" only!auth-audience
- This is the identifier of the API, that you created as part of your Auth0 application. This should match with the station monitoring service.auth-token-endpoint
- This is the endpoint that will be called by the Station Client to obtain an M2M token. Replace it with your tenant and region.Note: You may need to change the Token Expiration in Auth0 because the token endpoint has a quota of 1.000 requests / month. If you intend to run the client regularly (see usage section) then you will quickly exceed this quota, especially if you have multiple stations running. The Station Client caches the token by writing it to a file along with the timestamp when it will expire and request a new one only when it is expired. Setting the Token Expiration to 86400 seconds (24 hours) will allow you to connect up to 32 stations before hitting the quota.
Sensor specific configuration
Some sensors allow for customization. Below you can find more details for each sensor.
-
BME680
The sensor can be calibrated with sea level pressure to calculate the current altitude. This is not implemented yet, stay tuned.
-
SHT31-D
The SHT31-D has two modes:
Single
andPeriodic
. Currently, it only supports Single (default) mode.The sensor also comes with a heater than can be turned on to evaporate any condensation. It is planned to turn on the heater automatically in the future if humidity levels exceed a certain threshold. Stay tuned.
To use the secondary address, add the following to the
.env
file:sht31d-secondary-address=true
-
TSL2591
The TSL2591 has configurable
gain
andintegration time
for various lighting conditions. Learn more about Gain and timing. See the TSL2591 reference sheet for an overview of values you can expect in different conditions.Add the following to the
.env
file to adjust gain and/or timing:tsl2591-gain=GAIN_MEDIUM tsl2591-integration-time=100MS
tsl2591-gain
- Sets the gain level, the higher the level the more the signal will be "amplified". Low light conditions requires more gain to be measurable.Supported values are:
GAIN_LOW
- Sets the gain to 1x (bright light)GAIN_MEDIUM
- Sets the gain to 25x (general purpose) - defaultGAIN_HIGH
- Sets the gain to 428x (low light)GAIN_MAX
- Sets the gain to 9876x (extremely low light)
tsl2591-integration-time
- Set the integration time, a higher value allows the sensor to "capture" more light.Supported values are:
100MS
- 100 milliseconds - default200MS
- 200 milliseconds300MS
- 300 milliseconds400MS
- 400 milliseconds500MS
- 500 milliseconds600MS
- 600 milliseconds
-
SGP30
The SGP30 requires calibration before it can be used.
sgp30-init-baseline=true sgp30-baseline-file=/home/pi/rcm-sgp30-baseline.txt
sgp30-init-baseline
- Set this to true to calibrate the sensor and write the baseline file to the baseline file.sgp30-baseline-file
- The path to the file where the baseline values are stored.
Hardware installation
After the software is installed and configured, it is time to connect the sensor(s):
RPIO | Sensor |
---|---|
3.3v | VIN |
GND | GND |
GPIO 2 (SDA) | SDA [1] |
GPIO 3 (SCL) | SCL [2] |
Note 1: On the BME680 this pin is called "SDI" instead.
Note 2: On the BME680 this pin is called "SCK" instead.
Addresses
The I2C addresses are listed below:
Sensor | Address | Secondary Address |
---|---|---|
BME680 | 0x77 | |
SHT31-D | 0x44 | 0x45 |
TSL2591 | 0x29 | |
SGP30 | 0x58 |
Note: To use the secondary address, see sensor specific configuration.
Calibration
This section describes how to calibrate sensors. This should be done once before first usage.
-
SGP30
Set the
sgp30-init-baseline
property to true in the .env file and run the station_client manually once and leave it running for at least one hour, ideally 12 hours. Each hour it will write the baseline values to the baseline file. Once this process is finished, and the file is ready you can switch the property back to false or comment it out and run the script as described below.
Usage
To run the station client manually, run:
python station_client.py
To run the station client periodically, configure it using Crontab:
To edit crontab settings:
crontab -e
* * * * * /home/pi/rcm/venv/bin/python3 /home/pi/rcm/venv/lib/python3.7/site-packages/rcm/station_client.py
Note: if you cloned the repo, you must change the path accordingly, e.g.: "* * * * * /home/pi/rcm/venv/bin/python3 /home/pi/rcm/station-client/rcm/station_client.py
The * * * * *
expression executes the script once every minute. The 0 0 * * *
expression executes the script once a day at midnight.
# * * * * * command to execute
# ┬ ┬ ┬ ┬ ┬
# │ │ │ │ └─ day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └─ month (1 - 12)
# │ │ └─ day of month (1 - 31)
# │ └─ hour (0 - 23)
# └─ min (0 - 59)
Troubleshooting
To troubleshoot, the logs can be found at: /home/pi/rcm-station-client.log
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for rcm_station_client-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be3a601c88374e969c2f1ba920164470ca9b8488cfff83fd05e256a7f9a5c57 |
|
MD5 | db1f0175dd08a9b58c62f70578b49d6b |
|
BLAKE2b-256 | c38ca4fead284b6d0a54f789610af65bb3bff3fcc5a7c2b8fe6e1b22d6e68910 |