changes
This commit is contained in:
@@ -1,21 +1,20 @@
|
|||||||
package z2m
|
package z2m
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
"strings"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"encoding/json"
|
"strings"
|
||||||
|
"time"
|
||||||
"udi/config"
|
"udi/config"
|
||||||
"udi/handlers/handler"
|
|
||||||
"udi/database"
|
"udi/database"
|
||||||
"udi/handlers/z2m/models/wsdcgq11lm"
|
"udi/handlers/handler"
|
||||||
"udi/handlers/z2m/models/wsdcgq01lm"
|
|
||||||
"udi/handlers/z2m/models/gs361ah04"
|
"udi/handlers/z2m/models/gs361ah04"
|
||||||
|
"udi/handlers/z2m/models/wsdcgq01lm"
|
||||||
|
"udi/handlers/z2m/models/wsdcgq11lm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Z2MHandler struct {
|
type Z2MHandler struct {
|
||||||
handler.CommonHandler
|
handler.CommonHandler
|
||||||
dbh *database.DatabaseHandle
|
dbh *database.DatabaseHandle
|
||||||
@@ -46,13 +45,11 @@ func parse(T any, payload string, variables *map[string]database.VariableType) e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||||
t := &Z2MHandler {
|
t := &Z2MHandler{}
|
||||||
}
|
|
||||||
t.Id = id
|
t.Id = id
|
||||||
t.dbh = database.NewDatabaseHandle()
|
t.dbh = database.NewDatabaseHandle()
|
||||||
log.Printf("Handler Z2M %d initialized", id)
|
log.Printf("Handler Z2M %d initialized", id)
|
||||||
@@ -65,7 +62,6 @@ func (self *Z2MHandler) Handle(message handler.MessageT) {
|
|||||||
var measurement database.Measurement
|
var measurement database.Measurement
|
||||||
measurement.Time = time.Now()
|
measurement.Time = time.Now()
|
||||||
|
|
||||||
|
|
||||||
subTopics := strings.Split(message.Topic, "/")
|
subTopics := strings.Split(message.Topic, "/")
|
||||||
deviceId := subTopics[1]
|
deviceId := subTopics[1]
|
||||||
log.Printf("DeviceId: %s", deviceId)
|
log.Printf("DeviceId: %s", deviceId)
|
||||||
@@ -109,5 +105,3 @@ func (self *Z2MHandler) Handle(message handler.MessageT) {
|
|||||||
self.dbh.StoreMeasurement(&measurement)
|
self.dbh.StoreMeasurement(&measurement)
|
||||||
self.S()
|
self.S()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
135
src/udi/config-test-2.json
Normal file
135
src/udi/config-test-2.json
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
{
|
||||||
|
"mqtt": {
|
||||||
|
"broker": "mqtt://172.23.1.102:1883",
|
||||||
|
"tlsEnable": "false"
|
||||||
|
},
|
||||||
|
"topicMappings": [
|
||||||
|
{
|
||||||
|
"topics": [ "snmp" ],
|
||||||
|
"handler": "PREP",
|
||||||
|
"id": "SNMP",
|
||||||
|
"config": {
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "tsm" ],
|
||||||
|
"handler": "PREP",
|
||||||
|
"id": "TSM",
|
||||||
|
"config": {
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "dt1/ai/periodic/1" ],
|
||||||
|
"handler": "DT1T",
|
||||||
|
"id": "DT1T.0",
|
||||||
|
"config": {
|
||||||
|
"attributes": {
|
||||||
|
"Application": "Temperature Wago",
|
||||||
|
"Device": "Freezer",
|
||||||
|
"HardLow": "-273",
|
||||||
|
"SoftLow": "-50",
|
||||||
|
"SoftHigh": "20",
|
||||||
|
"HardHigh": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "dt1/ai/periodic/3" ],
|
||||||
|
"handler": "DT1T",
|
||||||
|
"id": "DT1T.1",
|
||||||
|
"config": {
|
||||||
|
"attributes": {
|
||||||
|
"Application": "Temperature Wago",
|
||||||
|
"Device": "Outdoor",
|
||||||
|
"HardLow": "-273",
|
||||||
|
"SoftLow": "-60",
|
||||||
|
"SoftHigh": "60",
|
||||||
|
"HardHigh": "100"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "IoT/PV/Values" ],
|
||||||
|
"handler": "PV",
|
||||||
|
"id": "PV",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "IoT/Car/Values" ],
|
||||||
|
"handler": "Car",
|
||||||
|
"id": "Car",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "IoT/MBGW3/Measurement" ],
|
||||||
|
"handler": "MBGW3",
|
||||||
|
"id": "MBGW3",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "IoT/OneWireGW/Bus 1/#" ],
|
||||||
|
"handler": "SVER",
|
||||||
|
"id": "SVER0",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
"application": "Temperature Heating",
|
||||||
|
"payloadRegex": "(\\d+(\\.\\d+)?)\\s*([^0-9\\s]\\S*)",
|
||||||
|
"deviceFrom": "topic",
|
||||||
|
"devicePart": "3",
|
||||||
|
"valueFrom": "payload",
|
||||||
|
"valuePart": "1",
|
||||||
|
"unitFrom": "payload",
|
||||||
|
"unitPart": "3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "shellyplusht/+/status/temperature:0" ],
|
||||||
|
"handler": "SVEJ",
|
||||||
|
"id": "SVEJ2",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
"application": "Temperature Shelly Plus HT",
|
||||||
|
"deviceSelector": "T:1",
|
||||||
|
"valueSelector": "J:$.tC",
|
||||||
|
"unitSelector": "C:°C"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "shellyplusht/+/status/humidity:0" ],
|
||||||
|
"handler": "SVEJ",
|
||||||
|
"id": "SVE4",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
"application": "Humidity Shelly Plus HT",
|
||||||
|
"deviceSelector": "T:1",
|
||||||
|
"valueSelector": "J:$.rh",
|
||||||
|
"unitSelector": "C:%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"archiver": {
|
||||||
|
"dir": "./tmp/udi"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user