communication with influxdb is working, schema of data in influxdb is unusable so far, too many spare columns
This commit is contained in:
89
attic/ttn/models/draginoLdds75/draginoLdds75.go
Normal file
89
attic/ttn/models/draginoLdds75/draginoLdds75.go
Normal 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
83
attic/ttn/models/draginoLdds75/example-ldds75.json
Normal file
83
attic/ttn/models/draginoLdds75/example-ldds75.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
90
attic/ttn/models/draginoLmds200/draginoLmds200.go
Normal file
90
attic/ttn/models/draginoLmds200/draginoLmds200.go
Normal 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
84
attic/ttn/models/draginoLmds200/lmds200-example.json
Normal file
84
attic/ttn/models/draginoLmds200/lmds200-example.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
63
attic/ttn/models/draginoLse01/draginoLse01.go
Normal file
63
attic/ttn/models/draginoLse01/draginoLse01.go
Normal 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
|
||||
}
|
||||
|
||||
74
attic/ttn/models/draginoLsn50/draginoLsn50.go
Normal file
74
attic/ttn/models/draginoLsn50/draginoLsn50.go
Normal 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
124
attic/ttn/models/emuProfIILoRaCfg1/emu-fprot1-example.json
Normal file
124
attic/ttn/models/emuProfIILoRaCfg1/emu-fprot1-example.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
93
attic/ttn/models/emuProfIILoRaCfg1/emu-fprot2-example.json
Normal file
93
attic/ttn/models/emuProfIILoRaCfg1/emu-fprot2-example.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
257
attic/ttn/models/emuProfIILoRaCfg1/emuProfIILoRaCfg1.go
Normal file
257
attic/ttn/models/emuProfIILoRaCfg1/emuProfIILoRaCfg1.go
Normal 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)
|
||||
}
|
||||
}
|
||||
|
||||
55
attic/ttn/models/hottisGy21/hottisGY21.go
Normal file
55
attic/ttn/models/hottisGy21/hottisGY21.go
Normal 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
|
||||
}
|
||||
69
attic/ttn/models/hottisScd30/hottisScd30.go
Normal file
69
attic/ttn/models/hottisScd30/hottisScd30.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
25
attic/ttn/models/rawPayloadPrinter/rawPayloadPrinter.go
Normal file
25
attic/ttn/models/rawPayloadPrinter/rawPayloadPrinter.go
Normal 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
|
||||
}
|
||||
183
attic/ttn/ttn.go
Normal file
183
attic/ttn/ttn.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package ttn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/handlers/ttn/models/emuProfIILoRaCfg1"
|
||||
"udi/handlers/ttn/models/draginoLdds75"
|
||||
"udi/handlers/ttn/models/draginoLmds200"
|
||||
"udi/handlers/ttn/models/draginoLse01"
|
||||
"udi/handlers/ttn/models/draginoLsn50"
|
||||
"udi/handlers/ttn/models/rawPayloadPrinter"
|
||||
"udi/handlers/ttn/models/hottisScd30"
|
||||
"udi/handlers/ttn/models/hottisGy21"
|
||||
"udi/handlers/ttn/models/hottisThreeWayThermometer"
|
||||
"udi/database"
|
||||
)
|
||||
|
||||
|
||||
type TTNHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
|
||||
type DecodedPayloaderHolder struct {
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
type uplinkMessage struct {
|
||||
EndDeviceIds struct {
|
||||
DeviceId string `json:"device_id"`
|
||||
ApplicationIds struct {
|
||||
ApplicationId string `json:"application_id"`
|
||||
} `json:"application_ids"`
|
||||
DevEui string `json:"dev_eui"`
|
||||
JoinEui string `json:"join_eui"`
|
||||
DevAddr string `json:"dev_addr"`
|
||||
} `json:"end_device_ids"`
|
||||
ReceivedAt string `json:"received_at"`
|
||||
UplinkMessage struct {
|
||||
FCnt int `json:"f_cnt"`
|
||||
FPort int `json:"f_port"`
|
||||
FrmPayload string `json:"frm_payload"`
|
||||
DecodedPayload DecodedPayloaderHolder `json:"decoded_payload"`
|
||||
RxMetadata []struct {
|
||||
GatewayIds struct {
|
||||
GatewayId string `json:"gateway_id"`
|
||||
Eui string `json:"eui"`
|
||||
} `json:"gateway_ids"`
|
||||
Time string `json:"time"`
|
||||
Rssi int `json:"rssi"`
|
||||
ChannelRssi int `json:"channel_rssi"`
|
||||
Snr float32 `json:"snr"`
|
||||
ChannelIndex int `json:"channel_index"`
|
||||
} `json:"rx_metadata"`
|
||||
ConsumedAirtime string `json:"consumed_airtime"`
|
||||
} `json:"uplink_message"`
|
||||
}
|
||||
|
||||
type gatewayAttributes struct {
|
||||
GatewayId string `json:"gateway_id"`
|
||||
Rssi int `json:"rssi"`
|
||||
Snr float32 `json:"snr"`
|
||||
}
|
||||
|
||||
type attributes struct {
|
||||
DeviceId string `json:"device_id"`
|
||||
ApplicationId string `json:"application_id"`
|
||||
FCnt int `json:"f_cnt"`
|
||||
FPort int `json:"f_port"`
|
||||
FrmPayload string `json:"frm_payload"`
|
||||
Gateways []gatewayAttributes `json:"gateways"`
|
||||
ConsumedAirtime string `json:"consumed_airtime"`
|
||||
}
|
||||
|
||||
func (self *DecodedPayloaderHolder) UnmarshalJSON(data []byte) error {
|
||||
self.Payload = data
|
||||
return nil
|
||||
}
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &TTNHandler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler TTN %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *TTNHandler) Handle(message handler.MessageT) {
|
||||
//log.Printf("Handler TTN %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||
|
||||
var measurement database.Measurement
|
||||
measurement.Time = time.Now()
|
||||
|
||||
var uplinkMessage uplinkMessage
|
||||
err := json.Unmarshal([]byte(message.Payload), &uplinkMessage)
|
||||
if err != nil {
|
||||
self.Lost("Error when unmarshaling message", err, message)
|
||||
return
|
||||
}
|
||||
//log.Printf("Parsed message: %s", uplinkMessage)
|
||||
|
||||
var attributes attributes
|
||||
attributes.DeviceId = uplinkMessage.EndDeviceIds.DeviceId
|
||||
attributes.ApplicationId = uplinkMessage.EndDeviceIds.ApplicationIds.ApplicationId
|
||||
attributes.FCnt = uplinkMessage.UplinkMessage.FCnt
|
||||
attributes.FPort = uplinkMessage.UplinkMessage.FPort
|
||||
attributes.FrmPayload = uplinkMessage.UplinkMessage.FrmPayload
|
||||
attributes.ConsumedAirtime = uplinkMessage.UplinkMessage.ConsumedAirtime
|
||||
for _, rxm := range uplinkMessage.UplinkMessage.RxMetadata {
|
||||
//log.Printf("RXM: %s", rxm)
|
||||
g := gatewayAttributes { GatewayId: rxm.GatewayIds.GatewayId, Rssi: rxm.Rssi, Snr: rxm.Snr }
|
||||
attributes.Gateways = append(attributes.Gateways, g)
|
||||
}
|
||||
//log.Printf("Attributes: %s", attributes)
|
||||
measurement.Attributes = map[string]interface{} {
|
||||
"DeviceId": attributes.DeviceId,
|
||||
"ApplicationId": attributes.ApplicationId,
|
||||
"FCnt": attributes.FCnt,
|
||||
"FPort": attributes.FPort,
|
||||
"FrmPayload": attributes.FrmPayload,
|
||||
"Gateways": attributes.Gateways,
|
||||
"ConsumedAirtime": attributes.ConsumedAirtime,
|
||||
}
|
||||
|
||||
//log.Printf("ApplicationId: %s, DeviceId: %s", attributes.ApplicationId, attributes.DeviceId)
|
||||
device, err2 := self.dbh.GetDeviceByLabelAndApplication(attributes.ApplicationId, attributes.DeviceId)
|
||||
if err2 != nil {
|
||||
self.Lost("Error when loading device", err2, message)
|
||||
return
|
||||
}
|
||||
measurement.Application = attributes.ApplicationId
|
||||
measurement.Device = attributes.DeviceId
|
||||
measurement.Attributes["DeviceType"] = device.DeviceType.ModelIdentifier
|
||||
|
||||
//log.Printf("DeviceLabel: %s, DeviceType: %s", device.Label, device.DeviceType.ModelIdentifier)
|
||||
|
||||
var parser func(int, []byte, string, *map[string]database.VariableType, *map[string]interface{}, *database.Device) error
|
||||
switch device.DeviceType.ModelIdentifier {
|
||||
case "emu-prof-ii-lora-cfg1":
|
||||
parser = emuProfIILoRaCfg1.Parse
|
||||
case "dragino-ldds75":
|
||||
parser = draginoLdds75.Parse
|
||||
case "dragino-lmds200":
|
||||
parser = draginoLmds200.Parse
|
||||
case "dragino-lse01":
|
||||
parser = draginoLse01.Parse
|
||||
case "dragino-lsn50":
|
||||
parser = draginoLsn50.Parse
|
||||
case "raw-payload-printer":
|
||||
parser = rawPayloadPrinter.Parse
|
||||
case "hottis-scd30":
|
||||
parser = hottisScd30.Parse
|
||||
case "hottis-gy21":
|
||||
parser = hottisGy21.Parse
|
||||
case "hottis-threeway-thermometer":
|
||||
parser = hottisThreeWayThermometer.Parse
|
||||
default:
|
||||
self.Lost(fmt.Sprintf("No parser found for %s", device.DeviceType.ModelIdentifier), nil, message)
|
||||
return
|
||||
}
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
err3 := parser(uplinkMessage.UplinkMessage.FPort,
|
||||
uplinkMessage.UplinkMessage.DecodedPayload.Payload,
|
||||
uplinkMessage.UplinkMessage.FrmPayload,
|
||||
&(measurement.Values),
|
||||
&(measurement.Attributes),
|
||||
device)
|
||||
if err3 != nil {
|
||||
self.Lost("Model parser failed", err3, message)
|
||||
return
|
||||
}
|
||||
//log.Printf("Prepared measurement item: %s", measurement)
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
15
attic/z2m/models/gs361ah04/gs361ah04.go
Normal file
15
attic/z2m/models/gs361ah04/gs361ah04.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package gs361ah04
|
||||
|
||||
type Observation struct {
|
||||
LinkQuality uint8 `unit:"" json:"linkquality"`
|
||||
Battery uint8 `unit:"%" json:"battery"`
|
||||
AwayMode string `unit:"" json:"away_mode"`
|
||||
ChildLock string `unit:"" json:"child_lock"`
|
||||
CurrentHeatingSetpoint float32 `unit:"°C" json:"current_heating_setpoint"`
|
||||
LocalTemperature float32 `unit:"°C" json:"local_temperature"`
|
||||
Preset string `unit:"" json:"preset"`
|
||||
SystemMode string `unit:"" json:"system_mode"`
|
||||
ValveDetection string `unit:"" json:"valve_detection"`
|
||||
WindowDetection string `unit:"" json:"window_detection"`
|
||||
}
|
||||
|
||||
11
attic/z2m/models/wsdcgq01lm/wsdcgq01lm.go
Normal file
11
attic/z2m/models/wsdcgq01lm/wsdcgq01lm.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package wsdcgq01lm
|
||||
|
||||
type Observation struct {
|
||||
LinkQuality uint8 `unit:"" json:"linkquality"`
|
||||
Battery uint8 `unit:"%" json:"battery"`
|
||||
Humidity float32 `unit:"%H" json:"humidity"`
|
||||
Pressure float32 `unit:"mbar" json:"pressure"`
|
||||
Temperature float32 `unit:"°C" json:"temperature"`
|
||||
Voltage uint16 `unit:"mV" json:"voltage"`
|
||||
}
|
||||
|
||||
10
attic/z2m/models/wsdcgq11lm/wsdcgq11lm.go
Normal file
10
attic/z2m/models/wsdcgq11lm/wsdcgq11lm.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package wsdcgq11lm
|
||||
|
||||
type Observation struct {
|
||||
LinkQuality uint8 `unit:"" json:"linkquality"`
|
||||
Battery uint8 `unit:"%" json:"battery"`
|
||||
Humidity float32 `unit:"%H" json:"humidity"`
|
||||
Temperature float32 `unit:"°C" json:"temperature"`
|
||||
Voltage uint16 `unit:"mV" json:"voltage"`
|
||||
}
|
||||
|
||||
113
attic/z2m/z2m.go
Normal file
113
attic/z2m/z2m.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package z2m
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"strings"
|
||||
"reflect"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"udi/handlers/z2m/models/wsdcgq11lm"
|
||||
"udi/handlers/z2m/models/wsdcgq01lm"
|
||||
"udi/handlers/z2m/models/gs361ah04"
|
||||
)
|
||||
|
||||
|
||||
type Z2MHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
|
||||
func parse(T any, payload string, variables *map[string]database.VariableType) error {
|
||||
observationType := reflect.TypeOf(T)
|
||||
observation := reflect.New(observationType).Interface()
|
||||
|
||||
err := json.Unmarshal([]byte(payload), observation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse payload into Observation struct: %v, %s", err, payload)
|
||||
}
|
||||
|
||||
observationValue := reflect.ValueOf(observation).Elem()
|
||||
|
||||
for i := 0; i < observationType.NumField(); i++ {
|
||||
field := observationType.Field(i)
|
||||
name := field.Name
|
||||
unit := field.Tag.Get("unit")
|
||||
value := observationValue.Field(i).Interface()
|
||||
|
||||
(*variables)[name] = database.VariableType {
|
||||
Label: name,
|
||||
Variable: "y",
|
||||
Unit: unit,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &Z2MHandler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Z2M %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *Z2MHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler Z2M %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||
|
||||
var measurement database.Measurement
|
||||
measurement.Time = time.Now()
|
||||
|
||||
|
||||
subTopics := strings.Split(message.Topic, "/")
|
||||
deviceId := subTopics[1]
|
||||
log.Printf("DeviceId: %s", deviceId)
|
||||
device, err1 := self.dbh.GetDeviceByLabel(deviceId)
|
||||
if err1 != nil {
|
||||
self.Lost("Error when loading device", err1, message)
|
||||
return
|
||||
}
|
||||
log.Printf("Device: %s", device)
|
||||
|
||||
measurement.Application = device.Application.Label
|
||||
measurement.Device = device.Attributes["Label"].(string)
|
||||
|
||||
var T any
|
||||
switch device.DeviceType.ModelIdentifier {
|
||||
case "WSDCGQ11LM":
|
||||
T = wsdcgq11lm.Observation{}
|
||||
case "WSDCGQ01LM":
|
||||
T = wsdcgq01lm.Observation{}
|
||||
case "GS361A-H04":
|
||||
T = gs361ah04.Observation{}
|
||||
default:
|
||||
self.Lost(fmt.Sprintf("No parser found for %s", device.DeviceType.ModelIdentifier), nil, message)
|
||||
return
|
||||
}
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
measurement.Attributes = make(map[string]interface{})
|
||||
err3 := parse(T,
|
||||
message.Payload,
|
||||
&(measurement.Values))
|
||||
if err3 != nil {
|
||||
self.Lost("Model parser failed", err3, message)
|
||||
return
|
||||
}
|
||||
|
||||
measurement.Attributes["Status"] = "ok"
|
||||
measurement.Attributes["DeviceId"] = deviceId
|
||||
measurement.Attributes["DeviceModel"] = device.DeviceType.ModelIdentifier
|
||||
log.Printf("Prepared measurement item: %s", measurement)
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user