communication with influxdb is working, schema of data in influxdb is unusable so far, too many spare columns

This commit is contained in:
2026-02-04 17:19:12 +01:00
parent 97679561d8
commit a1ea1b230e
22 changed files with 22 additions and 57 deletions

View File

@@ -0,0 +1,89 @@
package draginoLdds75
import (
"fmt"
// "log"
"strings"
"strconv"
"encoding/json"
"udi/database"
)
/*
"decoded_payload": {
"Bat": 3.299,
"Distance": "352 mm",
"Interrupt_flag": 0,
"Sensor_flag": 1,
"TempC_DS18B20": "0.00"
},
*/
type message struct {
Bat float32 `json:"Bat"`
Distance string `json:"Distance"`
Interrupt_flag int `json:"Interrupt_flag"`
Sensor_flag int `json:"Sensor_flag"`
TempC_DS18B20 string `json:"TempC_DS18B20"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
distanceParts := strings.Split(message.Distance, " ")
if len(distanceParts) != 2 && distanceParts[1] != "mm" {
return fmt.Errorf("Invalid format for distance value: %s", message.Distance)
}
distance, err2 := strconv.Atoi(distanceParts[0])
if err2 != nil {
return fmt.Errorf("Distance value is no number: %s -> %s", message.Distance, err2)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
(*variables)["Distance"] = database.VariableType {
Label: "Distance",
Variable: "Level",
Unit: "mm",
Value: distance,
}
if distance == 20 {
(*attributes)["Status"] = "invalid value"
} else if distance == 0 {
(*attributes)["Status"] = "no sensor detected"
} else {
(*attributes)["Status"] = "Ok"
}
groundLevelI, exists := device.Attributes["GroundLevel"]
groundLevelS, ok := groundLevelI.(string)
groundLevel, err3 := strconv.Atoi(groundLevelS)
if exists && err3 == nil && ok {
//log.Println("add corrected distance")
correctedDistance := groundLevel - distance
(*variables)["CorrectedDistance"] = database.VariableType {
Label: "CorrectedDistance",
Variable: "Level",
Unit: "mm",
Value: correctedDistance,
}
} /* else {
log.Printf("no ground level: %s %s %s", exists, err3, ok)
log.Printf("Device: %s", device)
log.Printf("Attributes: %s", device.Attributes)
} */
return nil
}

View File

@@ -0,0 +1,83 @@
{
"end_device_ids": {
"device_id": "eui-a84041a14185f67f",
"application_ids": {
"application_id": "de-hottis-level-monitoring"
},
"dev_eui": "A84041A14185F67F",
"join_eui": "A840410000000101",
"dev_addr": "260B3987"
},
"correlation_ids": [
"gs:uplink:01HHP8EVC1N78FGTNBTNZYGCVY"
],
"received_at": "2023-12-15T08:11:04.142793605Z",
"uplink_message": {
"session_key_id": "AYZ/cI2YeDLCZr4urRDzCw==",
"f_port": 2,
"f_cnt": 27758,
"frm_payload": "DOMBYAAAAAE=",
"decoded_payload": {
"Bat": 3.299,
"Distance": "352 mm",
"Interrupt_flag": 0,
"Sensor_flag": 1,
"TempC_DS18B20": "0.00"
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-00005813d35e3021",
"eui": "00005813D35E3021"
},
"timestamp": 3654294763,
"rssi": -85,
"channel_rssi": -85,
"snr": 8.8,
"location": {
"latitude": 52.17065267448476,
"longitude": 7.629437184774199,
"source": "SOURCE_REGISTRY"
},
"uplink_token": "CiIKIAoUZXVpLTAwMDA1ODEzZDM1ZTMwMjESCAAAWBPTXjAhEOu5wM4NGgwIl5TwqwYQ5Z/7vgMg+OvDp63eBA==",
"channel_index": 2,
"received_at": "2023-12-15T08:11:03.937349093Z"
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "867500000",
"timestamp": 3654294763
},
"received_at": "2023-12-15T08:11:03.938112475Z",
"consumed_airtime": "0.056576s",
"locations": {
"user": {
"latitude": 52.1710648323742,
"longitude": 7.62751003482794,
"altitude": 37,
"source": "SOURCE_REGISTRY"
}
},
"version_ids": {
"brand_id": "dragino",
"model_id": "ldds75",
"hardware_version": "_unknown_hw_version_",
"firmware_version": "1.1.4",
"band_id": "EU_863_870"
},
"network_ids": {
"net_id": "000013",
"ns_id": "EC656E0000000181",
"tenant_id": "ttn",
"cluster_id": "eu1",
"cluster_address": "eu1.cloud.thethings.network"
}
}
}

View File

@@ -0,0 +1,90 @@
package draginoLmds200
import (
"fmt"
"strconv"
"encoding/json"
"udi/database"
)
/*
"decoded_payload": {
"Bat": 3.082,
"DALARM_count": 0,
"Distance_alarm": 0,
"Interrupt_alarm": 0,
"dis1": 105,
"dis2": 201
},
*/
type message struct {
Bat float32 `json:"Bat"`
DALARM_count int `json:"DALARM_count"`
Distance_alarm int `json:"Distance_alarm"`
Interrupt_alarm int `json:"Interrupt_alarm"`
Dis1 int `json:"dis1"`
Dis2 int `json:"dis2"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
distance1 := message.Dis1 * 10
(*variables)["Distance1"] = database.VariableType {
Label: "Distance1",
Variable: "Level",
Unit: "mm",
Value: distance1,
}
distance2 := message.Dis2 * 10
(*variables)["Distance2"] = database.VariableType {
Label: "Distance2",
Variable: "Level",
Unit: "mm",
Value: distance2,
}
if distance1 == 2 {
(*attributes)["Status"] = "invalid value"
} else if distance1 == 1 {
(*attributes)["Status"] = "no sensor detected"
} else {
(*attributes)["Status"] = "Ok"
}
groundLevelI, exists := device.Attributes["GroundLevel"]
groundLevelS, ok := groundLevelI.(string)
groundLevel, err3 := strconv.Atoi(groundLevelS)
if exists && err3 == nil && ok {
correctedDistance1 := groundLevel - distance1
(*variables)["CorrectedDistance1"] = database.VariableType {
Label: "CorrectedDistance1",
Variable: "Level",
Unit: "mm",
Value: correctedDistance1,
}
correctedDistance2 := groundLevel - distance2
(*variables)["CorrectedDistance2"] = database.VariableType {
Label: "CorrectedDistance2",
Variable: "Level",
Unit: "mm",
Value: correctedDistance2,
}
}
return nil
}

View File

@@ -0,0 +1,84 @@
{
"end_device_ids": {
"device_id": "eui-a840419641867eb5",
"application_ids": {
"application_id": "de-hottis-level-monitoring"
},
"dev_eui": "A840419641867EB5",
"join_eui": "A840410000000101",
"dev_addr": "260B91F9"
},
"correlation_ids": [
"gs:uplink:01HH1R112BNDQQ52N9FVV0TKPW"
],
"received_at": "2023-12-07T08:59:05.369293395Z",
"uplink_message": {
"session_key_id": "AYa9JUhNJp00t+hKqkQUog==",
"f_port": 2,
"f_cnt": 25665,
"frm_payload": "DAoAaQDJAA==",
"decoded_payload": {
"Bat": 3.082,
"DALARM_count": 0,
"Distance_alarm": 0,
"Interrupt_alarm": 0,
"dis1": 105,
"dis2": 201
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-00005813d35e3021",
"eui": "00005813D35E3021"
},
"timestamp": 1141271036,
"rssi": -100,
"channel_rssi": -100,
"snr": 7.3,
"location": {
"latitude": 52.17065267448476,
"longitude": 7.629437184774199,
"source": "SOURCE_REGISTRY"
},
"uplink_token": "CiIKIAoUZXVpLTAwMDA1ODEzZDM1ZTMwMjESCAAAWBPTXjAhEPzTmaAEGgsI2ZLGqwYQnfLnTSDggLjIm5IF",
"channel_index": 6,
"received_at": "2023-12-07T08:59:05.163182877Z"
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "868300000",
"timestamp": 1141271036
},
"received_at": "2023-12-07T08:59:05.163964824Z",
"consumed_airtime": "0.056576s",
"locations": {
"user": {
"latitude": 52.1707216912195,
"longitude": 7.63066603211241,
"altitude": 39,
"source": "SOURCE_REGISTRY"
}
},
"version_ids": {
"brand_id": "dragino",
"model_id": "lmds200",
"hardware_version": "_unknown_hw_version_",
"firmware_version": "1.0",
"band_id": "EU_863_870"
},
"network_ids": {
"net_id": "000013",
"ns_id": "EC656E0000000181",
"tenant_id": "ttn",
"cluster_id": "eu1",
"cluster_address": "eu1.cloud.thethings.network"
}
}
}

View File

@@ -0,0 +1,63 @@
package draginoLse01
import (
"fmt"
"encoding/json"
"udi/database"
)
/*
{
"Bat":3.211,
"TempC_DS18B20":"0.0",
"conduct_SOIL":32,
"temp_SOIL":"7.56",
"water_SOIL":"25.92"
}
*/
type message struct {
Bat float32 `json:"Bat"`
TempC_DS18B20 string `json:"TempC_DS18B20"`
Conduct_SOIL int `json:"conduct_SOIL"`
Temp_SOIL string `json:"temp_SOIL"`
Water_SOIL string `json:"water_SOIL"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
(*variables)["Conductance"] = database.VariableType {
Label: "Conductance",
Variable: "Conductance",
Unit: "uS/cm",
Value: message.Conduct_SOIL,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_SOIL,
}
(*variables)["Water"] = database.VariableType {
Label: "Water",
Variable: "Water",
Unit: "%",
Value: message.Water_SOIL,
}
return nil
}

View File

@@ -0,0 +1,74 @@
package draginoLsn50
import (
"fmt"
"encoding/json"
"udi/database"
)
/*
"decoded_payload": {
"ALARM_status": "FALSE",
"BatV": 3.659,
"Temp_Black": 3276.7,
"Temp_Red": 22.6,
"Temp_White": 3276.7,
"Work_mode": "DS18B20"
},
*/
type message struct {
ALARM_status string `json:"ALARM_status"`
Bat float32 `json:"BatV"`
Work_mode string `json:"Work_mode"`
Temp_Black float32 `json:"Temp_Black"`
Temp_Red float32 `json:"Temp_Red"`
Temp_White float32 `json:"Temp_White"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
var message message
err := json.Unmarshal(decodedPayload, &message)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: message.Bat,
}
(*variables)["Alarm"] = database.VariableType {
Label: "Alarm",
Variable: "Alarm",
Unit: "",
Value: message.ALARM_status,
}
(*variables)["Temp_Red"] = database.VariableType {
Label: "Temp_Red",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_Red,
}
(*variables)["Temp_Black"] = database.VariableType {
Label: "Temp_Black",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_Black,
}
(*variables)["Temp_White"] = database.VariableType {
Label: "Temp_White",
Variable: "Temperature",
Unit: "°C",
Value: message.Temp_White,
}
(*attributes)["Status"] = "Ok"
return nil
}

View File

@@ -0,0 +1,124 @@
{
"end_device_ids": {
"device_id": "eui-102ceffffe01089c",
"application_ids": {
"application_id": "com-passavant-geiger-poc"
},
"dev_eui": "102CEFFFFE01089C",
"join_eui": "102CEF0000000000",
"dev_addr": "260B0E1A"
},
"correlation_ids": [
"gs:uplink:01HHF7YF14Y7HQBF9D8N8D20ZM"
],
"received_at": "2023-12-12T14:47:26.197129491Z",
"uplink_message": {
"session_key_id": "AYxJcJyrJgr7XiIUdO3EBA==",
"f_port": 1,
"f_cnt": 11738,
"frm_payload": "7HF4ZQsAAAAADAAAAAANAAAAAA4AAAAAFwAYABkA8ADc",
"decoded_payload": {
"Active Power L1": {
"cfgphase": 1,
"unit": "W",
"value": 0
},
"Active Power L123": {
"unit": "W",
"value": 0
},
"Active Power L2": {
"cfgphase": 2,
"unit": "W",
"value": 0
},
"Active Power L3": {
"cfgphase": 3,
"unit": "W",
"value": 0
},
"Powerfactor L1": {
"cfgphase": 1,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"Powerfactor L2": {
"cfgphase": 2,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"Powerfactor L3": {
"cfgphase": 3,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"errorcode": {
"CTRatioChange": false,
"ImpulseRatioChange": false,
"ImpulseWidthChange": false,
"LogbookFull": false,
"PowerFail": false,
"TimeChanged": false,
"VTRatioChange": false,
"value": 0
},
"medium": {
"desc": "Electricity",
"type": 1
},
"timeStamp": 1702392300
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-b827ebfffe8b01dd",
"eui": "B827EBFFFE8B01DD"
},
"time": "2023-12-12T14:47:25.951668977Z",
"timestamp": 3710351237,
"rssi": -89,
"channel_rssi": -89,
"snr": 14,
"location": {
"latitude": 51.404164272478724,
"longitude": 7.060088589208832,
"source": "SOURCE_REGISTRY"
},
"uplink_token": "CiIKIAoUZXVpLWI4MjdlYmZmZmU4YjAxZGQSCLgn6//+iwHdEIXvnekNGgwI/eThqwYQpoGI1wMgiL+rkf5r",
"received_at": "2023-12-12T14:47:25.969479115Z"
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "867100000",
"timestamp": 3710351237,
"time": "2023-12-12T14:47:25.951668977Z"
},
"received_at": "2023-12-12T14:47:25.988957776Z",
"confirmed": true,
"consumed_airtime": "0.092416s",
"version_ids": {
"brand_id": "emu",
"model_id": "emu-prof-ii",
"hardware_version": "1.0",
"firmware_version": "1.0",
"band_id": "EU_863_870"
},
"network_ids": {
"net_id": "000013",
"ns_id": "EC656E0000000181",
"tenant_id": "ttn",
"cluster_id": "eu1",
"cluster_address": "eu1.cloud.thethings.network"
}
}
}

View File

@@ -0,0 +1,93 @@
{
"end_device_ids": {
"device_id": "eui-102ceffffe01089c",
"application_ids": {
"application_id": "com-passavant-geiger-poc"
},
"dev_eui": "102CEFFFFE01089C",
"join_eui": "102CEF0000000000",
"dev_addr": "260B0E1A"
},
"correlation_ids": [
"gs:uplink:01HH53T0RPG7QFT6N267J3Q2PA"
],
"received_at": "2023-12-08T16:22:41.900339885Z",
"uplink_message": {
"session_key_id": "AYxJcJyrJgr7XiIUdO3EBA==",
"f_port": 2,
"f_cnt": 374,
"frm_payload": "BEFzZSQAAAAAAAAAACYAAAAAAAAAACgAAAAAAAAAACoAAAAAAAAAAMk=",
"decoded_payload": {
"Active Energy Export T1 64bit": {
"unit": "Wh",
"value": 0
},
"Active Energy Import T1 64bit": {
"unit": "Wh",
"value": 0
},
"Reactive Energy Export T1 64bit": {
"unit": "varh",
"value": 0
},
"Reactive Energy Import T1 64bit": {
"unit": "varh",
"value": 0
},
"medium": {
"desc": "Electricity",
"type": 1
},
"timeStamp": 1702052100
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-b827ebfffe8b01dd",
"eui": "B827EBFFFE8B01DD"
},
"time": "2023-12-08T16:22:40.969499111Z",
"timestamp": 383972090,
"rssi": -93,
"channel_rssi": -93,
"snr": 12.75,
"location": {
"latitude": 51.404164272478724,
"longitude": 7.060088589208832,
"source": "SOURCE_REGISTRY"
},
"uplink_token": "CiIKIAoUZXVpLWI4MjdlYmZmZmU4YjAxZGQSCLgn6//+iwHdEPrli7cBGgwI0YXNqwYQoteqxwIgkMGUtJb+pwI=",
"received_at": "2023-12-08T16:22:41.668146811Z"
}
],
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 7,
"coding_rate": "4/5"
}
},
"frequency": "867700000",
"timestamp": 383972090,
"time": "2023-12-08T16:22:40.969499111Z"
},
"received_at": "2023-12-08T16:22:41.687510109Z",
"confirmed": true,
"consumed_airtime": "0.102656s",
"version_ids": {
"brand_id": "emu",
"model_id": "emu-prof-ii",
"hardware_version": "1.0",
"firmware_version": "1.0",
"band_id": "EU_863_870"
},
"network_ids": {
"net_id": "000013",
"ns_id": "EC656E0000000181",
"tenant_id": "ttn",
"cluster_id": "eu1",
"cluster_address": "eu1.cloud.thethings.network"
}
}
}

View File

@@ -0,0 +1,257 @@
package emuProfIILoRaCfg1
// provisioning device with
// f_port=1: 01 00 0A 0B 0C 0D 0E 17 18 19 F0 4C
// 01 00 08 0B 0C 0D 0E 17 18 19 F0 BE
// f_port=2: 01 00 0A 24 26 28 2A 7A
// 01 00 08 24 26 28 2A BE
import (
"fmt"
//"log"
"encoding/json"
"udi/database"
)
/*
{
"Active Energy Export T1 64bit": {
"unit": "Wh",
"value": 0
},
"Active Energy Import T1 64bit": {
"unit": "Wh",
"value": 0
},
"Reactive Energy Export T1 64bit": {
"unit": "varh",
"value": 0
},
"Reactive Energy Import T1 64bit": {
"unit": "varh",
"value": 0
},
"medium": {
"desc": "Electricity",
"type": 1
},
"timeStamp": 1702052100
}
*/
type emuMessage2 struct {
ActiveEnergyExport struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"Active Energy Export T1 64bit"`
ReactiveEnergyExport struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"Reactive Energy Export T1 64bit"`
ActiveEnergyImport struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"Active Energy Import T1 64bit"`
ReactiveEnergyImport struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"Reactive Energy Import T1 64bit"`
Medium struct {
Desc string `json:"desc"`
Type int `json:"type"`
} `json:"medium"`
Timestamp int `json:"timestamp"`
}
/*
{
"Active Power L1": {
"cfgphase": 1,
"unit": "W",
"value": 0
},
"Active Power L123": {
"unit": "W",
"value": 0
},
"Active Power L2": {
"cfgphase": 2,
"unit": "W",
"value": 0
},
"Active Power L3": {
"cfgphase": 3,
"unit": "W",
"value": 0
},
"Powerfactor L1": {
"cfgphase": 1,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"Powerfactor L2": {
"cfgphase": 2,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"Powerfactor L3": {
"cfgphase": 3,
"unit": "Cos",
"value": 0,
"value_raw": 0
},
"errorcode": {
"CTRatioChange": false,
"ImpulseRatioChange": false,
"ImpulseWidthChange": false,
"LogbookFull": false,
"PowerFail": false,
"TimeChanged": false,
"VTRatioChange": false,
"value": 0
},
"medium": {
"desc": "Electricity",
"type": 1
},
"timeStamp": 1702392300
}
*/
type emuMessage1 struct {
ActivePowerL1 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value int `json:"value"`
} `json:"Active Power L1"`
ActivePowerL2 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value int `json:"value"`
} `json:"Active Power L2"`
ActivePowerL3 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value int `json:"value"`
} `json:"Active Power L3"`
ActivePowerL123 struct {
Unit string `json:"unit"`
Value int `json:"value"`
} `json:"Active Power L123"`
PowerfactorL1 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value float32 `json:"value"`
ValueRaw float32 `json:"value_raw"`
} `json:"Powerfactor L1"`
PowerfactorL2 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value float32 `json:"value"`
ValueRaw float32 `json:"value_raw"`
} `json:"Powerfactor L2"`
PowerfactorL3 struct {
CfgPhase int `json:"cfgphase"`
Unit string `json:"unit"`
Value float32 `json:"value"`
ValueRaw float32 `json:"value_raw"`
} `json:"Powerfactor L3"`
ErrorCode struct {
CTRatioChange bool `json:"CTRatioChange"`
ImpulseRatioChange bool `json:"ImpulseRatioChange"`
ImpulseWidthChange bool `json:"ImpulseWidthChange"`
LogbookFull bool `json:"LogbookFull"`
PowerFail bool `json:"PowerFail"`
TimeChanged bool `json:"TimeChanged"`
VTRatioChange bool `json:"VTRatioChange"`
Value int `json:"value"`
} `json:"errorcode"`
Medium struct {
Desc string `json:"desc"`
Type int `json:"type"`
} `json:"medium"`
Timestamp int `json:"timestamp"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
//log.Printf("Parse input: %d, %s", fPort, decodedPayload)
switch fPort {
case 1:
var emuMessage1 emuMessage1
err := json.Unmarshal(decodedPayload, &emuMessage1)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["ActivePowerL1"] = database.VariableType {
Variable: "ActivePowerL1",
Unit: emuMessage1.ActivePowerL1.Unit,
Value: emuMessage1.ActivePowerL1.Value,
}
(*variables)["ActivePowerL2"] = database.VariableType {
Variable: "ActivePowerL2",
Unit: emuMessage1.ActivePowerL2.Unit,
Value: emuMessage1.ActivePowerL2.Value,
}
(*variables)["ActivePowerL3"] = database.VariableType {
Variable: "ActivePowerL3",
Unit: emuMessage1.ActivePowerL3.Unit,
Value: emuMessage1.ActivePowerL3.Value,
}
(*variables)["ActivePowerL123"] = database.VariableType {
Variable: "ActivePowerL123",
Unit: emuMessage1.ActivePowerL123.Unit,
Value: emuMessage1.ActivePowerL123.Value,
}
(*variables)["PowerfactorL1"] = database.VariableType {
Variable: "PowerfactorL1",
Unit: emuMessage1.PowerfactorL1.Unit,
Value: emuMessage1.PowerfactorL1.Value,
}
(*variables)["PowerfactorL2"] = database.VariableType {
Variable: "PowerfactorL2",
Unit: emuMessage1.PowerfactorL2.Unit,
Value: emuMessage1.PowerfactorL2.Value,
}
(*variables)["PowerfactorL3"] = database.VariableType {
Variable: "PowerfactorL3",
Unit: emuMessage1.PowerfactorL3.Unit,
Value: emuMessage1.PowerfactorL3.Value,
}
return nil
case 2:
var emuMessage2 emuMessage2
err := json.Unmarshal(decodedPayload, &emuMessage2)
if err != nil {
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
}
(*variables)["ActiveEnergyExport"] = database.VariableType {
Variable: "ActiveEnergyExport",
Unit: emuMessage2.ActiveEnergyExport.Unit,
Value: emuMessage2.ActiveEnergyExport.Value,
}
(*variables)["ActiveEnergyImport"] = database.VariableType {
Variable: "ActiveEnergyImport",
Unit: emuMessage2.ActiveEnergyImport.Unit,
Value: emuMessage2.ActiveEnergyImport.Value,
}
(*variables)["ReactiveEnergyExport"] = database.VariableType {
Variable: "ReactiveEnergyExport",
Unit: emuMessage2.ReactiveEnergyExport.Unit,
Value: emuMessage2.ReactiveEnergyExport.Value,
}
(*variables)["ReactiveEnergyImport"] = database.VariableType {
Variable: "ReactiveEnergyImport",
Unit: emuMessage2.ReactiveEnergyImport.Unit,
Value: emuMessage2.ReactiveEnergyImport.Value,
}
return nil
default:
return fmt.Errorf("Unexpected fPort %d", fPort)
}
}

View File

@@ -0,0 +1,55 @@
package hottisGy21
import (
//"log"
"fmt"
"bytes"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisGy21Values struct {
Connected uint8
Status uint8
RawHumidity uint16
RawTemperature uint16
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisGy21Values
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var temperature float32 = -46.85 + 175.72 * (float32(values.RawTemperature) / 65536.0)
var humidity float32 = -6 + 125 * (float32(values.RawHumidity) / 65536.0);
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
(*variables)["Humidity"] = database.VariableType {
Label: "Humidity",
Variable: "Humidity",
Unit: "%",
Value: humidity,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: temperature,
}
(*attributes)["Status"] = values.Status
return nil
}

View File

@@ -0,0 +1,69 @@
package hottisScd30
import (
//"log"
"fmt"
"bytes"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisScd30Values struct {
Status uint8
CO2Conc int32
Temp int32
Hum int32
Bri int32
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisScd30Values
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var co2concentration float32 = float32(values.CO2Conc) / 100;
var temperature float32 = float32(values.Temp) / 100;
var humidity float32 = float32(values.Hum) / 100;
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
(*variables)["CO2concentration"] = database.VariableType {
Label: "CO2concentration",
Variable: "Concentration",
Unit: "ppm",
Value: co2concentration,
}
(*variables)["Temperature"] = database.VariableType {
Label: "Temperature",
Variable: "Temperature",
Unit: "°C",
Value: temperature,
}
(*variables)["Humidity"] = database.VariableType {
Label: "Humidity",
Variable: "Humidity",
Unit: "%",
Value: humidity,
}
(*variables)["Brightness"] = database.VariableType {
Label: "Brightness",
Variable: "Brightness",
Unit: "",
Value: values.Bri,
}
(*attributes)["Status"] = values.Status
return nil
}

View File

@@ -0,0 +1,93 @@
package hottisThreeWayThermometer
import (
"log"
"fmt"
"bytes"
"strconv"
"encoding/base64"
"encoding/binary"
"udi/database"
)
type hottisThreeWayThermometerValues struct {
Status uint8
Battery uint16
SensorAddress1 uint64
Value1 int32
SensorAddress2 uint64
Value2 int32
SensorAddress3 uint64
Value3 int32
}
func getSensorName(sensorsMap *map[string]interface{}, sensorAddress uint64) string {
key := strconv.FormatUint(sensorAddress, 10)
if sensorName, exists := (*sensorsMap)[key].(string); exists {
return sensorName
}
return "Sensor" + key
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
deviceAttrs := (*device).Attributes
sensorsMap := deviceAttrs["Sensors"].(map[string]interface{})
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
b, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
var values hottisThreeWayThermometerValues
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
if err != nil {
return fmt.Errorf("Unable to cast into struct: %v", err)
}
var battery float32 = float32(values.Battery) / 1000.0
var value1 float32 = float32(values.Value1) / 128.0
var value2 float32 = float32(values.Value2) / 128.0
var value3 float32 = float32(values.Value3) / 128.0
//log.Printf("Status: %d, Battery: %d", values.Status, values.Battery);
log.Printf("Status: %d", values.Status);
log.Printf("Battery: %d, %f", values.Battery, battery);
log.Printf("Sensor1: Addr: %d, Value: %f", values.SensorAddress1, value1);
log.Printf("Sensor2: Addr: %d, Value: %f", values.SensorAddress2, value2);
log.Printf("Sensor3: Addr: %d, Value: %f", values.SensorAddress3, value3);
(*variables)["Battery"] = database.VariableType {
Label: "Battery",
Variable: "Voltage",
Unit: "V",
Value: battery,
}
(*variables)["Temperature1"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress1),
Variable: "Temperature",
Unit: "°C",
Value: value1,
}
(*variables)["Temperature2"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress2),
Variable: "Temperature",
Unit: "°C",
Value: value2,
}
(*variables)["Temperature3"] = database.VariableType {
Label: getSensorName(&sensorsMap, values.SensorAddress3),
Variable: "Temperature",
Unit: "°C",
Value: value3,
}
(*attributes)["Status"] = values.Status
(*attributes)["SensorAddress1"] = values.SensorAddress1
(*attributes)["SensorAddress2"] = values.SensorAddress2
(*attributes)["SensorAddress3"] = values.SensorAddress3
return nil
}

View File

@@ -0,0 +1,25 @@
package rawPayloadPrinter
import (
"log"
"fmt"
"encoding/base64"
"encoding/hex"
"udi/database"
)
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
bytes, err := base64.StdEncoding.DecodeString(frmPayload)
if err != nil {
return fmt.Errorf("Unable to base64-decode payload: %v", err)
}
hexString := hex.EncodeToString(bytes)
log.Printf("Payload: %s", hexString)
return nil
}