![]() |
|
troubleshooting modbus script to control fornius inverter - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: troubleshooting modbus script to control fornius inverter (/showthread.php?tid=5351) |
troubleshooting modbus script to control fornius inverter - cgn - 09.04.2024 Hello, due to dynamic energy prices I wan't to enable / disable throttle of the inverter. This is possbile via modbus. Unfortunatelly it's not working and I have nothing in the log of LM. Code: require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.1.111', 502)
mb:connect()
res, err = mb:connect()
if res then
if (value <35) then
r0 = mb:writeregisters(40236, 0)
log(r0, '<')
else
r1 = mb:writeregisters(40236, 0)
r2 = mb:writeregisters(40232, 10000)
r3 = mb:writeregisters(40236, 1)
log(r1, r2, r3 '>')
mb:close()
end
else
log('failed', err)
endLog if value <35 * arg: 1 * nil * arg: 2 * string: < => This seems to work Log if value >35 Nothing in the log and I don't know why. Any idea what could be wrong? RE: troubleshooting modbus script to control fornius inverter - admin - 10.04.2024 You have two connect calls, remove one of them. Then log the error returned by the write call: Code: r0, err = mb:writeregisters(40236, 0)
log(r0, err)Same for all other registers. RE: troubleshooting modbus script to control fornius inverter - cgn - 15.04.2024 Thanks, that was an error as well. If someone what's to set the softlimit from a fronius inverter depending on the enery prices, this is the clean code: Code: t = os.date ("*t")
value = grp.getvalue('34/1/' .. t.hour)
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.1.111', 502)
res, err = mb:connect()
mb:setslave(1)
if res then
if (value <35) then
mb:writeregisters(40236, 0)
log('PV softlimit')
else
mb:writeregisters(40236, 0)
mb:writeregisters(40232, 10000)
mb:writeregisters(40236, 1)
log('PV unlimited')
end
mb:close()
else
log('failed', err)
end |