IoT - InfluxDB - first steps

Data aggregation

Here the first step to automated data aggregation of sensor data ...

 

Aggregate all sensor for last hour

Create initial measurement

SELECT min(value), mean(value), max(value), sum(value)
INTO "sensors_1h"
FROM "sensors"
GROUP BY time(1h), nodeId, sensorId

Create CQ

CREATE CONTINUOUS QUERY "cq_sensors_1h" ON "iot" BEGIN
SELECT min(value), mean(value), max(value), sum(value)
INTO "sensors_1h"
FROM "sensors"
GROUP BY time(1h), nodeId, sensorId
END

Aggregate all sensor for last day

Create initial measurement

SELECT min(value), mean(value), max(value), sum(value)
INTO "sensors_1d"
FROM "sensors"
GROUP BY time(1d), nodeId, sensorId

Create CQ

CREATE CONTINUOUS QUERY "cq_sensors_1d" ON "iot" BEGIN
SELECT min(value), mean(value), max(value), sum(value)
INTO "sensors_1d"
FROM "sensors"
GROUP BY time(1d), nodeId, sensorId
END