



indication = require("indication")
leds = indication.Leds.new({RGB=true, ledPin=pio.GPIO32})
snd = indication.Sound.new(pio.GPIO21)
wdt_on = Settings.get("sys_wdt") == "on"
pio.pin.setdir(pio.OUTPUT, pio.GPIO2) -- Замок
lock = function() pio.pin.setval(1, pio.GPIO2) end;
unlock = function() pio.pin.setval(0, pio.GPIO2) end;
lock()
modbus.rtu.init(Settings.get("rs485_addr"))
-- функция запуска wifi-интерфейса по modbus-команде
local web_start = (function()
local web_started = false
local sn = cpu.getmac(0, 1)
return function(num)
if web_started then return end
if string.sub(sn, -4) == string.format("%02X", num) then
net.wf.setup(net.wf.mode.AP, Settings.get("net_ssid"), Settings.get("net_password"), net.wf.powersave.NONE, 4, false)
net.wf.start()
web_started = true
end
end
end)()
if cpu.resetreason() == cpu.RESET_POWERON then
leds:start()
snd:start()
end
-- главный цикл
local uid, ret, action, web_pwd, new_addr
while true do
if wdt_on then cpu.watchdog.reset() end
uid = mfrc522.scan(7)
if uid then
modbus.setregs8(0, uid)
end
ret = modbus.getregs(0xf0, 3, true)
action, web_pwd, new_addr = ret[1], ret[2], ret[3]
if action == 1 then -- разрешено
unlock()
leds:ok()
snd:ok()
elseif action == 2 then -- запрещено
lock()
leds:err()
snd:err()
elseif action == 3 then -- закрыть замок (после прохода)
unlock()
end
if web_pwd and web_pwd ~= 0 then
web_start(web_pwd)
end
if new_addr and new_addr ~= 0 then
Settings.set("rs485_addr", string.format("%d", new_addr & 0xff))
os.exit()
end
thread.sleepms(200)
end Актуальные прошивки можно скачать по ссылке