75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package draginoLsn50
|
|
|
|
import (
|
|
"fmt"
|
|
"encoding/json"
|
|
"udi/database"
|
|
)
|
|
|
|
/*
|
|
"decoded_payload": {
|
|
"ALARM_status": "FALSE",
|
|
"BatV": 3.659,
|
|
"Temp_Black": 3276.7,
|
|
"Temp_Red": 22.6,
|
|
"Temp_White": 3276.7,
|
|
"Work_mode": "DS18B20"
|
|
},
|
|
*/
|
|
type message struct {
|
|
ALARM_status string `json:"ALARM_status"`
|
|
Bat float32 `json:"BatV"`
|
|
Work_mode string `json:"Work_mode"`
|
|
Temp_Black float32 `json:"Temp_Black"`
|
|
Temp_Red float32 `json:"Temp_Red"`
|
|
Temp_White float32 `json:"Temp_White"`
|
|
}
|
|
|
|
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)
|
|
}
|
|
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)["Alarm"] = database.VariableType {
|
|
Label: "Alarm",
|
|
Variable: "Alarm",
|
|
Unit: "",
|
|
Value: message.ALARM_status,
|
|
}
|
|
(*variables)["Temp_Red"] = database.VariableType {
|
|
Label: "Temp_Red",
|
|
Variable: "Temperature",
|
|
Unit: "°C",
|
|
Value: message.Temp_Red,
|
|
}
|
|
(*variables)["Temp_Black"] = database.VariableType {
|
|
Label: "Temp_Black",
|
|
Variable: "Temperature",
|
|
Unit: "°C",
|
|
Value: message.Temp_Black,
|
|
}
|
|
(*variables)["Temp_White"] = database.VariableType {
|
|
Label: "Temp_White",
|
|
Variable: "Temperature",
|
|
Unit: "°C",
|
|
Value: message.Temp_White,
|
|
}
|
|
|
|
(*attributes)["Status"] = "Ok"
|
|
|
|
return nil
|
|
}
|
|
|
|
|
|
|