Event Reporting and SMS sample

Below sample allows to monitor the state of Digital input 1, and upon state change, send a SMS to predefined phone number.



local sms = require ‘sms’
local sched = require “sched”
local os = require “os”
local devicetree = require ‘devicetree’
– add the wished phone number below, international format, removing leading 0
local send_sms_to = ‘00336xxxxxxxx’
local in1 = ‘system.aleos.io.in1’


– function called upon IO state change
function when_dig_input_changes (din_data)
print("Digital input 1 state changed to: ", din_data[in1])
local sendmsg = 'ATM ID: 77123 | Location: Dubai Mall | Alert: Digital input 1 state changed to: ’ … din_data[in1]
print(‘Sending SMS message [’, sendmsg, '] to ', send_sms_to)
assert(sms.send(send_sms_to, sendmsg, ‘7bits’))
end


function main ()
print(“Starting EventReporting sample app”)
assert(sms.init())
assert(devicetree.init())

– Be notified, through a callback, every time a given variable changes.
– This is done through method:
– “devicetree.register (list_of_variables, callback, passive_vars)”
assert(devicetree.register(in1, when_dig_input_changes))
end

sched.run(main)
sched.loop()