Compare commits

...

4 Commits

Author SHA1 Message Date
d6e7fa3949 sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:22:39 +02:00
97c6a045d2 sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:14:29 +02:00
f10f9afd8b sensor labels
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-31 16:10:52 +02:00
64f74c60f3 battery
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 15:29:54 +02:00

View File

@ -4,14 +4,16 @@ import (
"log" "log"
"fmt" "fmt"
"bytes" "bytes"
"strconv"
"encoding/base64" "encoding/base64"
"encoding/binary" "encoding/binary"
"encoding/json"
"udi/database" "udi/database"
) )
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 +22,25 @@ type hottisThreeWayThermometerValues struct {
Value3 int32 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 {
sensorsMap := make(map[string]string)
sensorsJSON, ok := (*device).Attributes["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 { if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort) return fmt.Errorf("Unexpected fPort %d", fPort)
} }
@ -37,30 +56,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,