From 73aaa2225dfea12d120597789900138fae619a5b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 7 Jan 2024 17:28:32 +0100 Subject: [PATCH] hottisScd30 --- .../ttn/models/hottisScd30/hottisScd30.go | 38 +++++++++++++++++++ src/udi/handlers/ttn/ttn.go | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go diff --git a/src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go b/src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go new file mode 100644 index 0000000..cc94ec6 --- /dev/null +++ b/src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go @@ -0,0 +1,38 @@ +package hottisScd30 + +import ( + "log" + "fmt" + "bytes" + "encoding/base64" + "encoding/binary" + "udi/database" +) + +type hottisScd30Values struct { + Status uint8 + CO2Conc int32 + Temp int32 + Hum int32 +} + + +func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error { + if fPort != 2 { + return fmt.Errorf("Unexpected fPort %d", fPort) + } + + b, err := base64.StdEncoding.DecodeString(frmPayload) + if err != nil { + return fmt.Errorf("Unable to base64-decode payload: %v", err) + } + + var values hottisScd30Values + err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values) + if err != nil { + return fmt.Errorf("Unable to cast into struct: %v", err) + } + log.Printf("CO2: %d, Temp: %d, Hum: %d, Status: %d", values.CO2Conc, values.Temp, values.Hum, values.Status) + + return nil +} diff --git a/src/udi/handlers/ttn/ttn.go b/src/udi/handlers/ttn/ttn.go index 7396bd6..c86222c 100644 --- a/src/udi/handlers/ttn/ttn.go +++ b/src/udi/handlers/ttn/ttn.go @@ -12,6 +12,7 @@ import ( "udi/handlers/ttn/models/draginoLmds200" "udi/handlers/ttn/models/draginoLse01" "udi/handlers/ttn/models/rawPayloadPrinter" + "udi/handlers/ttn/models/hottisScd30" "udi/database" ) @@ -146,6 +147,8 @@ func (self *TTNHandler) Handle(message handler.MessageT) { parser = draginoLse01.Parse case "raw-payload-printer": parser = rawPayloadPrinter.Parse + case "hottis-scd30": + parser = hottisScd30.Parse default: self.Lost(fmt.Sprintf("No parser found for %s", device.DeviceType.ModelIdentifier), nil, message) return