



local indication = require("indication")
local settings_get = Settings.get
local settings_set = Settings.set
local mb_setregs8 = modbus.setregs8
local mb_getvalues = modbus.getregsvalues
local sleepms = thread.sleepms
local leds = indication.Leds.new({ RGB = true, ledPin = pio.GPIO32 })
local snd = indication.Sound.new(pio.GPIO21)
local wdt_on = settings_get("sys_wdt") == "on"
local lock_pin = pio.GPIO16
pio.pin.setdir(pio.OUTPUT, lock_pin)
local function lock() pio.pin.setval(1, lock_pin) end
local function unlock() pio.pin.setval(0, lock_pin) end
lock()
modbus.rtu.init(settings_get("rs485_addr"))
local web_start = (function()
local web_started = false
local web_code = tonumber(string.sub(cpu.getmac(0, 1), -4), 16)
return function(num)
if web_started or num ~= web_code then return end
net.wf.setup(
net.wf.mode.AP,
settings_get("net_ssid"),
settings_get("net_password"),
net.wf.powersave.NONE,
4,
false
)
net.wf.start()
pcall(dofile, "/romfs/backend.lua")
net.service.tinyweb.start(80, "/romfs/www", nil, nil, "backend", backendcb)
web_started = true
collectgarbage("collect")
end
end)()
if cpu.resetreason() == cpu.RESET_POWERON then
leds:start()
snd:start()
end
local leds_ok, leds_err = leds.ok, leds.err
local snd_ok, snd_err = snd.ok, snd.err
local mfrc_scan = mfrc522.scan
local em_uid = emmarine.uid
local em_reader = emmarine.new()
local scan_mfrc = true
while true do
if wdt_on then cpu.watchdog.reset() end
if scan_mfrc then
-- byte-mode callback: modbus.setregs8(0, uid_byte1, uid_byte2, ...)
mfrc_scan(mb_setregs8, 0)
else
-- byte-mode callback: modbus.setregs8(4, uid_byte1, ..., uid_byte5)
em_uid(em_reader, mb_setregs8, 4)
end
scan_mfrc = not scan_mfrc
local action, web_pwd, new_addr = mb_getvalues(0xf0, 3, true)
if action == 1 then
unlock()
leds_ok(leds)
snd_ok(snd)
elseif action == 2 then
lock()
leds_err(leds)
snd_err(snd)
elseif action == 3 then
lock()
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", tostring(new_addr & 0xff))
os.exit()
end
sleepms(20)
end Актуальные прошивки можно скачать по ссылке