1
0
mirror of https://github.com/cmur2/miflorad.git synced 2025-06-26 22:30:24 +02:00

munin-miflora: refactor into two implementations using go-ble and gatt libraries, have common package

This commit is contained in:
cn
2018-12-14 09:45:13 +01:00
parent 51bb5a93c5
commit e75c04785a
11 changed files with 476 additions and 232 deletions

32
common/proto.go Normal file
View File

@ -0,0 +1,32 @@
package common
import (
"encoding/binary"
)
const (
MifloraServiceUUID = "00001204-0000-1000-8000-00805f9b34fb"
MifloraCharModeChangeUUID = "00001a00-0000-1000-8000-00805f9b34fb"
MifloraCharReadSensorDataUUID = "00001a01-0000-1000-8000-00805f9b34fb"
MifloraCharVersionBatteryUUID = "00001a02-0000-1000-8000-00805f9b34fb"
)
func MifloraGetModeChangeData() []byte {
return []byte{0xa0, 0x1f}
}
func ParseVersionBattery(bytes []byte) VersionBatteryResponse {
return VersionBatteryResponse{
string(bytes[2:]),
uint8(bytes[0]),
}
}
func ParseSensorData(bytes []byte) SensorDataResponse {
return SensorDataResponse{
Temperature: float64(binary.LittleEndian.Uint16(bytes[0:2])) / 10.0,
Brightness: binary.LittleEndian.Uint32(bytes[3:7]),
Moisture: uint8(bytes[7]),
Conductivity: binary.LittleEndian.Uint16(bytes[8:10]),
}
}