The files here create a service on the Raspberry Pi that works with the SenseHAT from the astro-pi project and streams its data over MQTT.
This service works on all the Raspberry Pi flavors, as long as they support the SenseHAT.
The files are here structured in this way:
rpi_sensehat_mqtt.py
python script to read the sensors and publish over MQTTrpi_sensehat_mqtt.logrotate
configuration for logrotate to rotate the log file of this scriptrpi_sensehat_mqtt.env
file to define the environmental variables used while running the background servicerpi_sensehat_mqtt.service
file to run the background servicesetconfiguration.sh
script to configure the system and properly propagate the files in the right folders
The main python script rpi_sensehat_mqtt.py
does the following operations when it runs:
- Reads sensor data
- Creates the MQTT message
- Publish it on the broker
The script logs its operations in the file /var/log/rpi_broadcaster/rpi_sensehat_mqtt.log
.
The script requires a configuration through environmental variables defined in the rpi_sensehat_mqtt.env
file.
The available configuration parameters are:
RPI_SENSEHAT_MQTT_LOGLEVEL="<desired loglevel>"
the desired log level to be used in the log, as defined by the python libraryRPI_SENSEHAT_MQTT_CYCLE=<desired timecycle>
the desired time cycleRPI_SENSEHAT_MQTT_LOCATION="<desired location>"
to set the location in the messageRPI_SENSEHAT_MQTT_BROKER="protocol://address:port"
endpoint of the brokerRPI_SENSEHAT_MQTT_TOPIC_PREFIX="<desired prefix>"
to set the prefix for all the topics (defaultsensehat
):readings
is used for the readings andcommands
to process input commandsRPI_SENSEHAT_MQTT_MEASUREMENT="<desired measurement>"
measurement nameRPI_SENSEHAT_MQTT_WELCOME="<desired welcome message>"
welcome message at startup
In order to deploy the configuration, you need to do the following steps
- Run the file
zip.bat
- Transfer the zip file
rpideploy_*.zip
to the desired target machine - On the target machine, extract the zip file content
- run the following command
<sudo> bash ./setconfiguration.sh
After this has been successfully executed the new service is already running, and it can be managed using
<sudo> systemctl <command> rpi_sensehat_mqtt.service