This page is also available in the other languages: English Deutsch

InfluxDB


The “influxdb” package can be used to send data to an InfluxDB v2 server. The package is available since hkknx v2.8.0

In the following example, temperature values from group addresses in the range 1/0/0 to 1/0/255 are received and sent to the InfluxDB server.

Authentication towards the server takes place via a Token.

 1var influxdb, hkknx = import("influxdb"), import("hkknx")
 2
 3// Create an influxdb client
 4var client = influxdb.NewClient("http://localhost:8086", "secret-token")
 5var bucket = client.Bucket("my org", "knx")
 6
 7// Create a channel to receive telegrams for group addresses
 8// in the range of "1/0/0-255".
 9var ch = hkknx.GroupWriteTelegramNotify("1/0/*")
10for {
11    // Wait for a telegram to arrive
12    var telegram = <-ch
13    // Decode the telegram bytes as 9.001
14    var temp = hkknx.ParseDPT9001(telegram.Bytes)
15    
16    // Create a new influxdb datapoint for the measurement "temperature"
17    // and set the group address and temperature value.
18    var point = influxdb.NewPointWithMeasurement("temperature")
19    point.AddTag("address", telegram.Addr)
20    point.AddField("value", temp)
21    
22    // Send the data to the server.
23    var err = bucket.Write(point)
24    if err != nil {
25        println(err)
26    }
27}

The data is stored in the bucket knx and as a measured value temperature. The temperature value is assigned to the value field. The group address is stored as an address tag.

In the Line protocol this would result in the following text:

temperature,address=<group address> value=<temp value> <timestamp>

e.g. temperature,address=1/0/125 value=19.5 1704892410000000000


On This Page
© Matthias Hochgatterer – MastodonGithubRésumé