From 66eb88d80ad4a0207273bd61bacb4c5996e8305a Mon Sep 17 00:00:00 2001 From: Brian Rochford Date: Mon, 27 Feb 2023 13:31:12 +0000 Subject: [PATCH 1/2] Adding more sensors --- .gitignore | 3 ++- adapters/devices/sofar/lsw.go | 8 +++++-- adapters/devices/sofar/sofar_protocol.go | 29 ++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d28f9ce..4c8c71c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ sofar_g3_lsw3_logger_reader config.yaml sofar -sofar-arm \ No newline at end of file +sofar-arm +.idea \ No newline at end of file diff --git a/adapters/devices/sofar/lsw.go b/adapters/devices/sofar/lsw.go index 219a5eb..9067acc 100644 --- a/adapters/devices/sofar/lsw.go +++ b/adapters/devices/sofar/lsw.go @@ -94,7 +94,7 @@ func readData(connPort ports.CommunicationPort, serialNumber uint) (map[string]i result[k] = v } - reply, err = readRegisterRange(rrPVGeneration, connPort, serialNumber) + reply, err = readRegisterRange(rrEnergyTodayTotals, connPort, serialNumber) if err != nil { return nil, err } @@ -121,7 +121,11 @@ func readData(connPort ports.CommunicationPort, serialNumber uint) (map[string]i result[k] = v } - reply, err = readRegisterRange(rrBatCharge, connPort, serialNumber) + for k, v := range reply { + result[k] = v + } + + reply, err = readRegisterRange(rrRatio, connPort, serialNumber) if err != nil { return nil, err } diff --git a/adapters/devices/sofar/sofar_protocol.go b/adapters/devices/sofar/sofar_protocol.go index 81b498e..471d110 100644 --- a/adapters/devices/sofar/sofar_protocol.go +++ b/adapters/devices/sofar/sofar_protocol.go @@ -75,19 +75,18 @@ var rrSystemInfo = registerRange{ {0x043A, "Fault27", "U16", "", ""}, }, } -var rrPVGeneration = registerRange{ +var rrEnergyTodayTotals = registerRange{ start: 0x680, - end: 0x687, + end: 0x69B, replyFields: []field{ {0x684, "PV_Generation_Today", "U32", "0.01", "kWh"}, {0x686, "PV_Generation_Total", "U32", "0.1", "kWh"}, - }, -} - -var rrBatCharge = registerRange{ - start: 0x680, - end: 0x69B, - replyFields: []field{ + {0x688, "Load_Consumption_Today", "U32", "0.1", "kWh"}, + {0x68A, "Load_Consumption_Total", "U32", "0.1", "kWh"}, + {0x68C, "Energy_Purchase_Today", "U32", "0.1", "kWh"}, + {0x68E, "Energy_Purchase_Total", "U32", "0.1", "kWh"}, + {0x690, "Energy_Selling_Today", "U32", "0.1", "kWh"}, + {0x692, "Energy_Selling_Total", "U32", "0.1", "kWh"}, {0x694, "Bat_Charge_Today", "U32", "0.01", "kWh"}, {0x696, "Bat_Charge_Total", "U32", "0.1", "kWh"}, {0x698, "Bat_Discharge_Today", "U32", "0.01", "kWh"}, @@ -191,3 +190,15 @@ var rrBatOutput = registerRange{ {0x0611, "ChargeCycle_Bat2", "U16", "1", ""}, }, } + +var rrRatio = registerRange{ + start: 0x1030, + end: 0x103D, + replyFields: []field{ + {0x1039, "PV_Generation_Ratio", "U16", "0.001", ""}, + {0x103A, "Energy_Purchase_Ratio", "U16", "0.001", ""}, + {0x103B, "Energy_Selling_Ratio", "U16", "0.001", ""}, + {0x103C, "Bat_Charge_Ratio", "U16", "0.001", ""}, + {0x103D, "Bat_Discharge_Ratio", "U16", "0.001", ""}, + }, +} From b755c577a5425d940b182ba8c7c8c6e6f2240aea Mon Sep 17 00:00:00 2001 From: Brian Rochford Date: Mon, 27 Feb 2023 13:46:56 +0000 Subject: [PATCH 2/2] Correcting duplicate value setting --- adapters/devices/sofar/lsw.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/adapters/devices/sofar/lsw.go b/adapters/devices/sofar/lsw.go index 9067acc..804925a 100644 --- a/adapters/devices/sofar/lsw.go +++ b/adapters/devices/sofar/lsw.go @@ -121,10 +121,6 @@ func readData(connPort ports.CommunicationPort, serialNumber uint) (map[string]i result[k] = v } - for k, v := range reply { - result[k] = v - } - reply, err = readRegisterRange(rrRatio, connPort, serialNumber) if err != nil { return nil, err