locative handler
This commit is contained in:
@ -67,3 +67,12 @@ create or replace view soil_v as
|
|||||||
device
|
device
|
||||||
from measurements
|
from measurements
|
||||||
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'dragino-lse01';
|
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'dragino-lse01';
|
||||||
|
|
||||||
|
create or replace view co2_v as
|
||||||
|
select time,
|
||||||
|
cast(values->'CO2concentration'->>'value' as float) as co2concentration,
|
||||||
|
cast(values->'Humidity'->>'value' as float) as humidity,
|
||||||
|
cast(values->'Temperature'->>'value' as float) as temperature,
|
||||||
|
device
|
||||||
|
from measurements
|
||||||
|
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'hottis-scd30';
|
||||||
|
@ -16,6 +16,7 @@ import "udi/handlers/mbgw3"
|
|||||||
import "udi/handlers/sver"
|
import "udi/handlers/sver"
|
||||||
import "udi/handlers/svej"
|
import "udi/handlers/svej"
|
||||||
import "udi/handlers/dt1t"
|
import "udi/handlers/dt1t"
|
||||||
|
import "udi/handlers/locative"
|
||||||
|
|
||||||
|
|
||||||
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
||||||
@ -44,6 +45,8 @@ func InitDispatcher() {
|
|||||||
factory = svej.New
|
factory = svej.New
|
||||||
case "DT1T":
|
case "DT1T":
|
||||||
factory = dt1t.New
|
factory = dt1t.New
|
||||||
|
case "Locative":
|
||||||
|
factory = locative.New
|
||||||
default:
|
default:
|
||||||
factory = nil
|
factory = nil
|
||||||
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
|
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
|
||||||
|
73
src/udi/handlers/locative/locative.go
Normal file
73
src/udi/handlers/locative/locative.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package locative
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
"log"
|
||||||
|
"encoding/json"
|
||||||
|
"udi/config"
|
||||||
|
"udi/handlers/handler"
|
||||||
|
"udi/database"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
type LocativeHandler struct {
|
||||||
|
handler.CommonHandler
|
||||||
|
dbh *database.DatabaseHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
type locativeEvent struct {
|
||||||
|
Trigger string `json:"trigger"`
|
||||||
|
Device string `json:"device"`
|
||||||
|
Location string `json:"location"`
|
||||||
|
Latitude string `json:"latitude"`
|
||||||
|
Longitude string `json:"longitude"`
|
||||||
|
Person string `json:"person"`
|
||||||
|
Timestamp string `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||||
|
t := &LocativeHandler {
|
||||||
|
}
|
||||||
|
t.Id = id
|
||||||
|
t.dbh = database.NewDatabaseHandle()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *LocativeHandler) Handle(message handler.MessageT) {
|
||||||
|
log.Printf("Handler Locative %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||||
|
|
||||||
|
var locativeEvent locativeEvent
|
||||||
|
err := json.Unmarshal([]byte(message.Payload), &locativeEvent)
|
||||||
|
if err != nil {
|
||||||
|
self.Lost("Unable to parse payload into locativeEvent struct", err, message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
variables := make(map[string]database.VariableType)
|
||||||
|
locativeEventStructValue := reflect.ValueOf(locativeEvent)
|
||||||
|
for i := 0; i < locativeEventStructValue.NumField(); i++ {
|
||||||
|
field := locativeEventStructValue.Type().Field(i)
|
||||||
|
fieldValue := locativeEventStructValue.Field(i)
|
||||||
|
v := database.VariableType {
|
||||||
|
Label: "",
|
||||||
|
Variable: field.Name,
|
||||||
|
Unit: "",
|
||||||
|
Value: fieldValue.Interface(),
|
||||||
|
}
|
||||||
|
variables[field.Name] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
measurement := database.Measurement {
|
||||||
|
Time: time.Now(),
|
||||||
|
Application: "Locative",
|
||||||
|
Device: locativeEvent.Person,
|
||||||
|
Values: variables,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.dbh.StoreMeasurement(&measurement)
|
||||||
|
self.S()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user