Compare commits

...

3 Commits

Author SHA1 Message Date
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
4 changed files with 282 additions and 277 deletions

View File

@@ -105,6 +105,7 @@
"devicePart": "3",
"valueFrom": "payload",
"valuePart": "1",
"valueType": "float",
"unitFrom": "payload",
"unitPart": "3"
}

View File

@@ -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()
}

View File

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

View File

@@ -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()
}