Feinstaub Bridge¶
Data received as JSON via an HTTP POST request is send over to an MQTT broker. A sample POST request originating from a luftdaten.info sensor is of the following form.
POST / HTTP/1.1
Host: 192.168.223.215
Content-Type: application/json
Authorization: Basic
X-PIN: 0
X-Sensor: esp8266-3394227
Content-Length: 412
Connection: close
{"esp8266id": "3394227", "software_version": "NRZ-2017-090",
"sensordatavalues":[{"value_type":"SDS_P1","value":"4.30"},
{"value_type":"SDS_P2","value":"3.53"},
{"value_type":"temperature","value":"20.80"},
{"value_type":"humidity","value":"52.30"},
{"value_type":"samples","value":"670215"},
{"value_type":"min_micro","value":"205"},
{"value_type":"max_micro","value":"505594"},
{"value_type":"signal","value":"-82"}]}
Installation¶
Ansible can be used to install this tool as a service.
$ ansible-playbook -K playbook-deploy.yml
Look into the playbook-deploy.yaml-file to get more details about the deployment process.
The tool will be installed as supervisord service. The configurtion script is services/supervisor.conf.
Option -K
asks for the sudo-Passwort - only needed if daemontools must be
installed.
To test the service you can now post a sample request found in the file sample_post.txt in the repo.
curl -d @sample_post.txt -H 'Content-Type: application/json' localhost:8080/feinstaub/json2mqtt
API-Doc¶
The bottle-Server is configured and run in the following module.
json2mqtt¶
This module runs a bottle webserver and listens for a post request that contains a JSON payload which will be transmitted over to an MQTT broker.
-
json2mqtt.run.
publish
(json: dict, topic_prefix: str)[source]¶ Take a JSON document and publish it to a given MQTT topic prefix.