mirror of
https://github.com/cmur2/miflorad.git
synced 2025-06-26 12:30:23 +02:00
munin-miflora: refactor helper into common, add RSSI and timing metrics
This commit is contained in:
@ -6,11 +6,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// captures response when reading meta data of miflora device
|
||||
type VersionBatteryResponse struct {
|
||||
BatteryLevel uint8 // in percent 0-100
|
||||
FirmwareVersion string // as "x.y.z"
|
||||
}
|
||||
|
||||
// captures response when reading sensor data of miflora device
|
||||
type SensorDataResponse struct {
|
||||
Temperature float64 // in degree C
|
||||
Brightness uint32 // in lux
|
||||
@ -18,8 +20,8 @@ type SensorDataResponse struct {
|
||||
Conductivity uint16 // in µS/cm
|
||||
}
|
||||
|
||||
// turns firmware version "2.3.4" into 20304
|
||||
func (res VersionBatteryResponse) NumericFirmwareVersion() int {
|
||||
// turns "2.3.4" into 20304
|
||||
version := 0
|
||||
parts := strings.Split(res.FirmwareVersion, ".")
|
||||
for i, part := range parts {
|
||||
@ -31,3 +33,8 @@ func (res VersionBatteryResponse) NumericFirmwareVersion() int {
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
||||
// for the newer models a magic number must be written before we can read the current data
|
||||
func (res VersionBatteryResponse) RequiresModeChangeBeforeRead() bool {
|
||||
return res.FirmwareVersion >= "2.6.6"
|
||||
}
|
||||
|
14
common/misc.go
Normal file
14
common/misc.go
Normal file
@ -0,0 +1,14 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const peripheralAddressAllowedChars = "[^a-z0-9]+"
|
||||
|
||||
var peripheralAddressAllowedCharsPattern = regexp.MustCompile(peripheralAddressAllowedChars)
|
||||
|
||||
func MifloraGetAlphaNumericID(peripheralAddress string) string {
|
||||
return peripheralAddressAllowedCharsPattern.ReplaceAllString(strings.ToLower(peripheralAddress), "")
|
||||
}
|
Reference in New Issue
Block a user