This distribution package consists of two main components:
Project description
Sensord
The distribution package consists of two main components.
Sensor Service
- Executable:
sensord
- Manages IoT devices and sensors using the Sensation library.
- Runs as a background process.
- Handles communication and data processing for connected sensors.
- Sends sensor data and events to external systems according to configured endpoints (MQTT, etc.)
Sensor Control CLI
- Executable:
sensorctl
- Provides a command-line tool for controlling and interacting with the Sensor Service.
- Allows users to start, stop, configure, and monitor sensors through the command line.
- Offers a convenient way to manage the Sensor Service and connected devices.
Table of Contents
Installation
The recommended way of installing this service is using pipx, since this is a Python application. See this manual about how to install pipx if it is not already on your system.
Installing for a given user
pipx install sensord
Installing system-wide
If your pipx is installed system-wide, you can also install this service globally.
sudo pipx --global install sensord
This makes sensord
available for all users in the system, which can be convenient, for example, if you plan to
run it as a systemd service by a dedicated user.
Sensord service
Execute by: sensord
command or run as a systemd service
Never run more than one instance of the service at the same time. Especially, do not run simultaneously under a super user and a normal user.
Configuration Directory
All service configuration files must be placed in the sensord
directory located in one of the configuration paths
according to the XDG specification:
- For a given user:
~/.config/sensord
or$XDG_CONFIG_HOME/sensord
- For all users:
/etc/xdg/sensord
or/etc/sensord
Sensors
Configuration
All sensors are configured in the configuration file sensors.toml
which must be placed in the configuration directory.
See the example configuration file.
SEN0395
Mandatory fields
type
: Specifies the type of the sensor. Must be set to"sen0395"
for the SEN0395 sensor.name
: A unique name for the sensor instance. Used for identification.port
: The serial port to which the sensor is connected (e.g.,"/dev/ttyAMA0"
,"/dev/ttyUSB0"
).
Optional fields
enabled
(default:true
): If set totrue
, the service will start reading and processing sensor data (MQTT, presence logging, etc.).autostart
(default:true
): Specifies whether the sensor should automatically start scanning upon service startup.print_presence
(default:true
): Determines whether presence changes should be printed to stdout and logged.
Section [[sensor.mqtt]] (optional)
broker
: The configured name of the MQTT broker to which the sensor should publish presence data.topic
: The MQTT topic under which the presence data should be published.
Section [[sensor.ws]] (optional)
endpoint
: The configured name of the WS endpoint to which the sensor should publish presence data.
MQTT
Broker Configuration
Presence change events of a sensor can be sent as an MQTT message to an MQTT broker. For this, a broker must first be
defined in the mqtt.toml
configuration file. See the example configuration file.
Payload
The schema of the MQTT message payload is defined in the presence-message-schema.json file.
Example
{
"sensorId": "sen0395/desk",
"event": "presence_change",
"eventAt": "2024-05-30T06:25:13.929544+00:00",
"eventData": {
"presence": false
}
}
Sensor Configuration
A sensor must explicitly define an MQTT broker for the notification to be sent. Multiple brokers can be defined to send notifications to different MQTT brokers:
[[sensor]]
# Sensor configuration is here
[[sensor.mqtt]]
broker = "local-rpi" # Broker name defined as `broker.name` in the `mqtt.toml` file
topic = "living_room/desk/presence" # Topic where the notification events are sent
[[sensor.mqtt]]
broker = "cloud-broker" # Another broker name defined in the `mqtt.toml` file
topic = "sensors/living_room/desk/presence" # Topic on the second broker
WebSocket
Endpoint Configuration
Presence change events of a sensor can be sent as a WebSocket message to a WebSocket server.
For this, an endpoint must first be defined in the ws.toml
configuration file. See the example configuration file.
Payload
The schema of the WebSocket message payload is defined in the presence-message-schema.json file.
Example
{
"sensorId": "sen0395/desk",
"event": "presence_change",
"eventAt": "2024-05-30T06:25:13.929544+00:00",
"eventData": {
"presence": false
}
}
Sensor Configuration
A sensor must explicitly define a WebSocket endpoint for the notification to be sent. Multiple endpoints can be defined to send notifications to different WebSocket servers:
[[sensor]]
# Sensor configuration is here
[[sensor.ws]]
endpoint = "local-rpi" # Endpoint name defined as `endpoint.name` in the `ws.toml` file
[[sensor.ws]]
endpoint = "cloud-ws" # Another endpoint name defined in the `ws.toml` file
Systemd
To run this service as a systemd service, follow the steps below.
You can create a dedicated user for the service and add the user to the required groups (optional):
sudo useradd -r -s /usr/sbin/nologin sensord
sudo usermod -a -G dialout sensord
Note: dialout
group is required for reading serial port on Raspberry Pi OS
Create the service file /etc/systemd/system/sensord.service
:
[Unit]
Description=Sensor Daemon Service
After=network.target
[Service]
ExecStart=/usr/local/bin/sensord --log-file-level off
Restart=always
User=sensord
Group=sensord
[Install]
WantedBy=multi-user.target
Note: You can remove the --log-file-level off
option if you want to log to /var/log/sensord
.
However, you need to set the corresponding permissions for the user.
Active and start the service:
sudo systemctl daemon-reload
sudo systemctl enable sensord.service
sudo systemctl start sensord.service
To manually debug, you can run the service as sensord
user:
sudo -u sensord /usr/local/bin/sensord
To read the service logs in the journal:
journalctl -u sensord
Sensor Control CLI
Execute sensorctl --help
to see the available commands. This CLI utility communicates with the sensord
service.
The service must be running when a command is executed.
Note: If the service runs under a different user than the one executing sensorctl
, then the current user must be added
to the same group as the primary group of the service user. For example, if the service runs as the sensord
user
with the sensord
group, then add the current user to the same group:
sudo usermod -a -G sensord $USER
After adding the user to the group, the user needs to log out and log back in for the group changes to take effect.
Subcommands
SEN0395
The sen0395 subcommand group provides commands for controlling the DFRobot mmWave presence sensor SEN0395. All subcommands accept the following option:
--name NAME
: The name of the specific sensor to execute the command on. If not provided, the command is executed for all registered sensors.
start
Start scanning with the SEN0395 sensor(s).
stop
Stop scanning with the SEN0395 sensor(s).
reset
Send a reset command to the SEN0395 sensor(s).
latency DETECTION_DELAY DISAPPEARANCE_DELAY
Configure the detection and disappearance latencies for the SEN0395 sensor(s).
detrange PARA_S PARA_E [PARB_S] [PARB_E] [PARC_S] [PARC_E] [PARD_S] [PARD_E]
Configure the detection range segments for the SEN0395 sensor(s).
status
Print the status of the SEN0395 sensor(s).
enable
Start reading and processing data from the SEN0395 sensor(s).
disable
Stop reading and processing data from the SEN0395 sensor(s).
Project details
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
File details
Details for the file sensord-0.2.0.tar.gz
.
File metadata
- Download URL: sensord-0.2.0.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57444436e0838f5209049c90fd49a5fcc1978a98bf0bef2e7c2161bd661395a3 |
|
MD5 | 4dd6a137482f434f6e919742a357c10f |
|
BLAKE2b-256 | 79576673a9c7033a6f53c49b22daacfa7ddde37f12af88e0b467811ebfeadf05 |
File details
Details for the file sensord-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: sensord-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a970eab9b64eb508431121633c8f15f35c3fe0df1c5d30818cb3cdea21357b |
|
MD5 | 2cc5ae653928b2a70a01bf35d4d71dab |
|
BLAKE2b-256 | be0d85be837420e47a7091628de49d189af2ac1e289e9740a490f3b5d44555b3 |