powerList []powertime
}
+type hexdevice struct {
+ *zigdevice
+ location string
+}
+
func (dev *powerdevice) filter() {
// if this gets excessive we can pass it down the chain
now := time.Now().UTC()
}
}
+func newhexdevice(friendlyName, location string) *hexdevice {
+ return &hexdevice{
+ zigdevice: newdevice(friendlyName),
+ location: location,
+ }
+}
+
func handleTemp(obj map[string]interface{}) {
logger.V(1).Info("Temperature received", "obj", obj)
// these should both probably be checked for existence and type but oh well
}
+func processPM25(location string, pm25 float64, sendChannel chan helper.RabbitSend) {
+ // should have the senseType setup correctly now, if we're still here
+ dataMap := make(map[string]interface{}, 0)
+ dataMap["location"] = location
+ dataMap["pm25"] = pm25
+ results, err := aqi.Calculate(aqi.PM25{Concentration: pm25})
+ if err != nil {
+ logger.Error(nil, "Unable to calculate AQI, ignoring this delivery")
+ return
+ }
+
+ aqi := results.AQI
+ dataMap["aqi"] = aqi
+
+ sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "aqi", IncludeDate: true}
+ sendChannel <- sendThis
+ // we don't want to have to loop back around on rabbit processing, so just set the gauge here
+ now := time.Now().UTC()
+ // do the label update here
+ pm25Gauge.With(prometheus.Labels{"location": location}).Set(pm25)
+ aqiGauge.With(prometheus.Labels{"location": location}).Set(aqi)
+
+ expireMutex.Lock()
+ defer expireMutex.Unlock()
+
+ aqiExpire[location] = now
+ pm25Expire[location] = now
+
+}
+
func (dev *diydevice) handleDIY(obj map[string]interface{}, sendChannel chan helper.RabbitSend) {
logger.V(1).Info("DIY data received", "obj", obj)
_, isAction := obj["action"]
} else if senseType == "pm25" {
location := data["location"].(string)
pm25 := data["pm25"].(float64)
- dataMap["location"] = location
- dataMap["pm25"] = pm25
- results, err := aqi.Calculate(aqi.PM25{Concentration: pm25})
- if err != nil {
- logger.Error(nil, "Unable to calculate AQI, ignoring this delivery")
- return
- }
-
- aqi := results.AQI
- dataMap["aqi"] = aqi
-
- sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "aqi", IncludeDate: true}
- sendChannel <- sendThis
- // we don't want to have to loop back around on rabbit processing, so just set the gauge here
- now := time.Now().UTC()
- // do the label update here
- pm25Gauge.With(prometheus.Labels{"location": location}).Set(pm25)
- aqiGauge.With(prometheus.Labels{"location": location}).Set(aqi)
-
- expireMutex.Lock()
- defer expireMutex.Unlock()
-
- aqiExpire[location] = now
- pm25Expire[location] = now
-
+ processPM25(location, pm25, sendChannel)
} else {
logger.Info("Sense type not detected, ignoring")
}
}
+func (dev *hexdevice) handleHex(obj map[string]interface{}, sendChannel chan helper.RabbitSend) {
+ //now := time.Now().UTC()
+ logger.V(1).Info("Hex data received", "obj", obj)
+ pm25, ok := obj["pm25"].(float64)
+ if !ok {
+ logger.Error(nil, "contact not found in data, ignoring", "obj", obj)
+ return
+ }
+ processPM25(dev.location, pm25, sendChannel)
+
+ temperature, ok := obj["temperature"].(float64)
+ if !ok {
+ logger.Error(nil, "contact not found in data, ignoring", "obj", obj)
+ return
+ }
+
+ dataMap := make(map[string]interface{}, 0)
+ // these should all exist properly
+ dataMap["fahrenheit"] = temperature*9/5 + 32
+ dataMap["celsius"] = temperature
+ dataMap["location"] = dev.location
+ logger.V(2).Info("Sending reprocessed temperature")
+ // hardcoded temp routingKey for this type of measurement
+ sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "temp", IncludeDate: true}
+ sendChannel <- sendThis
+}
+
func (dev *doordevice) handleDoor(obj map[string]interface{}, sendChannel chan helper.RabbitSend) {
//now := time.Now().UTC()
- logger.V(0).Info("Door data received", "obj", obj)
+ logger.V(1).Info("Door data received", "obj", obj)
doorOpened := false
doorTampered := false
case *doordevice:
logger.V(2).Info("Door device, sending to handle", "device", device)
device.(*doordevice).handleDoor(item, channel)
+ case *hexdevice:
+ logger.V(2).Info("Hex device, sending to handle", "device", device)
+ device.(*hexdevice).handleHex(item, channel)
+
default:
logger.Info("Found a device we can't classify", "device", device, "type", t)
}
devices = append(devices, newdoordevice("front_door"))
devices = append(devices, newdoordevice("data_door"))
+ // hex devices (super custom)
+ devices = append(devices, newhexdevice("0xfffe7e6af7f95560", "Downstairs Test"))
+
//currentTemp, err := fetchTemp(weatherStation)
channel := make(chan helper.RabbitSend)