From 2844bd89d12cf17f62844ba68581ec6e57ba835c Mon Sep 17 00:00:00 2001 From: Pieter Hollander Date: Sun, 18 Feb 2024 15:10:37 +0100 Subject: [PATCH] Added documentation to Payload struct. --- main.go | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index 379ac62..9c153be 100644 --- a/main.go +++ b/main.go @@ -13,29 +13,33 @@ import ( _ "github.com/lib/pq" ) +// Payload struct +// Dt1, Dt2, Rt1, Rt2 and G are meter readings +// By making them pointers to int, they can be set to 'nil' when the reading has not changed. +// This way, they are logged as NULL in the database when no change has happened, saving storage capacity. type Payload struct { - T string `json:"t"` - Dt1 *int `json:"dt1"` - Dt2 *int `json:"dt2"` - Rt1 *int `json:"rt1"` - Rt2 *int `json:"rt2"` - D int `json:"d"` - R int `json:"r"` - F int `json:"f"` - Fl int `json:"fl"` - G *int `json:"g"` - V1 int `json:"v1"` - V2 int `json:"v2"` - V3 int `json:"v3"` - C1 int `json:"c1"` - C2 int `json:"c2"` - C3 int `json:"c3"` - D1 int `json:"d1"` - D2 int `json:"d2"` - D3 int `json:"d3"` - R1 int `json:"r1"` - R2 int `json:"r2"` - R3 int `json:"r3"` + T string `json:"t"` // Timestamp + Dt1 *int `json:"dt1"` // Delivered / imported meter reading tariff 1 (kWh) + Dt2 *int `json:"dt2"` // Delivered / imported tariff 2 (kWh) + Rt1 *int `json:"rt1"` // Returned / exported tariff 1 (kWh) + Rt2 *int `json:"rt2"` // Returned / exported tariff 2 (kWh) + D int `json:"d"` // Delivering / importing (W) + R int `json:"r"` // Returning / exporting (W) + F int `json:"f"` // Failure (counter) + Fl int `json:"fl"` // Failure long duration (counter) + G *int `json:"g"` // Gas meter reading (l) + V1 int `json:"v1"` // Voltage L1 (V) + V2 int `json:"v2"` // Voltage L2 (V) + V3 int `json:"v3"` // Voltage L3 (V) + C1 int `json:"c1"` // Current L1 (A) + C2 int `json:"c2"` // Current L2 (A) + C3 int `json:"c3"` // Current L3 (A) + D1 int `json:"d1"` // Delivering / importing L1 (W) + D2 int `json:"d2"` // Delivering / importing L2 (W) + D3 int `json:"d3"` // Delivering / importing L3 (W) + R1 int `json:"r1"` // Returning / exporting L1 (W) + R2 int `json:"r2"` // Returning / exporting L2 (W) + R3 int `json:"r3"` // Returning / exporting L3 (W) } var db *sql.DB