change influxdb2 schema
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jeffrey C. Ollie 2020-08-13 00:46:28 -05:00
parent 523a561015
commit 6fa0a57a20
Signed by: jeff
GPG key ID: 6F86035A6D97044E
5 changed files with 58 additions and 42 deletions

View file

@ -83,7 +83,7 @@ func advHandler(advertisement ble.Advertisement) {
timestamp := time.Now()
description := bluetooth.GetDescription(advertisement.Addr())
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("rssi")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -92,8 +92,7 @@ func advHandler(advertisement ble.Advertisement) {
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "rssi")
point.AddTag("measurement_unit", "dBm")
point.AddTag("unit", "dBm")
point.AddField("value", advertisement.RSSI())
writeAPI.WritePoint(point)

View file

@ -37,20 +37,22 @@ func ParseCleargrassSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Log
zap.String("event_data", hex.Dump(eventData)))
continue
}
temperature := float64(binary.LittleEndian.Uint16(eventData[0:2])) / 10
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("temperature")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
}
point.AddTag("address", advertisement.Addr().String())
if description != "" {
point.AddTag("description", description)
}
point.AddTag("temperature_unit", "°C")
point.AddField("temperature", temperature)
point.AddTag("unit", "°C")
point.AddField("value", temperature)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -59,7 +61,8 @@ func ParseCleargrassSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Log
zap.Float64("value", temperature))
humidity := float64(binary.LittleEndian.Uint16(eventData[2:4])) / 10
point = influxdb2.NewPointWithMeasurement("sensor")
point = influxdb2.NewPointWithMeasurement("humidity")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -68,9 +71,10 @@ func ParseCleargrassSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Log
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement_unit", "%")
point.AddField("humidity", humidity)
point.AddTag("unit", "%")
point.AddField("value", humidity)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -83,8 +87,10 @@ func ParseCleargrassSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Log
logger.Warn("battery event length should be 1")
continue
}
battery := int(eventData[0])
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("battery")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -93,10 +99,10 @@ func ParseCleargrassSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Log
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "battery")
point.AddTag("measurement_unit", "%")
point.AddTag("unit", "%")
point.AddField("value", battery)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),

View file

@ -128,7 +128,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
switch sensorData.eventData.eventType {
case temperatureEvent:
sensorData.eventData.temperature = float64(int16(binary.LittleEndian.Uint16(sd.Data[eventOffset+3:]))) / 10.0
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("temperature")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -138,10 +139,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measaurement", "temperature")
point.AddTag("measurement_unit", "°C")
point.AddTag("unit", "°C")
point.AddField("value", sensorData.eventData.temperature)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -151,7 +152,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case humidityEvent:
sensorData.eventData.humidity = float64(binary.LittleEndian.Uint16(sd.Data[eventOffset+3:])) / 10.0
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("humidity")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -161,10 +163,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measaurement", "humidity")
point.AddTag("measaurement_unit", "%")
point.AddTag("unit", "%")
point.AddField("value", sensorData.eventData.humidity)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -174,7 +176,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case illuminanceEvent:
sensorData.eventData.illuminance = uint(sd.Data[eventOffset+3]) + uint(sd.Data[eventOffset+4])<<8 + uint(sd.Data[eventOffset+5])<<16
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("illuminance")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -184,10 +187,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "illuminance")
point.AddTag("measurement_unit", "lx")
point.AddTag("unit", "lx")
point.AddField("value", sensorData.eventData.illuminance)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -197,7 +200,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case moistureEvent:
sensorData.eventData.moisture = int8(sd.Data[eventOffset+3])
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("moisture")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -207,10 +211,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "moisture")
point.AddTag("measurement_unit", "%")
point.AddTag("unit", "%")
point.AddField("value", sensorData.eventData.moisture)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -220,7 +224,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case conductivityEvent:
sensorData.eventData.conductivity = int16(binary.LittleEndian.Uint16(sd.Data[eventOffset+3:]))
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("conductivity")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -230,10 +235,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "conductivity")
point.AddTag("measurement_unit", "µS/cm")
point.AddTag("unit", "µS/cm")
point.AddField("value", sensorData.eventData.conductivity)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -243,7 +248,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case batteryEvent:
sensorData.eventData.battery = uint8(sd.Data[eventOffset+3])
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("battery")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -253,10 +259,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "battery")
point.AddTag("measurement_unit", "%")
point.AddTag("unit", "%")
point.AddField("value", sensorData.eventData.battery)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -266,7 +272,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
case temperatureAndHumidityEvent:
sensorData.eventData.temperature = float64(int16(binary.LittleEndian.Uint16(sd.Data[eventOffset+3:]))) / 10.0
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("temperature")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -276,10 +283,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "temperature")
point.AddTag("measurement_unit", "°C")
point.AddTag("unit", "°C")
point.AddField("value", sensorData.eventData.temperature)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
@ -288,7 +295,8 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
zap.Float64("value", sensorData.eventData.temperature))
sensorData.eventData.humidity = float64(binary.LittleEndian.Uint16(sd.Data[eventOffset+5:])) / 10.0
point = influxdb2.NewPointWithMeasurement("sensor")
point = influxdb2.NewPointWithMeasurement("humidity")
point.SetTime(timestamp)
if detector != "" {
point.AddTag("detector", detector)
@ -298,10 +306,10 @@ func ParseXiaomiMijiaSensorData(writeAPI *influxdb2_api.WriteAPI, logger *zap.Lo
if description != "" {
point.AddTag("description", description)
}
point.AddTag("measurement", "humidity")
point.AddTag("measurement_unit", "%")
point.AddTag("unit", "%")
point.AddField("value", sensorData.eventData.humidity)
(*writeAPI).WritePoint(point)
logger.Debug("sending sensor reading",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),

View file

@ -13,7 +13,7 @@ var XiaomiScaleV1UUID ble.UUID = []byte{0x1d, 0x18}
// ParseXiaomiScaleV1 parses V1 scale service data
func ParseXiaomiScaleV1(writeAPI *influxdb2_api.WriteAPI, logger *zap.Logger, timestamp time.Time, detector string, description string, advertisement ble.Advertisement, index int, sd ble.ServiceData) {
logger.Debug("xiaomi v1 scale",
logger.Info("xiaomi v1 scale",
zap.String("source", advertisement.Addr().String()),
zap.String("description", description),
zap.String("name", advertisement.LocalName()),

View file

@ -71,16 +71,19 @@ func ParseXiaomiScaleV2(writeAPI *influxdb2_api.WriteAPI, logger *zap.Logger, ti
loc)
difference := timestamp.Sub(scaleTimestamp)
point := influxdb2.NewPointWithMeasurement("sensor")
point := influxdb2.NewPointWithMeasurement("weight")
point.SetTime(scaleTimestamp)
if detector != "" {
point.AddTag("detector", detector)
}
point.AddTag("address", advertisement.Addr().String())
point.AddTag("weight_unit", "kg")
point.AddTag("original_weight_unit", originalUnit)
if description != "" {
point.AddTag("description", description)
}
point.AddTag("unit", "kg")
point.AddTag("original_unit", originalUnit)
point.AddField("time_difference", difference.Seconds())
point.AddField("weight", weight)
point.AddField("value", weight)
if hasImpedance {
point.AddField("impedance", scaleData.Impedance)
}