Configuration¶
The CLI tool can be configured in different ways.
Note
When using the CLI flag configuration, the API-key still has to be provided via the environment variable VPF730_API_KEY
, since CLI arguments may be visible to other users.
Also the logging needs to be configured via VPF730_LOGLEVEL
.
usage: vpf-730 [-h] {comm,logger,sender} ...
Positional Arguments¶
- command
Possible choices: comm, logger, sender
Chose the type of process to run
Sub-commands¶
comm¶
Manually send ASCII commands to the VPF-730 sensor
vpf-730 comm [-h] [--serial-port SERIAL_PORT] [-c CONFIG] ascii_command
Positional Arguments¶
- ascii_command
The ASCII command to be send to the VPF-730 sensor e.g: D?. The carriage return (r) and line feed (n) at the end MUST NOT be part of the command. It is appended automatically.
Named Arguments¶
- --serial-port
Serial port the VPF-730 sensor is connected to, e.g /dev/ttyS0
config from file¶
Reads the configuration from a file and overrides all previous CLI options
- -c, --config
Path to an .ini config file
If no argument for –serial-port is provided, the configuration will be read from the environment variable VPF730_PORT.
logger¶
Run a logger taking measurements from the VPF-730 sensor and store them in a local database
vpf-730 logger [-h] [--local-db LOCAL_DB] [--serial-port SERIAL_PORT]
[--log-interval [1-30]] [-c CONFIG]
config from CLI¶
- --local-db
Path to the local database
Default:
'vpf_730_local.db'
- --serial-port
Serial port the VPF-730 sensor is connected to, e.g /dev/ttyS0
- --log-interval
the interval to be used for logging e.g. 1 for every minute (minimum), 30 for 30 minutes (maximum)
Default:
1
config from file¶
Reads the configuration from a file and overrides all previous CLI options
- -c, --config
Path to an .ini config file
- If no arguments are provided, the configuration will be read from the environment variables.
VPF730_LOCAL_DB
VPF730_PORT
VPF730_LOG_INTERVAL
For variable descriptions see the CLI arguments above
sender¶
Synchronize the local database with a remote endpoint by sending data via a POST request
vpf-730 sender [-h] [--local-db LOCAL_DB] [--send-interval [1-30]]
[--get-endpoint GET_ENDPOINT] [--post-endpoint POST_ENDPOINT]
[--max-req-len MAX_REQ_LEN] [-c CONFIG]
Named Arguments¶
- --local-db
Path to the local database
Default:
'vpf_730_local.db'
- --send-interval
The interval in which data should be send to the remote server 1, every minute (minimum), 30 for 30 minutes (maximum)
Default:
5
- --get-endpoint
API endpoint to get the status of the remote server i.e. what is the latest data e.g. https://api.example/com/vpf-730/status. The API-Key must be provided as an environment variable VPF730_API_KEY=mykey
- --post-endpoint
API endpoint to send the data to e.g. https://api.example/com/vpf-730/data. The API-Key must be provided as an environment variable VPF730_API_KEY=mykey
- --max-req-len
the maximum number of measurements that are allowed to be send in a single request
Default:
512
config from file¶
Reads the configuration from a file and overrides all previous CLI options
- -c, --config
Path to an .ini config file
- If no arguments are provided, the configuration will be read from the environment variables.
VPF730_LOCAL_DB
VPF730_SEND_INTERVAL
VPF730_GET_ENDPOINT
VPF730_POST_ENDPOINT
VPF730_MAX_REQ_LEN
VPF730_API_KEY
For variable descriptions see the CLI arguments above
configuration file¶
The configuration file is very simple and uses the .ini
format. The configuration file cannot be used together with environment variables or CLI flags. The VPF730_SENTRY_DSN
and VPF730_SENTRY_SAMPLE_RATE
environment variables are an exception.
Warning
When using the configuration file with the -c
, --config
option, all other flags are ignored
[vpf_730]
local_db=local.db
serial_port=/dev/ttyS0
log_interval=1
send_interval=5
get_endpoint=http://localhost:5000/vpf-730/status
post_endpoint=http://localhost:5000/vpf-730/data
max_req_len=512
api_key=deadbeef
Important
make sure to change the file permissions to -rw-------
(only owner can read and write), so other users can’t see the API-key.
chmod 600 config.ini
config from environment¶
Configuration via the environment is implicit, so no additional CLI arguments have to be supplied.
environment variable |
description |
---|---|
|
path to the sqlite database to store the measurements locally |
|
serial port the VPF-730 sensor is connected to |
|
interval used for logging e.g. 1 for every minute |
|
interval in minutes to send data to the endpoint |
|
http endpoint the data should be send to |
|
http endpoint to get the latest date from, the response should have the format |
|
the maximum number of measurements that are allowed to be send in a single request |
|
api key that is used to authenticate to the API endpoint. A header |
|
is optional and allows error tracking using sentry.io. You can provide the DSN via this variable e.g. |
|
is optional, and sets the sample rate for transactions, if |
|
this sets the log level, if not set it defaults to |
using systemd¶
When running the tool on a server it makes sense to set it up as a systemd
service.
This shows the setup for a Debian based distribution.
create a
config.ini
in the working directory, in this case/home/daten
create a virtual python environment in the working directory
python3.10 -m venv venv
install the
vpf-730
packagevenv/bin/pip install vpf-730
setting up the logger¶
create a systemd service file called
vpf-730-logger.service
in/etc/systemd/system/
with the following contents.Important
You want to change the
User
andGroup
andWorkingDirectory
according to the user on your system, that should run this service.[Unit] Description=vpf-730 logger service After=network.target [Service] User=daten Group=daten WorkingDirectory=/home/daten/ # Environment="VPF730_SENTRY_DSN=https://<PUBLIC_KEY>@<SECRET_KEY>.ingest.sentry.io/<PROJECT_ID>" # Environment="VPF730_SENTRY_SAMPLE_RATE=0" ExecStart=venv/bin/vpf-730 logger --config config.ini Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
enable the systemd service to be started when the system boots
sudo systemctl enable vpf-730-logger.service
you can now start the service using
sudo systemctl start vpf-730-logger
the systemd status should now display the service as active (running)
sudo systemctl status vpf-730-logger
you can check for error using the journal
sudo journalctl --unit vpf-730-logger.service
setting up the sender¶
create a systemd service file called
vpf-730-sender.service
in/etc/systemd/system/
with the following contents.Important
You want to change the
User
andGroup
andWorkingDirectory
according to the user on your system, that should run this service.[Unit] Description=vpf-730 sender service After=network.target [Service] User=daten Group=daten WorkingDirectory=/home/daten/ # Environment="VPF730_SENTRY_DSN=https://<PUBLIC_KEY>@<SECRET_KEY>.ingest.sentry.io/<PROJECT_ID>" # Environment="VPF730_SENTRY_SAMPLE_RATE=0" ExecStart=venv/bin/vpf-730 sender --config config.ini Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
enable the systemd service to be started when the system boots
sudo systemctl enable vpf-730-sender.service
you can now start the service using
sudo systemctl start vpf-730-sender
the systemd status should now display the service as active (running)
sudo systemctl status vpf-730-sender
you can check for error using the journal
sudo journalctl --unit vpf-730-sender.service