221
17.2. Send SMS messages to specific SIM numbers after group-read or group-
write is triggered
Task: Assume we have an Event-based script which triggers a program once group-read or
group-write is triggered for address 1/1/1. We want to send SMS to numbers 23335555 and
23335556 with 1/1/1 actual status.
1.
require('socket')
2.
3.
client
=
socket.udp
()
4.
5.
-- in the message field the number where SMS has to be send should be specified at the
beginning
6.
local
msg
='23335555 1/1/1 changes its value to: '
..
tonumber(
event.datahex
)
7.
client:sendto
(
msg,
'127.0.0.1'
,
12535)
8.
9.
msg
='23335556 1/1/1 changes its value to: '
..
tonumber(
event.datahex
)
10.
client:sendto
(
msg,
'127.0.0.1'
,
12535)
17.3. Send SMS messages without 3G modem
How to send event SMS to mobile phone from LogicMachine through Twilio service, without
external 3G adapter?
You can use Twilio service which offers free of charge SMS in the test period and messaging at
$0.01 for regular usage. The only disadvantage is it will use your standard Internet connection
to send messages to Twilio servers (not via GSM as with 3G adapters).
Twilio account
You can get ID and Token needed for the below example by registering on Twilio. Make sure
you enter a verified SIM number list / recipients in your account. Or please contact us for ready
example with our account data.
Function
Add the following function in Scripting > Common functions
1.
function sms(id, token, from, to, body)
2.
local escape = require('socket.url').escape
3.
local request = require('ssl.https').request
4.
local url = string.format('https://%s:%s@api.twilio.com/2010-04-
01/Accounts/%s/Messages.json', id, token, id)
5.
local body = string.format('From=%s&To=%s&Body=%s', escape(from),
escape(to), escape(body))
6.
7.
return request(url, body)