64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package draginoLse01
|
|
|
|
import (
|
|
"fmt"
|
|
"encoding/json"
|
|
"udi/database"
|
|
)
|
|
|
|
/*
|
|
{
|
|
"Bat":3.211,
|
|
"TempC_DS18B20":"0.0",
|
|
"conduct_SOIL":32,
|
|
"temp_SOIL":"7.56",
|
|
"water_SOIL":"25.92"
|
|
}
|
|
*/
|
|
|
|
type message struct {
|
|
Bat float32 `json:"Bat"`
|
|
TempC_DS18B20 string `json:"TempC_DS18B20"`
|
|
Conduct_SOIL int `json:"conduct_SOIL"`
|
|
Temp_SOIL string `json:"temp_SOIL"`
|
|
Water_SOIL string `json:"water_SOIL"`
|
|
}
|
|
|
|
func Parse(fPort int, decodedPayload []byte, _ string, variables *map[string]database.VariableType, device *database.Device) error {
|
|
if fPort != 2 {
|
|
return fmt.Errorf("Unexpected fPort %d", fPort)
|
|
}
|
|
var message message
|
|
err := json.Unmarshal(decodedPayload, &message)
|
|
if err != nil {
|
|
return fmt.Errorf("Unable to parse payload, fPort %d, error %s", fPort, err)
|
|
}
|
|
(*variables)["Battery"] = database.VariableType {
|
|
Label: "Battery",
|
|
Variable: "Voltage",
|
|
Unit: "V",
|
|
Value: message.Bat,
|
|
}
|
|
(*variables)["Conductance"] = database.VariableType {
|
|
Label: "Conductance",
|
|
Variable: "Conductance",
|
|
Unit: "uS/cm",
|
|
Value: message.Conduct_SOIL,
|
|
}
|
|
(*variables)["Temperature"] = database.VariableType {
|
|
Label: "Temperature",
|
|
Variable: "Temperature",
|
|
Unit: "°C",
|
|
Value: message.Temp_SOIL,
|
|
}
|
|
(*variables)["Water"] = database.VariableType {
|
|
Label: "Water",
|
|
Variable: "Water",
|
|
Unit: "%",
|
|
Value: message.Water_SOIL,
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|