Compare commits
1 Commits
influxdb-m
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
01acf835a8
|
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"mqtt": {
|
||||
"broker": "ssl://eu1.cloud.thethings.network:8883",
|
||||
"username": "com-passavant-geiger-poc@ttn",
|
||||
"tlsEnable": "true"
|
||||
},
|
||||
"topicMappings": [
|
||||
{
|
||||
"topics": [ "v3/com-passavant-geiger-poc@ttn/devices/#" ],
|
||||
"handler": "TTN",
|
||||
"id": "TTN0",
|
||||
"config": {
|
||||
"attributes": {
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"archiver": {
|
||||
"dir": "/archive"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"mqtt": {
|
||||
"broker": "ssl://eu1.cloud.thethings.network:8883",
|
||||
"username": "de-hottis-app01@ttn",
|
||||
"password": "ENV",
|
||||
"tlsEnable": "true"
|
||||
},
|
||||
"topicMappings": [
|
||||
{
|
||||
"topics": [ "v3/#" ],
|
||||
"handler": "TTN",
|
||||
"id": "TTN0",
|
||||
"config": {
|
||||
"attributes": {
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"archiver": {
|
||||
"dir": "/archive"
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package mbgw3
|
||||
|
||||
import (
|
||||
"time"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
)
|
||||
|
||||
|
||||
type Mbgw3Handler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
@@ -26,10 +25,8 @@ type Observation struct {
|
||||
Values map[string]string
|
||||
}
|
||||
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &Mbgw3Handler {
|
||||
}
|
||||
t := &Mbgw3Handler{}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler MBGW3 %d initialized", id)
|
||||
@@ -74,22 +71,12 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
unitMap := map[string]string{"Energy": "Wh", "Power": "W", "Voltage": "V", "Current": "A", "Volume": "m3"}
|
||||
keyCount := make(map[string]int)
|
||||
|
||||
for k, v := range observation.Values {
|
||||
unit, exists := unitMap[k]
|
||||
if !exists {
|
||||
unit = "Unmapped Unit"
|
||||
}
|
||||
|
||||
// Check if key already exists and create unique key if needed
|
||||
keyCount[k]++
|
||||
uniqueKey := k
|
||||
if keyCount[k] > 1 {
|
||||
uniqueKey = k + strconv.Itoa(keyCount[k])
|
||||
}
|
||||
|
||||
measurement.Values[uniqueKey] = database.VariableType {
|
||||
measurement.Values[k] = database.VariableType{
|
||||
Label: "",
|
||||
Variable: k,
|
||||
Unit: unit,
|
||||
@@ -102,5 +89,3 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user