hottisScd30
This commit is contained in:
38
src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go
Normal file
38
src/udi/handlers/ttn/models/hottisScd30/hottisScd30.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user