I've optimized communication with this meter and now script is trying max 7 times read the register. Min. time to read all registers(or spending 7 times to try) i 7s and maximum 16s. Today I will try contact with the manufacturer.
Code:
require('json')
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
timeout = 0.05
mb:setresponsetimeout(timeout)
mb:setslave(4)
energyMeters = [[
{
"manufacturer": "F&F",
"description": "Licznik energii LE-03MQ",
"mapping": [
{ "address": 0, "name": "Napięcie fazowe L1", "delta": 2 },
{ "address": 2, "name": "Napięcie fazowe L2", "delta": 2 },
{ "address": 4, "name": "Napięcie fazowe L3", "delta": 2 },
{ "address": 6, "name": "Natężenie prądu L1", "delta": 0.5 },
{ "address": 8, "name": "Natężenie prądu L2", "delta": 0.5 },
{ "address": 10, "name": "Natężenie prądu L3", "delta": 0.5 },
{ "address": 12, "name": "Moc czynna L1", "delta": 50 },
{ "address": 14, "name": "Moc czynna L2", "delta": 50 },
{ "address": 16, "name": "Moc czynna L3", "delta": 20 },
{ "address": 24, "name": "Moc bierna L1", "delta": 50 },
{ "address": 26, "name": "Moc bierna L2", "delta": 50 },
{ "address": 28, "name": "Moc bierna L3", "delta": 50 },
{ "address": 30, "name": "Współczynnik mocy L1", "delta": 0.01 },
{ "address": 32, "name": "Współczynnik mocy L2", "delta": 0.01 },
{ "address": 34, "name": "Współczynnik mocy L3", "delta": 0.01 },
{ "address": 52, "name": "Całkowita moc układu", "delta": 50 },
{ "address": 60, "name": "Całkowita moc bierna układu", "delta": 50 },
{ "address": 62, "name": "Współczynnik mocy układu", "delta": 0.01 },
{ "address": 70, "name": "Częstotliwość napięć zasilania", "delta": 0.25 },
{ "address": 200, "name": "Napięcie międzyfazowe L1-L2", "delta": 2 },
{ "address": 202, "name": "Napięcie międzyfazowe L2-L3", "delta": 2 },
{ "address": 204, "name": "Napięcie międzyfazowe L3-L1", "delta": 2 },
{ "address": 224, "name": "Prąd przewodu zerowego", "delta": 1 },
{ "address": 234, "name": "Współczynnik zawartości harmonicznych napięcia L1-N", "delta": 1 },
{ "address": 236, "name": "Współczynnik zawartości harmonicznych napięcia L2-N", "delta": 1 },
{ "address": 238, "name": "Współczynnik zawartości harmonicznych napięcia L3-N", "delta": 1 },
{ "address": 240, "name": "Harmoniczne prądu fazy 1", "delta": 1 },
{ "address": 242, "name": "Harmoniczne prądu fazy 2", "delta": 1 },
{ "address": 244, "name": "Harmoniczne prądu fazy 3", "delta": 1 },
{ "address": 334, "name": "Harmoniczna napięcia międzyfazowego L1-L2", "delta": 1 },
{ "address": 336, "name": "Harmoniczna napięcia międzyfazowego L2-L3", "delta": 1 },
{ "address": 338, "name": "Harmoniczna napięcia międzyfazowego L3-L1", "delta": 1 },
{ "address": 342, "name": "Całkowita energia czynna", "delta": 0.1 },
{ "address": 344, "name": "Całkowita energia bierna", "delta": 1 }
]
}]]
energyMeters = json.decode(energyMeters)
meterName = 'Licznik 1 - '
function readRegister(meterName, address, name, delta)
for i = 1, 7, 1 do
res, err = mb:readinputregistervalue(address, "float32", "w")
if res then
GA = meterName .. name
value = math.round(res, 2)
grp.checkwrite(GA, value, delta)
break
end
end
end
for k,meter in pairs(energyMeters.mapping) do
readRegister(meterName, meter.address, meter.name, meter.delta)
end
mb:close()