About openSenseMap

openSenseMap is an open web-platform that transfers sensor data and is available for free to anyone. This tutorial explains how to transfer current values from Querx to the platform. It also shows how to adapt Querx to new cloud services, independent from the selected platform.
openSenseMap

 

openSenseMap
Registering with openSenseMap  
The first step is registering the device with openSenseMap. This requires a valid email address.
openSenseMap
While the first page of the registry site is in German, the following are all in English. Activating the input field “I agree” confirms that the device’s location can be made public. The entered email address is only used to inform users of updates and is not passed on to third parties.
openSenseMap

Now the device needs a name, e.g. “Querx”, and we need to select whether it is located indoors, outdoors, or is mobile.

openSenseMap
The next step is to enter the device’s location. This is done with the help of an intuitive roadmap.
openSenseMap
Finally, the hardware setup needs to be specified. Since Querx is not supported natively, we need to select manual configuration. The sensor can be set up by clicking “Add sensor”.
openSenseMap
The last page displays a summary and confirms that the data sent by the sensor can be used freely by anyone.
A confirmation email will arrive within the next few minutes, which also contains the source code for Arduino based devices. Two identifiers from the source code are required to configure Querx. One for the device (SENSEBOX_ID) and one for the sensor (SENSOR1_ID).
//senseBox ID
#define SENSEBOX_ID “000000000000000000000000000"
//Sensor IDs
//Temperature
#define SENSOR1_ID “000000000000000000000000000"

 

Configuring Querx  
Since the release of firmware version 4.2, it is now possible to configure the format for data export via custom template files. We are therefore no longer dependent on the firmware’s native support of certain cloud services, but can configure Querx to the requirements of any cloud available. opsenSenseMap expects a JSON string in the following format:
{“value”: measured value}
This string is sent to the following URL via POST:
ingress.opensensemap.org/boxes/ID1/ID2
“ID1” and “ID2” need to be replaced by the two identifiers that we received during registration. Now Querx needs a simple text file, a so-called template, with the following contents:
add=/tpl/j/osem.tpl

Content-Type: application/json
{# #}
{“value”:{{sensortab_value.0}}}
This file with the name osem.tpl is created with a text editor (Notepad, vi, etc.) on our computer. The first line determines the folder in which the file is saved in Querx’s memory. The next line must remain blank. The following lines determine the contents of the data that is sent to the cloud and let us add further headers to the HTTP-POST. Here, we are only using one header (Content-Type) to determine the file format JSON.
In HTTP, headers are separated from the content by a blank line. The file will later be converted by the template interpreter within Querx, which deletes blank lines. A comment line, however, allows us to create a blank line. The comment {# #} is deleted by the interpreter, but the line itself remains. The final line contains the JSON string that is required by openSenseMap. The template interpreter replaces the part {{sensortab_value.0}} with the current value measured by the first sensor.
Querx
After having saved the file on our computer, we can now install it on Querx via the web interface, by navigating to the page Configuration / Maintenance / Firmware / Install Content.
Querx
Querx can now be set to send the sensor’s value to openSenseMap in regular intervals. This is configured on the page Interfaces / HTTP Push. The variable fields are not really required, since the identifiers can be entered directly in the URL. However, the length of the URL with the identifiers exceeds the limit of the input field of 63 characters. We can solve this issue by entering the placeholders $1 and $2 in the URL and entering the identifiers in the variable fields.
Querx
A first transmission can be triggered manually by clicking the button Test. The result can be checked on the page Interfaces / Syslog.

 

Result
If everything works as intended, we can now see the data in openSenseMap at
https://opensensenemap.org/explore/ID1
The placeholder ID1 in the URL needs to be replaced by the device’s identifier.
openSenseMap
This successfully demonstrates how to integrate Querx into new cloud services that are not supported by the device natively.
There are, however, several problems. We shortened the long URL by using variables. A problem that has not yet been solved concerns the transfer of data by multiple sensors in one device. openSenseMap requires an individual URL for each sensor, while Querx can only configure one single URL. It may be possible to circumvent this issue by connecting openSenseMap with MQTT or TheThingsNetwork. On the other hand, we are planning to extend the Querx firmware to allow for multiple URLs in HTTP Push in the medium near future.