Relay board R421A08
#1
Hello
I've done a short script for controlling cheap relay board from AliExpress Routerboard R421A08

If someone is interested in:
User library named ecl_modbus_rtu
Code:
local lt_modbus = {
 it_rboard_actions={
   close=0x100,
   open=0x200,
   toggle=0x300, -- close/open/close/open
   switch=0x400, -- switch 1 of 8
   impulse=0x0500, -- close one for 1s, open other relays
   close_delay=0x0600 --close, then open with delay[s] 00 - FF - (0x06[00-FF])
 },
 is_port='/dev/RS485-1',
 il_baudrate=9600,
    ecl_modbus_rtu_writeregister=function(self,ll_slave,ll_register,ll_value)
   -- ll_slave =RS485 RTU Number set at relay board DIPs
   -- ll_Register = relay Nr 1-8
   -- ll_value = it_rboard_actions
   require('luamodbus')
   mb = luamodbus.rtu()
   mb:open(self.is_port, self.il_baudrate, 'N', 8, 1, 'H')
   mb:connect()
   mb:setslave(ll_slave)
   mb:writeregisters(ll_register,ll_value)
   mb:close()
 end
}
return lt_modbus

Code for testing:
Code:
local mbus=require('user.ecl_modbus_rtu')
mbus:ecl_modbus_rtu_writeregister(1,4,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,5,mbus.it_rboard_actions.close)
mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.open)
LM5Lp, firmware: 20170620 lm5m3-20170620.img, FlashSYS2 20170612, ARMv7 Processor rev 5 (v7l), kernel 4.4.73




Reply
#2
Thank you.
I have been trying to communicate with tha same relayboard with no luck.
I will give this a try. Cool
Reply


Forum Jump: