Skip to content
Warukira Theuri edited this page May 25, 2023 · 13 revisions

Next page: Pinouts NodeMCU v2, v3

API

The API accepts the sensor data and serves as the basis for the graphical display on v2/map.aq.sensors.africa. In addition, the data of the "public" sensors are exported once a day as CSV and made available at africaopendata.org/organization/sensors.africa.

API Madavi.de

The API also accepts the sensor data and stores it in a CSV file (one file per sensor per day). Furthermore, the data is stored in a RoundRobin database and graphically processed via RRDTools. The file archive can be found at https://www.madavi.de/sensor/csvfiles.php, and the graphical representation at https://www.madavi.de/sensor/graph.php.

OpenSenseMap

Opensensemap is a free platform for open sensor data. The website and API are open source. In addition to numerous projects that provide data to this platform, the fine dust sensor can also be used Transfer data to it. Users can display their values ​​there and have them processed as a graph. A "box" generated there has its own ID, which must be entered on the configuration page of the particulate matter sensor. Then the API point in the configuration is to be activated.

Send to your own API

The data can be stored on a local web server such as a Raspberry Pi in the local network. The menu item "Send to own API" on the configuration page of the particulate matter sensor must be activated accordingly and the destination address with the server, path, port and optional user and password must be entered. A simple PHP script is available for saving and later evaluating the data:

https://github.com/opendata-stuttgart/madavi-api/blob/master/data_simple.php

This saves the supplied data in a daily .csv file. The data is delivered in .json format and not in $ _post format! This script can also be used to store in a separate database (self-program).

Issue # 69 gives more hints and code examples for PHP:
https://github.com/opendata-stuttgart/meta/issues/69#issuecomment-314222830

Another example: a Python script as Systemd Service receives the data and sends it to Domoticz:
https://github.com/joba-1/airrohr2domoticz

InfluxDB

InfluxDB is a special database for time-based measurements or events. If there is a separate InfluxDB server, the sensor data can also be sent directly to it. The presettings must be adjusted accordingly for your own application. (Server, port, path, user) In this case, the server only the address without additions such as HTTP or HTTPS must be entered, the latter is anyway not supported.
More information about InfluxDB
https://www.influxdata.com/   

more detailed description

For the NodeMCU, the chipID is used as the ID. For other systems, X-Sensor is composed of a name for the system (e.g., raspi for Raspberry) and a unique ID (Raspberry: Serial in / proc / cpuinfo).

Example POST for SDS011:
Header
Content-Type: application / json
X-Pin: 1
X-sensor: esp8266-12345678

Data
{"software_version": "your_version", "sensordatavalues": [{"value_type": "P1", "value": "66.04"}, {"value_type": "P2", "value": "53.32"}] }

Example POST for DHT22:
Header
Content-Type: application / json
X-Pin: 7
X-sensor: esp8266-12345678

Data
{"software_version": "your_version", "sensordatavalues": [{"value_type": "temperature", "value": "22.30"}, {"value_type": "humidity", "value": "34.70"}] }  

Other sensors:
BMP180: value_types: temperature, pressure; X-Pin: 3
BME280: value_types: temperature, humidity, pressure; X-pin: 11
PMS1003 - PMS 7003: value_types: P1 (PM10), P2 (PM2.5); X-Pin: 1

The address of the API endpoint to deliver the data is https://api.sensors.africa/v1/push-sensor-data/   

Accessing the API data:

We have some 'API' endpoints to access the sensor data. The data is saved once a minute due to performance reasons:
https://api.sensors.africa/v1/now/ - all measurements of the last 5 minutes for all publicly accessible sensors
https://api.sensors.africa/v1/data/ - all measurements for all publicly accessible sensors in our database
https://api.sensors.africa/v1/sensor/{apiID}/ - all measurements of the last 5 minutes for one sensor
https://api.sensors.africa/v1/filter/{query} - 5 minutes filtered by query

  • type = {sensor type}: comma separated list of sensor types, i.e. 'SDS011, BME280'
  • area = {lat, lon, distance}: all sensors within a max. radius
  • box = {lat1, lon1, lat2, lon2}: all sensors in a 'box' with the given coordinates
  • country = {country code}: i.e. 'KE, TZ, NG, ZA, ...'

https://api.sensors.africa/v1/data.json - average of all measurements per sensor of the last 5 minutes for all sensors