This short application note shows how to implement a smart IoT security switch using ACR-CV device.
This application can be implemented using ACR-CV-101L-I4-EAC-D. The “EAC-D” stands for battery backed variant.
With the default control Lua script, the device sends periodically each 15 minutes payload of a single byte, whose least significant bits (0,1,2,3) correspond respectively to S0 inputs, which are used as digital inputs with weak pull ups (inputs 1,2,3, and 4). The weak pull-ups are suitable for connection of external magnetic-contact. This message is sent on port 100 using acknowledged LoRaWAN uplink message. In case the message is not acknowledged, the transmission is repeated in 30 seconds. This message is also transmitted whenever the logic value / magnetic contact state changes and the periodic transmission restarts from this event. Once per 96 messages (in idle state corresponds to a period of once per day), the voltage value of the system is reported in mV to port 101. This message consists of two bytes, the first is the most significant byte of the voltage in mV and the seconds is the least significant byte.
The device is powered from AC mains rated 100-240VAC (50/60Hz) and backed with primary lithium battery (e.g. FANSO ER34615M + JST XH type). The device can operates from the AC mains source whenever the mains is up and available, when the mains is unavailable, operation continues without interruption from the internal primary lithium battery. The device can operate from the primary lithium battery up to 1 year in row. The life expectancy of the internal backup lithium battery to provide this service is 10 years. The battery state as well as the currently selected power can be deduced from reported system voltage. If the voltage value is greater than 3100mV, the external mains power supply is active. When the voltage value is approximately 3000mV, backup external battery power is active and the mains power source is down. When the battery becomes weak, the read out voltage value drops to approximately 2800mV.
function getInputStates() x1 = api.DIOreadPin(1) print("PIN 1: ".. tostring(x1)) x2 = api.DIOreadPin(2) print("PIN 2: ".. tostring(x2)) x3 = api.DIOreadPin(3) print("PIN 3: ".. tostring(x3)) x4 = api.DIOreadPin(4) print("PIN 4: ".. tostring(x4)) return string.char(x1+(2*x2)+(4*x3)+(8*x4)) end function onWake () print("Periodic wake up - send a ping, that we are alive") buf = getInputStates() api.dumpArray(buf) acked = api.loraSend(1, 6000, buf, 100) if acked > 0 then counter = api.getVar(1) counter = counter + 1 if counter > 96 then -- approx. once per day (96*15minutes) -- get battery voltage v = api.getBatteryVoltage() buf = string.char((v/256)%256) .. string.char(v%256) print("Battery voltage is: " .. tostring(v) .. "mV") if v > 3150 then print("Running on external power source") else print("Using backup battery power source") end api.dumpArray(buf) acked = api.loraSend(1, 6000, buf, 101) api.setVar(1,0) else api.setVar(1,counter) end end if acked > 0 then print("Ack received, next message in 15 minutes") api.setVar(2,1) api.wakeUpIn(0,0,15,0) else print("No ack! Send again in 30 seconds!") api.setVar(2,0) api.wakeUpIn(0,0,0,30) end end function onInputChanged (src) print("Event occured on pin "..tostring(src)) buf = getInputStates() api.dumpArray(buf) acked = api.loraSend(1, 6000, buf, 100) if acked > 0 then print("Ack received, next message in 15 minutes") api.setVar(2,1) api.wakeUpIn(0,0,15,0) else print("No ack! Send again in 30 seconds!") api.setVar(2,0) api.wakeUpIn(0,0,0,30) end end function onStartup() print("Starting up, set all inputs to rising/falling edge event source") api.DIOwaitForEvent(1,3) api.DIOwaitForEvent(2,3) api.DIOwaitForEvent(3,3) api.DIOwaitForEvent(4,3) api.setVar(1,0) end
The default Lua script corresponds to the description provided hereabove and can be adapted depending on customer needs using configuration cable or over a series of LoRaWAN downlink messages.
The payload is taken as a part of uplink message captured on Acrios System LoRa Network Server.