InfluxDB
Integrate Thingsee IoT data with InfluxDB time series database
InfluxDB is a purpose-built time series platform for IoT analytics and monitoring.
Overview
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#73F9C1','primaryTextColor':'#143633','primaryBorderColor':'#143633','lineColor':'#143633','secondaryColor':'#C7FDE6','tertiaryColor':'#F6FAFA','clusterBkg':'#F6FAFA','clusterBorder':'#143633'}}}%%
flowchart TB
subgraph InfluxDBPlatform["InfluxDB"]
DASH[Dashboards]
ALERT[Alerting]
API[Query API]
I[InfluxDB]
end
T[Thingsee Cloud]
T -->|Line Protocol| I
I --> DASH & ALERT & APISetup
1. Install InfluxDB
Follow InfluxDB installation guide or use InfluxDB Cloud.
2. Configure Access
Create access credentials:
- Organization name
- Bucket name
- Write token
3. Request Integration
Contact Haltian with:
- InfluxDB server URL
- Write token
- Organization name
- Bucket name
Data Schema
Thingsee Cloud converts messages to InfluxDB line protocol:
| InfluxDB Concept | Thingsee Mapping |
|---|---|
| Bucket | Your bucket name |
| Measurement | tsmId value |
| Field | Thingsee message property |
| Tag | tsmTuid (device serial) |
| Timestamp | tsmTs (Unix seconds) |
Example
Thingsee message:
{
"tsmId": 12100,
"tsmEv": 10,
"tsmTs": 1520416221,
"tsmTuid": "TSPR04E2O90201558",
"temp": 21.3,
"humd": 45.2
}
InfluxDB line protocol:
12100,tsmTuid=TSPR04E2O90201558 temp=21.3,humd=45.2 1520416221000000000
Querying Data
Flux Query Language
Get latest temperature for all devices:
from(bucket: "thingsee")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "12100")
|> filter(fn: (r) => r._field == "temp")
|> last()
Average temperature by device:
from(bucket: "thingsee")
|> range(start: -24h)
|> filter(fn: (r) => r._measurement == "12100")
|> filter(fn: (r) => r._field == "temp")
|> mean()
|> group(columns: ["tsmTuid"])
Detect temperature anomalies:
from(bucket: "thingsee")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "12100")
|> filter(fn: (r) => r._field == "temp")
|> filter(fn: (r) => r._value > 30 or r._value < 10)
InfluxQL (v1 compatibility)
SELECT mean("temp") FROM "12100"
WHERE time > now() - 24h
GROUP BY time(1h), "tsmTuid"
Dashboards
InfluxDB includes built-in dashboard capabilities:
Create Dashboard
- Open InfluxDB UI
- Go to Dashboards → Create Dashboard
- Add cells with Flux queries
- Configure visualizations
Example Visualizations
| Cell Type | Query | Description |
|---|---|---|
| Line graph | Temperature over time | filter(fn: (r) => r._field == "temp") |
| Gauge | Latest battery level | filter(fn: (r) => r._field == "batl") |> last() |
| Table | Device status | Group by tsmTuid with latest values |
| Heatmap | Occupancy patterns | Count of presence events |
Alerting
Configure alerts with InfluxDB Checks:
Low Battery Alert
import "influxdata/influxdb/monitor"
check = {
_check_id: "low-battery",
_check_name: "Low Battery Alert",
_type: "threshold",
tags: {}
}
from(bucket: "thingsee")
|> range(start: -5m)
|> filter(fn: (r) => r._measurement == "1110")
|> filter(fn: (r) => r._field == "batl")
|> last()
|> monitor.check(
crit: (r) => r._value < 20,
warn: (r) => r._value < 40,
data: check
)
No Data Alert
from(bucket: "thingsee")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "12100")
|> count()
|> map(fn: (r) => ({ r with _level: if r._value == 0 then "crit" else "ok" }))
Retention Policies
Configure data retention based on needs:
// Create bucket with 30-day retention
influx bucket create \
--name thingsee \
--org your-org \
--retention 30d
Consider tiered storage:
- Hot: Recent data (7 days), fast queries
- Warm: Historical data (1 year), slower queries
- Cold: Archive (3+ years), object storage
Integration with Grafana
InfluxDB integrates seamlessly with Grafana:
- Add InfluxDB as data source
- Use Flux or InfluxQL queries
- Build advanced dashboards
- Set up unified alerting