Event Reporting and Email sample

Below sample allows to monitor the state of Digital input 1, and upon state change, send an Email to predefined email address.

Note that you will need a SMTP account to be able to send the mail.
You can subscribe to free SMTP test account under jangosmtp.com/default.asp



local sched = require “sched”
local os = require “os”
local devicetree = require ‘devicetree’
local smtp = require ‘socket.smtp’

local from_email = “AAF_script_LS@sierrasupport.com
local email_rcpt = {
“”,
}

local in1 = ‘system.aleos.io.in1’


function when_dig_input_changes (din_data)
print("Digital input 1 state changed to: ", din_data[in1])

local mesgt = {
        headers = {
              to = "name surname <destination email address>",
              --cc = '"name surname " < copy email address>',
              subject = "Alert: Digital input 1 state changed to:" .. din_data[in1]
                         },
                    body = "this is the body of my email"
                    }

print (‘Sending email message’)
local r, e = smtp.send{
from = from_email,
rcpt = email_rcpt,
user = “xxxxx”,
password = “xxxxxx”,
server = “relay.jangosmtp.net”,
port = 25,
source = smtp.message(mesgt)
}
print®
print(e)
end


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

-- subscirbe to IO1 digital input. 
-- Function "when_dig_input_changes" will be executed upon every state change. 
assert(devicetree.register(in1, when_dig_input_changes))

end


– execute in loop
sched.run(main)
sched.loop()

When I try to use this code to send an email, I get an error stating,

"
Sending email message
nil
/root/aleos/usr/readyagent/lua/socket/smtp.lua:115: host not found
"

In my project libraries I do not see the socket.smtp that is referenced in the code above. Where can I get the proper Aaf file? (I have Aaf 4.3.4)

Well the error indicate that the host was not found. You may have lost the connectivity on your device, or have a host down, etc.

socket.smtp is part of the AAF framework (which is why you do not have it in your sources). The file is embedded in the ALEOS firmware under /usr/readyagent/lua/. You can also get a copy there: w3.impa.br/~diego/software/luaso … l#download, we are using 2.02 version.