Compare commits
2 Commits
0.3.12
...
influxdb-m
| Author | SHA1 | Date | |
|---|---|---|---|
|
0f6590c720
|
|||
|
42ff8b51ed
|
@@ -34,20 +34,20 @@ type CarHandler struct {
|
||||
*/
|
||||
|
||||
type CarValue struct {
|
||||
Status string `unit:"" json:"status"`
|
||||
Timestamp string `unit:"" json:"timestamp"`
|
||||
VoltageL1 float32 `unit:"V" json:"voltageL1"`
|
||||
VoltageL2 float32 `unit:"V" json:"voltageL2"`
|
||||
VoltageL3 float32 `unit:"V" json:"voltageL3"`
|
||||
CurrentL1 float32 `unit:"A" json:"currentL1"`
|
||||
CurrentL2 float32 `unit:"A" json:"currentL2"`
|
||||
CurrentL3 float32 `unit:"A" json:"currentL3"`
|
||||
PowerL1 float32 `unit:"W" json:"powerL1"`
|
||||
PowerL2 float32 `unit:"W" json:"powerL2"`
|
||||
PowerL3 float32 `unit:"W" json:"powerL3"`
|
||||
TotalImportEnergy float32 `unit:"Wh" json:"totalImportEnergy"`
|
||||
TotalExportEnergy float32 `unit:"Wh" json:"totalExportEnergy"`
|
||||
Cnt int `unit:"" json:"cnt"`
|
||||
Status string `unit:"" json:"status"`
|
||||
Timestamp string `unit:"" json:"timestamp"`
|
||||
VoltageL1 float32 `unit:"V" json:"voltageL1"`
|
||||
VoltageL2 float32 `unit:"V" json:"voltageL2"`
|
||||
VoltageL3 float32 `unit:"V" json:"voltageL3"`
|
||||
CurrentL1 float32 `unit:"A" json:"currentL1"`
|
||||
CurrentL2 float32 `unit:"A" json:"currentL2"`
|
||||
CurrentL3 float32 `unit:"A" json:"currentL3"`
|
||||
PowerL1 float32 `unit:"W" json:"powerL1"`
|
||||
PowerL2 float32 `unit:"W" json:"powerL2"`
|
||||
PowerL3 float32 `unit:"W" json:"powerL3"`
|
||||
TotalImportEnergy float32 `unit:"Wh" json:"totalImportEnergy"`
|
||||
TotalExportEnergy float32 `unit:"Wh" json:"totalExportEnergy"`
|
||||
Cnt int `unit:"" json:"cnt"`
|
||||
}
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
|
||||
@@ -1,79 +1,74 @@
|
||||
package prepared
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
)
|
||||
|
||||
|
||||
type PreparedHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
|
||||
type endpoint_t struct {
|
||||
Label string `json:"label"`
|
||||
Variable string `json:"variable"`
|
||||
Value string `json:"value"`
|
||||
Unit string `json:"unit"`
|
||||
Status string `json:"status"`
|
||||
Label string `json:"label"`
|
||||
Variable string `json:"variable"`
|
||||
Value interface{} `json:"value"`
|
||||
Unit string `json:"unit"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type observation_t struct {
|
||||
Device string `json:"device"`
|
||||
Label string `json:"label"`
|
||||
Variables map[string]endpoint_t `json:"variables"`
|
||||
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 := &PreparedHandler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Prepared %d initialized", id)
|
||||
return t
|
||||
t := &PreparedHandler{}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Prepared %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *PreparedHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler Prepared %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||
log.Printf("Handler Prepared %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 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()
|
||||
var measurement database.Measurement
|
||||
measurement.Time = time.Now()
|
||||
|
||||
measurement.Application = self.Id
|
||||
measurement.Device = observation.Device
|
||||
measurement.Application = self.Id
|
||||
measurement.Device = observation.Device
|
||||
|
||||
measurement.Attributes = map[string]interface{} {
|
||||
"Label": observation.Label,
|
||||
}
|
||||
measurement.Attributes = map[string]interface{}{
|
||||
"Label": observation.Label,
|
||||
}
|
||||
|
||||
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: v.Unit,
|
||||
Value: v.Value,
|
||||
Status: v.Status,
|
||||
}
|
||||
}
|
||||
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: v.Unit,
|
||||
Value: v.Value,
|
||||
Status: v.Status,
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Prepared measurement item: %s", measurement)
|
||||
log.Printf("Prepared measurement item: %s", measurement)
|
||||
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user