API that receives updates via HTTP from Shelly IoT devices and provides endpoint for listing all provided sensor data.
The application persists sensor data to a json file. By default, the data is persisted to sensors.json and that same file is used by some tests. The default configuration file can be overriden by giving path to configuration file as a command line parameter when running the application.
The application also has capability to map sensor id's to human-readable names. By default, empty mapping array is used from file id_mappings.json i.e. no mapping is done, but it can be overriden by giving path to mapping file.
- Python 3.9
https://python.land/virtual-environments/virtualenv
Create virtual environment: python -m venv venv
Activate virtual environment: source venv/bin/activate
Deativate virtual environment: deactivate
pip install -r requirements.txt
python -m unittest discover
Uses sensors.json as sensors configuration file and id_mappings.json as id-name mapping configuration file.
python shelly_http_api.py
Uses the first parameter as sensors configuration file and second as id-name mapping configuration.
python shelly_http_api.py configuration.json id_mappings.json
- requirements.txt contains dependencies
- shelly_http_api.py is the main file and contains HTTP endpoints
- sensor is a module for shelly sensors
- test contains all tests
URL: /sensor/upsert?<query parameters>
Query parameters
- state: optional sensor state e.g. open/closed
- temp: temperature reading
- lux: optional lux reading
- flood: optional flood indicator as 0/1
Response:
{
"name": "kitchen",
"lux": 10,
"state": "open",
"temperature": 19.7
}
URL: /sensor
Response:
[
{
"name": "kitchen",
"lux": 10,
"state": "open",
"temperature": 19.7
}
]