Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2f16c811a
|
|||
6f9327fdd6
|
|||
1d1942a4d3
|
|||
d6e7fa3949
|
|||
97c6a045d2
|
|||
f10f9afd8b
|
|||
64f74c60f3
|
@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"fmt"
|
"fmt"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strconv"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"udi/database"
|
"udi/database"
|
||||||
@ -11,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type hottisThreeWayThermometerValues struct {
|
type hottisThreeWayThermometerValues struct {
|
||||||
Status uint8
|
Status uint8
|
||||||
// Battery uint16
|
Battery uint16
|
||||||
SensorAddress1 uint64
|
SensorAddress1 uint64
|
||||||
Value1 int32
|
Value1 int32
|
||||||
SensorAddress2 uint64
|
SensorAddress2 uint64
|
||||||
@ -20,8 +21,18 @@ type hottisThreeWayThermometerValues struct {
|
|||||||
Value3 int32
|
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{})
|
||||||
|
|
||||||
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
|
|
||||||
if fPort != 2 {
|
if fPort != 2 {
|
||||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||||
}
|
}
|
||||||
@ -37,30 +48,38 @@ func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]databas
|
|||||||
return fmt.Errorf("Unable to cast into struct: %v", err)
|
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 value1 float32 = float32(values.Value1) / 128.0
|
||||||
var value2 float32 = float32(values.Value2) / 128.0
|
var value2 float32 = float32(values.Value2) / 128.0
|
||||||
var value3 float32 = float32(values.Value3) / 128.0
|
var value3 float32 = float32(values.Value3) / 128.0
|
||||||
|
|
||||||
//log.Printf("Status: %d, Battery: %d", values.Status, values.Battery);
|
//log.Printf("Status: %d, Battery: %d", values.Status, values.Battery);
|
||||||
log.Printf("Status: %d", values.Status);
|
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("Sensor1: Addr: %d, Value: %f", values.SensorAddress1, value1);
|
||||||
log.Printf("Sensor2: Addr: %d, Value: %f", values.SensorAddress2, value2);
|
log.Printf("Sensor2: Addr: %d, Value: %f", values.SensorAddress2, value2);
|
||||||
log.Printf("Sensor3: Addr: %d, Value: %f", values.SensorAddress3, value3);
|
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 {
|
(*variables)["Temperature1"] = database.VariableType {
|
||||||
Label: "Temperature1",
|
Label: getSensorName(&sensorsMap, values.SensorAddress1),
|
||||||
Variable: "Temperature",
|
Variable: "Temperature",
|
||||||
Unit: "°C",
|
Unit: "°C",
|
||||||
Value: value1,
|
Value: value1,
|
||||||
}
|
}
|
||||||
(*variables)["Temperature2"] = database.VariableType {
|
(*variables)["Temperature2"] = database.VariableType {
|
||||||
Label: "Temperature2",
|
Label: getSensorName(&sensorsMap, values.SensorAddress2),
|
||||||
Variable: "Temperature",
|
Variable: "Temperature",
|
||||||
Unit: "°C",
|
Unit: "°C",
|
||||||
Value: value2,
|
Value: value2,
|
||||||
}
|
}
|
||||||
(*variables)["Temperature3"] = database.VariableType {
|
(*variables)["Temperature3"] = database.VariableType {
|
||||||
Label: "Temperature3",
|
Label: getSensorName(&sensorsMap, values.SensorAddress3),
|
||||||
Variable: "Temperature",
|
Variable: "Temperature",
|
||||||
Unit: "°C",
|
Unit: "°C",
|
||||||
Value: value3,
|
Value: value3,
|
||||||
|
Reference in New Issue
Block a user