add status in ttn handlers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
2023-12-28 15:48:51 +01:00
parent b374b7f49d
commit b938d48c7f
7 changed files with 40 additions and 12 deletions

View File

@ -26,7 +26,7 @@ type message struct {
Dis2 int `json:"dis2"`
}
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, device *database.Device) error {
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort)
}
@ -55,6 +55,15 @@ func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]dat
Unit: "mm",
Value: distance2,
}
if distance1 == 2 {
(*attributes)["Status"] = "invalid value"
} else if distance1 == 1 {
(*attributes)["Status"] = "no sensor detected"
} else {
(*attributes)["Status"] = "Ok"
}
groundLevelI, exists := device.Attributes["GroundLevel"]
groundLevelS, ok := groundLevelI.(string)
groundLevel, err3 := strconv.Atoi(groundLevelS)