Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
3af9482880
|
|||
df353d4f6c
|
|||
d1bbbeaccf
|
|||
8cfc92c226
|
|||
08e81e309c
|
|||
f44664eaad
|
|||
15458b9955
|
|||
f55990cc57
|
|||
766355f85d
|
@ -4,6 +4,15 @@
|
|||||||
"tlsEnable": "false"
|
"tlsEnable": "false"
|
||||||
},
|
},
|
||||||
"topicMappings": [
|
"topicMappings": [
|
||||||
|
{
|
||||||
|
"topics": [ "snmp" ],
|
||||||
|
"handler": "SNMP",
|
||||||
|
"id": "SNMP",
|
||||||
|
"config": {
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"topics": [ "dt1/ai/periodic/1" ],
|
"topics": [ "dt1/ai/periodic/1" ],
|
||||||
"handler": "DT1T",
|
"handler": "DT1T",
|
||||||
@ -44,6 +53,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "locative/event/#" ],
|
||||||
|
"handler": "Locative",
|
||||||
|
"id": "Locative",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"topics": [ "IoT/MBGW3/Measurement" ],
|
"topics": [ "IoT/MBGW3/Measurement" ],
|
||||||
"handler": "MBGW3",
|
"handler": "MBGW3",
|
||||||
|
@ -67,3 +67,23 @@ 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(m.values->'CO2concentration'->>'value' as float) as co2concentration,
|
||||||
|
cast(m.values->'Humidity'->>'value' as float) as humidity,
|
||||||
|
cast(m.values->'Temperature'->>'value' as float) as temperature,
|
||||||
|
m.device as device,
|
||||||
|
d.attributes->>'Label' as label
|
||||||
|
from measurements m, devices d
|
||||||
|
where m.application = 'de-hottis-app01' and
|
||||||
|
m.attributes->>'DeviceType' = 'hottis-scd30' and
|
||||||
|
m.device = d.label;
|
||||||
|
|
||||||
|
create or replace view locative_v as
|
||||||
|
select time,
|
||||||
|
device as person,
|
||||||
|
values->'Location'->>'value' as location,
|
||||||
|
values->'Trigger'->>'value' as direction
|
||||||
|
from measurements
|
||||||
|
where application = 'Locative';
|
||||||
|
@ -16,6 +16,8 @@ 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"
|
||||||
|
import "udi/handlers/snmp"
|
||||||
|
|
||||||
|
|
||||||
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
||||||
@ -44,6 +46,10 @@ func InitDispatcher() {
|
|||||||
factory = svej.New
|
factory = svej.New
|
||||||
case "DT1T":
|
case "DT1T":
|
||||||
factory = dt1t.New
|
factory = dt1t.New
|
||||||
|
case "Locative":
|
||||||
|
factory = locative.New
|
||||||
|
case "SNMP":
|
||||||
|
factory = snmp.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()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
73
src/udi/handlers/snmp/snmp.go
Normal file
73
src/udi/handlers/snmp/snmp.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package snmp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
"log"
|
||||||
|
"encoding/json"
|
||||||
|
"udi/config"
|
||||||
|
"udi/handlers/handler"
|
||||||
|
"udi/database"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
type SnmpHandler struct {
|
||||||
|
handler.CommonHandler
|
||||||
|
dbh *database.DatabaseHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
type endpoint_t struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
Variable string `json:"variable"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type observation_t struct {
|
||||||
|
Device string `json:"device"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
Variables map[string]endpoint_t `json:"variables"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||||
|
t := &SnmpHandler {
|
||||||
|
}
|
||||||
|
t.Id = id
|
||||||
|
t.dbh = database.NewDatabaseHandle()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SnmpHandler) Handle(message handler.MessageT) {
|
||||||
|
log.Printf("Handler SNMP %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||||
|
|
||||||
|
var observation observation_t
|
||||||
|
err := json.Unmarshal([]byte(message.Payload), &observation)
|
||||||
|
if err != nil {
|
||||||
|
self.Lost("Unable to parse payload into Observation struct", err, message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var measurement database.Measurement
|
||||||
|
measurement.Time = time.Now()
|
||||||
|
|
||||||
|
measurement.Application = "SNMP"
|
||||||
|
measurement.Device = observation.Device
|
||||||
|
|
||||||
|
measurement.Attributes = make(map[string]interface{})
|
||||||
|
|
||||||
|
measurement.Values = make(map[string]database.VariableType)
|
||||||
|
for k, v := range observation.Variables {
|
||||||
|
measurement.Values[k] = database.VariableType {
|
||||||
|
Label: v.Label,
|
||||||
|
Variable: v.Variable,
|
||||||
|
Unit: "",
|
||||||
|
Value: v.Value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Prepared measurement item: %s", measurement)
|
||||||
|
|
||||||
|
self.dbh.StoreMeasurement(&measurement)
|
||||||
|
self.S()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
package hottisScd30
|
package hottisScd30
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
//"log"
|
||||||
"fmt"
|
"fmt"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@ -17,7 +17,7 @@ type hottisScd30Values struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, _ *map[string]interface{}, _ *database.Device) error {
|
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
|
||||||
if fPort != 2 {
|
if fPort != 2 {
|
||||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||||
}
|
}
|
||||||
@ -32,7 +32,30 @@ func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]databas
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to cast into struct: %v", err)
|
return fmt.Errorf("Unable to cast into struct: %v", err)
|
||||||
}
|
}
|
||||||
log.Printf("CO2: %d, Temp: %d, Hum: %d, Status: %d", values.CO2Conc, values.Temp, values.Hum, values.Status)
|
var co2concentration float32 = float32(values.CO2Conc) / 100;
|
||||||
|
var temperature float32 = float32(values.Temp) / 100;
|
||||||
|
var humidity float32 = float32(values.Hum) / 100;
|
||||||
|
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
|
||||||
|
|
||||||
|
(*variables)["CO2concentration"] = database.VariableType {
|
||||||
|
Label: "CO2concentration",
|
||||||
|
Variable: "Concentration",
|
||||||
|
Unit: "ppm",
|
||||||
|
Value: co2concentration,
|
||||||
|
}
|
||||||
|
(*variables)["Temperature"] = database.VariableType {
|
||||||
|
Label: "Temperature",
|
||||||
|
Variable: "Temperature",
|
||||||
|
Unit: "°C",
|
||||||
|
Value: temperature,
|
||||||
|
}
|
||||||
|
(*variables)["Humidity"] = database.VariableType {
|
||||||
|
Label: "Humidity",
|
||||||
|
Variable: "Humidity",
|
||||||
|
Unit: "%",
|
||||||
|
Value: humidity,
|
||||||
|
}
|
||||||
|
|
||||||
|
(*attributes)["Status"] = values.Status
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user