Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
f63c22912a
|
|||
|
c37420a993
|
|||
|
ac0c417a48
|
|||
|
dc965aeba6
|
|||
|
b940f715c0
|
|||
|
8c5626942f
|
|||
|
6d0dc12ac1
|
|||
|
6a4aac4140
|
|||
|
77d23e39cf
|
|||
|
e28042f3be
|
|||
|
e1ad76f703
|
@@ -17,7 +17,7 @@ metadata:
|
||||
labels:
|
||||
app: udi
|
||||
annotations:
|
||||
secret.reloader.stakater.com/reload: "%PRE%-udi-conf,%PRE%-udi-db-cred,%PRE%-mqtt-password"
|
||||
secret.reloader.stakater.com/reload: "%PRE%-udi-conf,%PRE%-udi-db-cred,%PRE%-mqtt-password,%PRE%-udi-influxdb-cred"
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
|
||||
@@ -84,7 +84,7 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
|
||||
--dry-run=client \
|
||||
-o yaml \
|
||||
--save-config \
|
||||
--from-literal=INFLUXDB_URL="$INFLUXDB_URL" | \
|
||||
--from-literal=INFLUXDB_URL="${!INFLUXDB_URL}" | \
|
||||
kubectl apply -f - -n $NAMESPACE
|
||||
|
||||
# set configuration as configMap
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
"devicePart": "3",
|
||||
"valueFrom": "payload",
|
||||
"valuePart": "1",
|
||||
"valueType": "float",
|
||||
"unitFrom": "payload",
|
||||
"unitPart": "3"
|
||||
}
|
||||
@@ -165,7 +166,7 @@
|
||||
{
|
||||
"topics": [ "shellyplusht/+/status/humidity:0" ],
|
||||
"handler": "SVEJ",
|
||||
"id": "SVE4",
|
||||
"id": "SVEJ3",
|
||||
"config": {
|
||||
"databaseConnStr": "",
|
||||
"attributes": {
|
||||
@@ -175,6 +176,48 @@
|
||||
"unitSelector": "C:%"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "shellies/sensor/+/status/temperature:0" ],
|
||||
"handler": "SVEJ",
|
||||
"id": "SVEJ4",
|
||||
"config": {
|
||||
"databaseConnStr": "",
|
||||
"attributes": {
|
||||
"application": "Shellies Sensor Temperature",
|
||||
"deviceSelector": "T:2",
|
||||
"valueSelector": "J:$.tC",
|
||||
"unitSelector": "C:°C"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "shellies/sensor/+/status/humidity:0" ],
|
||||
"handler": "SVEJ",
|
||||
"id": "SVEJ5",
|
||||
"config": {
|
||||
"databaseConnStr": "",
|
||||
"attributes": {
|
||||
"application": "Shellies Sensor Humidity",
|
||||
"deviceSelector": "T:2",
|
||||
"valueSelector": "J:$.rh",
|
||||
"unitSelector": "C:%"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "shellies/sensor/+/status/devicepower:0" ],
|
||||
"handler": "SVEJ",
|
||||
"id": "SVEJ6",
|
||||
"config": {
|
||||
"databaseConnStr": "",
|
||||
"attributes": {
|
||||
"application": "Shellies Sensor Power",
|
||||
"deviceSelector": "T:2",
|
||||
"valueSelector": "J:$.battery.percent",
|
||||
"unitSelector": "C:%"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"archiver": {
|
||||
|
||||
@@ -40,7 +40,7 @@ func NewDatabaseHandle() *DatabaseHandle {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Unable to create InfluxDB client: %s", err)
|
||||
log.Printf("Unable to create InfluxDB client (config: URL: %s, Username: %s, Password: %s): %s", influxDB, username, password, err)
|
||||
db.initialized = false
|
||||
return &db
|
||||
}
|
||||
|
||||
@@ -2,15 +2,13 @@ package dt1t
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"time"
|
||||
"strconv"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
)
|
||||
|
||||
|
||||
type Dt1tHandler struct {
|
||||
handler.CommonHandler
|
||||
ready bool
|
||||
@@ -18,12 +16,10 @@ type Dt1tHandler struct {
|
||||
dbh *database.DatabaseHandle
|
||||
application string
|
||||
device string
|
||||
|
||||
}
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &Dt1tHandler {
|
||||
}
|
||||
t := &Dt1tHandler{}
|
||||
|
||||
if config.Attributes["Application"] == "" {
|
||||
log.Println("Error: application not configured")
|
||||
@@ -69,7 +65,7 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
||||
variable.Label = "Temperature"
|
||||
variable.Variable = ""
|
||||
variable.Unit = "°C"
|
||||
variable.Value = fmt.Sprintf("%f", temperatureF)
|
||||
variable.Value = temperatureF
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
measurement.Values["Value"] = variable
|
||||
|
||||
@@ -77,5 +73,3 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package svej
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
"github.com/oliveagle/jsonpath"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
|
||||
"github.com/oliveagle/jsonpath"
|
||||
)
|
||||
|
||||
type SingleValueExtractorJsonpathHandler struct {
|
||||
@@ -33,7 +34,6 @@ T:TopicPartIndex
|
||||
C:ConstantValue
|
||||
*/
|
||||
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &SingleValueExtractorJsonpathHandler{
|
||||
ready: false,
|
||||
@@ -76,12 +76,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t.Id = id
|
||||
t.ready = true
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler SVEJ %d initialized", id)
|
||||
log.Printf("Handler SVEJ %s initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (string, error) {
|
||||
var res string
|
||||
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (interface{}, error) {
|
||||
var res interface{}
|
||||
switch selector[:2] {
|
||||
case "J:":
|
||||
// extract using jsonpath from payload
|
||||
@@ -89,7 +89,7 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
|
||||
if e != nil {
|
||||
return "", fmt.Errorf("jp.Lookup failed with %s", e)
|
||||
}
|
||||
res = fmt.Sprint(r)
|
||||
res = r
|
||||
case "T:":
|
||||
// T: extract from topic
|
||||
i, e := strconv.Atoi(selector[2:])
|
||||
@@ -109,7 +109,6 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT) {
|
||||
if !self.ready {
|
||||
self.Lost("Handler is not marked as ready", nil, message)
|
||||
@@ -149,12 +148,12 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
|
||||
return
|
||||
}
|
||||
|
||||
measurement.Device = device
|
||||
measurement.Device = device.(string)
|
||||
|
||||
var variable database.VariableType
|
||||
variable.Label = ""
|
||||
variable.Variable = ""
|
||||
variable.Unit = unit
|
||||
variable.Unit = unit.(string)
|
||||
variable.Value = value
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
measurement.Values["Value"] = variable
|
||||
@@ -163,4 +162,3 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package sver
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"regexp"
|
||||
"log"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
)
|
||||
|
||||
|
||||
type SingleValueExtractorRegexHandler struct {
|
||||
handler.CommonHandler
|
||||
ready bool
|
||||
@@ -32,12 +31,12 @@ type localConfig struct {
|
||||
device string
|
||||
valueFrom string
|
||||
valuePart int
|
||||
valueType string
|
||||
unitFrom string
|
||||
unitPart int
|
||||
unit string
|
||||
}
|
||||
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &SingleValueExtractorRegexHandler{
|
||||
ready: false,
|
||||
@@ -88,6 +87,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
localConfig.valuePart = valuePart
|
||||
}
|
||||
|
||||
if config.Attributes["valueType"] != "float" && config.Attributes["valueType"] != "string" {
|
||||
log.Printf("Error: invalid value %s for valueType", config.Attributes["valueType"])
|
||||
return t
|
||||
}
|
||||
localConfig.valueType = config.Attributes["valueType"]
|
||||
|
||||
if config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL {
|
||||
log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"])
|
||||
return t
|
||||
@@ -161,6 +166,7 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
||||
variable.Label = ""
|
||||
variable.Variable = ""
|
||||
|
||||
var value string
|
||||
switch self.config.valueFrom {
|
||||
case PAYLOAD_SEL:
|
||||
if self.payloadRegex == nil {
|
||||
@@ -171,9 +177,19 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
||||
self.Lost("valuePart out of range", nil, message)
|
||||
return
|
||||
}
|
||||
variable.Value = payloadMatches[self.config.valuePart]
|
||||
value = payloadMatches[self.config.valuePart]
|
||||
case PAYLOAD_FULL_SEL:
|
||||
variable.Value = message.Payload
|
||||
value = message.Payload
|
||||
}
|
||||
if self.config.valueType == "float" {
|
||||
fValue, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
self.Lost("Unable to convert value to float", err, message)
|
||||
return
|
||||
}
|
||||
variable.Value = fValue
|
||||
} else {
|
||||
variable.Value = value
|
||||
}
|
||||
|
||||
switch self.config.unitFrom {
|
||||
@@ -197,4 +213,3 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user