Mainflux.mainflux/consumers/writers/influxdb/fields.go

36 lines
673 B
Go

package influxdb
import (
"strconv"
"github.com/mainflux/mainflux/pkg/transformers/senml"
)
type fields map[string]interface{}
func senmlFields(msg senml.Message) fields {
updateTime := strconv.FormatFloat(msg.UpdateTime, 'f', -1, 64)
ret := fields{
"protocol": msg.Protocol,
"unit": msg.Unit,
"updateTime": updateTime,
}
switch {
case msg.Value != nil:
ret["value"] = *msg.Value
case msg.StringValue != nil:
ret["stringValue"] = *msg.StringValue
case msg.DataValue != nil:
ret["dataValue"] = *msg.DataValue
case msg.BoolValue != nil:
ret["boolValue"] = *msg.BoolValue
}
if msg.Sum != nil {
ret["sum"] = *msg.Sum
}
return ret
}