Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6f9327fdd6
|
|||
1d1942a4d3
|
|||
d6e7fa3949
|
|||
97c6a045d2
|
|||
f10f9afd8b
|
@ -4,8 +4,10 @@ import (
|
||||
"log"
|
||||
"fmt"
|
||||
"bytes"
|
||||
"strconv"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"udi/database"
|
||||
)
|
||||
|
||||
@ -20,8 +22,26 @@ type hottisThreeWayThermometerValues struct {
|
||||
Value3 int32
|
||||
}
|
||||
|
||||
func getSensorName(sensorsMap *map[string]string, sensorAddress uint64) string {
|
||||
key := strconv.FormatUint(sensorAddress, 10)
|
||||
if sensorName, exists := (*sensorsMap)[key]; 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 := make(map[string]string)
|
||||
sensorsJSON, ok := deviceAttrs["Sensors"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unable to load sensor map from attributes")
|
||||
}
|
||||
errJ := json.Unmarshal([]byte(sensorsJSON), &sensorsMap)
|
||||
if errJ != nil {
|
||||
return fmt.Errorf("Unable to parse sensor map: %v", errJ)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
@ -56,19 +76,19 @@ func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]databas
|
||||
Value: battery,
|
||||
}
|
||||
(*variables)["Temperature1"] = database.VariableType {
|
||||
Label: "Temperature1",
|
||||
Label: getSensorName(&sensorsMap, values.SensorAddress1),
|
||||
Variable: "Temperature",
|
||||
Unit: "°C",
|
||||
Value: value1,
|
||||
}
|
||||
(*variables)["Temperature2"] = database.VariableType {
|
||||
Label: "Temperature2",
|
||||
Label: getSensorName(&sensorsMap, values.SensorAddress2),
|
||||
Variable: "Temperature",
|
||||
Unit: "°C",
|
||||
Value: value2,
|
||||
}
|
||||
(*variables)["Temperature3"] = database.VariableType {
|
||||
Label: "Temperature3",
|
||||
Label: getSensorName(&sensorsMap, values.SensorAddress3),
|
||||
Variable: "Temperature",
|
||||
Unit: "°C",
|
||||
Value: value3,
|
||||
|
Reference in New Issue
Block a user