Add debugging code for DB inserts.
All checks were successful
Build Docker image / build (push) Successful in 54s

This commit is contained in:
Pieter Hollander 2024-02-20 16:44:57 +01:00
parent 396b7d67b4
commit f6cefb4ca2
Signed by: pieter
SSH key fingerprint: SHA256:HbX+9cBXsop9SuvL+mELd29sK+7DehFfdVweFVDtMSg

27
main.go
View file

@ -180,7 +180,7 @@ func mqttMessageHandler(client mqtt.Client, msg mqtt.Message) {
}
// Parse timestamp to time.Time
timestamp, err := parseTimestamp(payload.T)
timestamp, err := parseDSMRTimestamp(payload.T)
if err != nil {
logger.Error("Error parsing timestamp", "error", err)
return
@ -216,12 +216,35 @@ func mqttMessageHandler(client mqtt.Client, msg mqtt.Message) {
}
// Insert data into PostgreSQL
err = insertData(timestamp, payload)
logger.Debug("Inserting values",
"t", payload.T,
"dt1", payload.Dt1,
"dt2", payload.Dt2,
"rt1", payload.Rt1,
"rt2", payload.Rt2,
"d", payload.D,
"r", payload.R,
"f", payload.F,
"fl", payload.Fl,
"g", payload.G,
"v1", payload.V1,
"v2", payload.V2,
"v3", payload.V3,
"c1", payload.C1,
"c2", payload.C2,
"c3", payload.C3,
"d1", payload.D1,
"d2", payload.D2,
"d3", payload.D3,
"r1", payload.R1,
"r2", payload.R2,
"r3", payload.R3)
if err != nil {
logger.Error("Error inserting data into PostgreSQL", "error", err)
}
}
func parseTimestamp(t string) (time.Time, error) {
func parseDSMRTimestamp(t string) (time.Time, error) {
// Extract values from timestamp string
year, month, day := 2000+int(t[0]-'0')*10+int(t[1]-'0'), time.Month(int(t[2]-'0')*10+int(t[3]-'0')), int(t[4]-'0')*10+int(t[5]-'0')