Compare commits

..

14 Commits

Author SHA1 Message Date
0f6590c720 float fix 4
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 21:49:51 +01:00
42ff8b51ed float fix 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 21:35:32 +01:00
f63c22912a float fix 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:57:32 +01:00
c37420a993 float fix 1
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:51:50 +01:00
ac0c417a48 small j for float 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:34:21 +01:00
dc965aeba6 small j for float 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:27:28 +01:00
b940f715c0 small j for float
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2026-03-06 20:25:04 +01:00
8c5626942f fix config 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 12:30:04 +01:00
6d0dc12ac1 fix config 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 11:28:28 +01:00
6a4aac4140 fix config
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 11:24:02 +01:00
77d23e39cf add new shellies 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-04 23:27:48 +01:00
e28042f3be add new shellies
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-04 23:25:59 +01:00
e1ad76f703 fix
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-04 12:10:29 +01:00
6dac149a48 influxdb url
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-04 11:21:55 +01:00
10 changed files with 489 additions and 433 deletions

View File

@@ -17,7 +17,7 @@ metadata:
labels: labels:
app: udi app: udi
annotations: 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: spec:
replicas: 1 replicas: 1
selector: selector:
@@ -36,6 +36,8 @@ spec:
name: %PRE%-udi-db-cred name: %PRE%-udi-db-cred
- secretRef: - secretRef:
name: %PRE%-mqtt-password name: %PRE%-mqtt-password
- secretRef:
name: %PRE%-udi-influxdb-cred
- configMapRef: - configMapRef:
name: %PRE%-udi-conf name: %PRE%-udi-conf
volumeMounts: volumeMounts:

View File

@@ -67,6 +67,7 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
DATABASE_VARIABLE=$VARIABLE_PREFIX"_PGDATABASE" DATABASE_VARIABLE=$VARIABLE_PREFIX"_PGDATABASE"
NEW_UDI_DB_DATABASE="${!DATABASE_VARIABLE}" NEW_UDI_DB_DATABASE="${!DATABASE_VARIABLE}"
NEW_UDI_DB_HOST=database.database1.svc.cluster.local NEW_UDI_DB_HOST=database.database1.svc.cluster.local
INFLUXDB_URL=$VARIABLE_PREFIX"_INFLUXDB_URL"
kubectl create secret generic $INSTANCE-udi-db-cred \ kubectl create secret generic $INSTANCE-udi-db-cred \
--dry-run=client \ --dry-run=client \
@@ -79,6 +80,13 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
--from-literal=PGSSLMODE="require" | \ --from-literal=PGSSLMODE="require" | \
kubectl apply -f - -n $NAMESPACE kubectl apply -f - -n $NAMESPACE
kubectl create secret generic $INSTANCE-udi-influxdb-cred \
--dry-run=client \
-o yaml \
--save-config \
--from-literal=INFLUXDB_URL="${!INFLUXDB_URL}" | \
kubectl apply -f - -n $NAMESPACE
# set configuration as configMap # set configuration as configMap
kubectl create configmap $INSTANCE-udi-conf \ kubectl create configmap $INSTANCE-udi-conf \
--from-literal=UDI_CONF="`cat $CONFIG_FILE`" \ --from-literal=UDI_CONF="`cat $CONFIG_FILE`" \

View File

@@ -105,6 +105,7 @@
"devicePart": "3", "devicePart": "3",
"valueFrom": "payload", "valueFrom": "payload",
"valuePart": "1", "valuePart": "1",
"valueType": "float",
"unitFrom": "payload", "unitFrom": "payload",
"unitPart": "3" "unitPart": "3"
} }
@@ -165,7 +166,7 @@
{ {
"topics": [ "shellyplusht/+/status/humidity:0" ], "topics": [ "shellyplusht/+/status/humidity:0" ],
"handler": "SVEJ", "handler": "SVEJ",
"id": "SVE4", "id": "SVEJ3",
"config": { "config": {
"databaseConnStr": "", "databaseConnStr": "",
"attributes": { "attributes": {
@@ -175,6 +176,48 @@
"unitSelector": "C:%" "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": { "archiver": {

View File

@@ -1,7 +1,8 @@
-----BEGIN PGP MESSAGE----- -----BEGIN PGP MESSAGE-----
jA0ECQMIOpibMyX5/pH90mMBMdpIUJC/lR3BeUddyWJjwixQcePZIAQ/QEV6VO71 jA0ECQMIYUoTHR96Qfb90psBoxuk38UXPXTWPCmdW690bi2+w34S4NLHZvHfe3Ra
2cleQWnw8Ll5/bKtDv94UMLDZy86YdcNyeUXDP5cYPrGAFqWLaBmkLbpAJf7LRtb nck319+PXvr0agfHGZ733hhTQv4sa8I2o6ICrgFqtKGfHmgnqL5kYNP9+NuV/IsF
nckgwR1+++GPvn5vNYcqGt92pB0= x3dxwjEejsZ5GYn/zk+CQceItQ8nyyJc2ms1KwTu2r4hMzuHmnVtvKxNCzPrw2N5
=xy3G SJIRhh41eequFkzELQqqXXu10raBFsttOemVhA==
=TySu
-----END PGP MESSAGE----- -----END PGP MESSAGE-----

View File

@@ -40,7 +40,7 @@ func NewDatabaseHandle() *DatabaseHandle {
}) })
if err != nil { 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 db.initialized = false
return &db return &db
} }

View File

@@ -2,15 +2,13 @@ package dt1t
import ( import (
"log" "log"
"fmt"
"time"
"strconv" "strconv"
"udi/handlers/handler" "time"
"udi/database"
"udi/config" "udi/config"
"udi/database"
"udi/handlers/handler"
) )
type Dt1tHandler struct { type Dt1tHandler struct {
handler.CommonHandler handler.CommonHandler
ready bool ready bool
@@ -18,12 +16,10 @@ type Dt1tHandler struct {
dbh *database.DatabaseHandle dbh *database.DatabaseHandle
application string application string
device string device string
} }
func New(id string, config config.HandlerConfigT) handler.Handler { func New(id string, config config.HandlerConfigT) handler.Handler {
t := &Dt1tHandler { t := &Dt1tHandler{}
}
if config.Attributes["Application"] == "" { if config.Attributes["Application"] == "" {
log.Println("Error: application not configured") log.Println("Error: application not configured")
@@ -69,7 +65,7 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
variable.Label = "Temperature" variable.Label = "Temperature"
variable.Variable = "" variable.Variable = ""
variable.Unit = "°C" variable.Unit = "°C"
variable.Value = fmt.Sprintf("%f", temperatureF) variable.Value = temperatureF
measurement.Values = make(map[string]database.VariableType) measurement.Values = make(map[string]database.VariableType)
measurement.Values["Value"] = variable measurement.Values["Value"] = variable
@@ -77,5 +73,3 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()
} }

View File

@@ -1,15 +1,14 @@
package prepared package prepared
import ( import (
"time"
"log"
"encoding/json" "encoding/json"
"log"
"time"
"udi/config" "udi/config"
"udi/handlers/handler"
"udi/database" "udi/database"
"udi/handlers/handler"
) )
type PreparedHandler struct { type PreparedHandler struct {
handler.CommonHandler handler.CommonHandler
dbh *database.DatabaseHandle dbh *database.DatabaseHandle
@@ -18,7 +17,7 @@ type PreparedHandler struct {
type endpoint_t struct { type endpoint_t struct {
Label string `json:"label"` Label string `json:"label"`
Variable string `json:"variable"` Variable string `json:"variable"`
Value string `json:"value"` Value interface{} `json:"value"`
Unit string `json:"unit"` Unit string `json:"unit"`
Status string `json:"status"` Status string `json:"status"`
} }
@@ -29,10 +28,8 @@ type observation_t struct {
Variables map[string]endpoint_t `json:"variables"` Variables map[string]endpoint_t `json:"variables"`
} }
func New(id string, config config.HandlerConfigT) handler.Handler { func New(id string, config config.HandlerConfigT) handler.Handler {
t := &PreparedHandler { t := &PreparedHandler{}
}
t.Id = id t.Id = id
t.dbh = database.NewDatabaseHandle() t.dbh = database.NewDatabaseHandle()
log.Printf("Handler Prepared %d initialized", id) log.Printf("Handler Prepared %d initialized", id)
@@ -75,5 +72,3 @@ func (self *PreparedHandler) Handle(message handler.MessageT) {
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()
} }

View File

@@ -1,16 +1,17 @@
package svej package svej
import ( import (
"encoding/json"
"fmt"
"log" "log"
"time"
"strconv" "strconv"
"strings" "strings"
"fmt" "time"
"github.com/oliveagle/jsonpath"
"encoding/json"
"udi/config" "udi/config"
"udi/handlers/handler"
"udi/database" "udi/database"
"udi/handlers/handler"
"github.com/oliveagle/jsonpath"
) )
type SingleValueExtractorJsonpathHandler struct { type SingleValueExtractorJsonpathHandler struct {
@@ -33,7 +34,6 @@ T:TopicPartIndex
C:ConstantValue C:ConstantValue
*/ */
func New(id string, config config.HandlerConfigT) handler.Handler { func New(id string, config config.HandlerConfigT) handler.Handler {
t := &SingleValueExtractorJsonpathHandler{ t := &SingleValueExtractorJsonpathHandler{
ready: false, ready: false,
@@ -76,12 +76,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
t.Id = id t.Id = id
t.ready = true t.ready = true
t.dbh = database.NewDatabaseHandle() t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SVEJ %d initialized", id) log.Printf("Handler SVEJ %s initialized", id)
return t return t
} }
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (string, error) { func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (interface{}, error) {
var res string var res interface{}
switch selector[:2] { switch selector[:2] {
case "J:": case "J:":
// extract using jsonpath from payload // extract using jsonpath from payload
@@ -89,7 +89,7 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
if e != nil { if e != nil {
return "", fmt.Errorf("jp.Lookup failed with %s", e) return "", fmt.Errorf("jp.Lookup failed with %s", e)
} }
res = fmt.Sprint(r) res = r
case "T:": case "T:":
// T: extract from topic // T: extract from topic
i, e := strconv.Atoi(selector[2:]) i, e := strconv.Atoi(selector[2:])
@@ -109,7 +109,6 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
return res, nil return res, nil
} }
func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT) { func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT) {
if !self.ready { if !self.ready {
self.Lost("Handler is not marked as ready", nil, message) self.Lost("Handler is not marked as ready", nil, message)
@@ -149,12 +148,12 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
return return
} }
measurement.Device = device measurement.Device = device.(string)
var variable database.VariableType var variable database.VariableType
variable.Label = "" variable.Label = ""
variable.Variable = "" variable.Variable = ""
variable.Unit = unit variable.Unit = unit.(string)
variable.Value = value variable.Value = value
measurement.Values = make(map[string]database.VariableType) measurement.Values = make(map[string]database.VariableType)
measurement.Values["Value"] = variable measurement.Values["Value"] = variable
@@ -163,4 +162,3 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()
} }

View File

@@ -1,17 +1,16 @@
package sver package sver
import ( import (
"time" "log"
"regexp"
"strconv" "strconv"
"strings" "strings"
"regexp" "time"
"log"
"udi/config" "udi/config"
"udi/handlers/handler"
"udi/database" "udi/database"
"udi/handlers/handler"
) )
type SingleValueExtractorRegexHandler struct { type SingleValueExtractorRegexHandler struct {
handler.CommonHandler handler.CommonHandler
ready bool ready bool
@@ -32,12 +31,12 @@ type localConfig struct {
device string device string
valueFrom string valueFrom string
valuePart int valuePart int
valueType string
unitFrom string unitFrom string
unitPart int unitPart int
unit string unit string
} }
func New(id string, config config.HandlerConfigT) handler.Handler { func New(id string, config config.HandlerConfigT) handler.Handler {
t := &SingleValueExtractorRegexHandler{ t := &SingleValueExtractorRegexHandler{
ready: false, ready: false,
@@ -88,6 +87,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
localConfig.valuePart = valuePart 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 { if config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL {
log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"]) log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"])
return t return t
@@ -161,6 +166,7 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
variable.Label = "" variable.Label = ""
variable.Variable = "" variable.Variable = ""
var value string
switch self.config.valueFrom { switch self.config.valueFrom {
case PAYLOAD_SEL: case PAYLOAD_SEL:
if self.payloadRegex == nil { if self.payloadRegex == nil {
@@ -171,9 +177,19 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
self.Lost("valuePart out of range", nil, message) self.Lost("valuePart out of range", nil, message)
return return
} }
variable.Value = payloadMatches[self.config.valuePart] value = payloadMatches[self.config.valuePart]
case PAYLOAD_FULL_SEL: 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 { switch self.config.unitFrom {
@@ -197,4 +213,3 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()
} }