Connection parameters¶
HTTP URL:
https://[YOUR_DOMAIN].decentlab.com/api/datasources/proxy/uid/main/query?db=main&epoch=ms&q=[YOUR_QUERY]
The URL values, /datasources/proxy/uid/main
(datasource main), db=main
(database main) and epoch=ms
(millisecond-resolution timestamps) reflect the most common cases. Nevertheless, you may modify them according to the InfluxDB specification for your special needs.
Note
The datasource name and the database name names must match.
Additional HTTP Header:
Authorization: Bearer [YOUR_API_KEY]
This additional HTTP header represents your credential to access the database. Please contact us if you haven’t received an API key already.
The following example shows how to access the HTTP API using curl with our demo instance. The query fetches the first senseair-lp8-co2 values from device ID 3001.
You can also use Swagger or JSFiddle to test the following example or your instance.
$ curl -G \
-H 'Authorization: Bearer eyJrIjoiclhMRFFvUXFzQXpKVkZydm52b0VMRVg3M3U2b3VqQUciLCJuIjoiZGF0YS1xdWVyeS1hcGktZGVtby0yIiwiaWQiOjF9' \
--data-urlencode \
'q=SELECT value FROM "measurements" WHERE node =~ /^3001$/ AND sensor =~ /^senseair-lp8-co2$/ GROUP BY node, sensor LIMIT 2' \
--data-urlencode 'pretty=true' \
'https://demo.decentlab.com/api/datasources/proxy/uid/main/query?db=main&epoch=ms'
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "measurements",
"tags": {
"node": "3001",
"sensor": "senseair-lp8-co2"
},
"columns": [
"time",
"value"
],
"values": [
[
1572020453441,
808
],
[
1572021053535,
781
]
]
}
]
}
]
}
Note
--data-urlencode 'pretty=true'
enables a pretty-printed output, which is useful only for debugging purposes.
Note
InfluxDB supports only JSON-formatted output which may require format conversions for your specific environment.
Query language¶
InfluxDB provides a time series-oriented special query language, InfluxQL. Although InfluxQL is similar to the generic SQL, there are significant differences. You may need to consult the documentation.
Besides simple data retrievals, InfluxQL supports useful mathematical and statistical functions executed on the server. Using such server-side processing can significantly reduce communication overheads, increasing overall system performance.
Reference implementations¶
For starting your development, we provide the following implementations:
Please feel free to integrate and adapt these implementations into your data processing tools.
Query examples¶
List all devices
SHOW TAG VALUES WITH KEY = node
name: measurements
key value
--- -----
node 19672
node 19673
List all devices with any sensor containing temperature
SHOW TAG VALUES WITH KEY = node WHERE sensor =~ /temperature/
name: measurements
key value
--- -----
node 19672
node 19673
List all sensors
SHOW TAG VALUES WITH KEY = sensor
name: measurements
key value
--- -----
sensor altitude
sensor bandwidth
sensor battery
sensor frame-counter
sensor frequency
sensor latitude
sensor longitude
sensor nb-gateways
sensor optris-cslt-temperature-head
sensor optris-cslt-temperature-target
sensor port
sensor rssi
sensor sensirion-sht35-humidity
sensor sensirion-sht35-temperature
sensor snr
sensor spreading-factor
List all sensors from device 19672
SHOW TAG VALUES WITH KEY = sensor WHERE node =~ /^19672$/
name: measurements
key value
--- -----
sensor altitude
sensor bandwidth
sensor battery
sensor frame-counter
sensor frequency
sensor latitude
sensor longitude
sensor nb-gateways
sensor optris-cslt-temperature-head
sensor optris-cslt-temperature-target
sensor port
sensor rssi
sensor sensirion-sht35-humidity
sensor sensirion-sht35-temperature
sensor snr
sensor spreading-factor
List all non-network sensors from device 19672
SHOW TAG VALUES WITH KEY = sensor WHERE node =~ /^19672$/ AND channel !~ /^link-/
name: measurements
key value
--- -----
sensor battery
sensor optris-cslt-temperature-head
sensor optris-cslt-temperature-target
sensor sensirion-sht35-humidity
sensor sensirion-sht35-temperature
List unit of sensirion-sht35-temperature
of device 19672
SHOW TAG VALUES WITH KEY = unit WHERE node =~ /^19672$/ AND sensor =~ /^sensirion-sht35-temperature$/
name: measurements
key value
--- -----
unit °C
A timeseries in DDA can be uniquely identified by a combination of device, sensor and optional channel. For convenience, each datapoint has uqk
tag formed by joining those values. Consequently, to list all non-network timeseries:
SHOW TAG VALUES WITH KEY = uqk WHERE channel !~ /^link-/
name: measurements
key value
--- -----
uqk 19672.battery
uqk 19672.optris-cslt-temperature-head
uqk 19672.optris-cslt-temperature-target
uqk 19672.sensirion-sht35-humidity
uqk 19672.sensirion-sht35-temperature
uqk 19673.battery
uqk 19673.optris-cslt-temperature-head
uqk 19673.optris-cslt-temperature-target
uqk 19673.sensirion-sht35-humidity
uqk 19673.sensirion-sht35-temperature
The last value of sensirion-sht35-temperature
from 19672
SELECT LAST(value) FROM "measurements" WHERE node =~ /^19672$/ AND sensor =~ /^sensirion-sht35-temperature$/
name: measurements
time last
---- ----
1609829710193000000 -3.529793240253298
The values of sensirion-sht35-temperature
from 19672
in the last one hour
SELECT value FROM "measurements" WHERE node =~ /^19672$/ AND sensor =~ /^sensirion-sht35-temperature$/ AND time > now() - 1h
name: measurements
time value
---- -----
1609827302411000000 -4.093232623788815
1609827903338000000 -3.9223315785458155
1609828505467000000 -4.077210650797284
1609829105703000000 -3.7407492179751287
1609829710193000000 -3.529793240253298
The mean values of 20 minute interval groups formed from the values of sensirion-sht35-temperature
from 19672
in the last one hour
SELECT MEAN(value) FROM "measurements" WHERE node =~ /^19672$/ AND sensor =~ /^sensirion-sht35-temperature$/ AND time > now() - 1h GROUP BY time(20m)
name: measurements
time mean
---- ----
1609826000000000000
1609827200000000000 -4.007782101167315
1609828400000000000 -3.908979934386206
1609829600000000000 -3.564507515068282