Compare commits

...

1 Commits

Author SHA1 Message Date
b6132afb11 disable logging in ttn
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-12-27 12:14:05 +01:00

View File

@ -2,7 +2,7 @@ package ttn
import ( import (
"fmt" "fmt"
"log" //"log"
"time" "time"
"encoding/json" "encoding/json"
"udi/config" "udi/config"
@ -86,7 +86,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
} }
func (self *TTNHandler) Handle(message handler.MessageT) { func (self *TTNHandler) Handle(message handler.MessageT) {
log.Printf("Handler TTN %d processing %s -> %s", self.Id, message.Topic, message.Payload) //log.Printf("Handler TTN %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var measurement database.Measurement var measurement database.Measurement
measurement.Time = time.Now() measurement.Time = time.Now()
@ -97,7 +97,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
self.Lost("Error when unmarshaling message", err, message) self.Lost("Error when unmarshaling message", err, message)
return return
} }
log.Printf("Parsed message: %s", uplinkMessage) //log.Printf("Parsed message: %s", uplinkMessage)
var attributes attributes var attributes attributes
attributes.DeviceId = uplinkMessage.EndDeviceIds.DeviceId attributes.DeviceId = uplinkMessage.EndDeviceIds.DeviceId
@ -107,11 +107,11 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
attributes.FrmPayload = uplinkMessage.UplinkMessage.FrmPayload attributes.FrmPayload = uplinkMessage.UplinkMessage.FrmPayload
attributes.ConsumedAirtime = uplinkMessage.UplinkMessage.ConsumedAirtime attributes.ConsumedAirtime = uplinkMessage.UplinkMessage.ConsumedAirtime
for _, rxm := range uplinkMessage.UplinkMessage.RxMetadata { for _, rxm := range uplinkMessage.UplinkMessage.RxMetadata {
log.Printf("RXM: %s", rxm) //log.Printf("RXM: %s", rxm)
g := gatewayAttributes { GatewayId: rxm.GatewayIds.GatewayId, Rssi: rxm.Rssi, Snr: rxm.Snr } g := gatewayAttributes { GatewayId: rxm.GatewayIds.GatewayId, Rssi: rxm.Rssi, Snr: rxm.Snr }
attributes.Gateways = append(attributes.Gateways, g) attributes.Gateways = append(attributes.Gateways, g)
} }
log.Printf("Attributes: %s", attributes) //log.Printf("Attributes: %s", attributes)
measurement.Attributes = map[string]interface{} { measurement.Attributes = map[string]interface{} {
"DeviceId": attributes.DeviceId, "DeviceId": attributes.DeviceId,
"ApplicationId": attributes.ApplicationId, "ApplicationId": attributes.ApplicationId,
@ -122,7 +122,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
"ConsumedAirtime": attributes.ConsumedAirtime, "ConsumedAirtime": attributes.ConsumedAirtime,
} }
log.Printf("ApplicationId: %s, DeviceId: %s", attributes.ApplicationId, attributes.DeviceId) //log.Printf("ApplicationId: %s, DeviceId: %s", attributes.ApplicationId, attributes.DeviceId)
device, err2 := self.dbh.GetDeviceByLabelAndApplication(attributes.ApplicationId, attributes.DeviceId) device, err2 := self.dbh.GetDeviceByLabelAndApplication(attributes.ApplicationId, attributes.DeviceId)
if err2 != nil { if err2 != nil {
self.Lost("Error when loading device", err2, message) self.Lost("Error when loading device", err2, message)
@ -132,7 +132,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
measurement.Device = attributes.DeviceId measurement.Device = attributes.DeviceId
measurement.Attributes["DeviceType"] = device.DeviceType.ModelIdentifier measurement.Attributes["DeviceType"] = device.DeviceType.ModelIdentifier
log.Printf("DeviceLabel: %s, DeviceType: %s", device.Label, device.DeviceType.ModelIdentifier) //log.Printf("DeviceLabel: %s, DeviceType: %s", device.Label, device.DeviceType.ModelIdentifier)
var parser func(int, []byte, string, *map[string]database.VariableType, *database.Device) error var parser func(int, []byte, string, *map[string]database.VariableType, *database.Device) error
switch device.DeviceType.ModelIdentifier { switch device.DeviceType.ModelIdentifier {
@ -161,7 +161,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
self.Lost("Model parser failed", err3, message) self.Lost("Model parser failed", err3, message)
return return
} }
log.Printf("Prepared measurement item: %s", measurement) //log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()
} }