Integrate SMS Alarms into Ignition (Part 1 of 2)
Introduction
This is a two part blog series walking through the steps to bring an sms alarm into Ignition and trigger an alarm. Part 1 (this post) will walk through the steps to get the incoming SMS into a broker using Twilio. Part 2 will walk through the steps to configure Ignition to read the message and trigger an alarm.
Steps
Prerequisites
- Create a Twilio account
- Create a virtual phone number
Create and Deploy a Function
- Go to Twilio Console
- Create a Service, fill name field, and click Next
- When redirected to the new Service, click the Add + button and select Add Function from the dropdown and update function name
- Click Dependencies to import mqtt npm module, fill in the fields and click Add (see image)
- Navigate to function and update script, click Save, then click Deploy All. Console will update when the process is complete. Below the screenshot is a sample script that takes the body of the incoming SMS message and publishes it to the HiveMQ Public Broker
mqtt://broker.hivemq.com
Sample Script
const mqtt = require('mqtt');
exports.handler = (context, event, callback) => {
const incomingMessage = event.Body;
const client = mqtt.connect('mqtt://broker.hivemq.com');
client.on('connect', function () {
console.log('Connected')
// Publish a message to a topic
client.publish('sms2mqtt/messages', incomingMessage);
return callback();
})
console.log(incomingMessage);
};
Set a Function as a webhook
Source: Set a Function as a webhook
- Twilio Console’s Phone Numbers page
- Click on the phone number you’d like to have connected to your Function
- Navigate to A Message Comes In option under Messaging
- Select Function from the A Message Comes In
- Select the Service that you are using, then the Environment (this will default to ui unless you have created custom domains), and finally Function Path of your Function from the respective dropdown menus
Testing using HiveMQ Websocket Client
- Navigate to HiveMQ Websocket Client
- Fill in the Host and Port settings then click Connect. I am using
broker.hivemq.com
and8884
for testing purposes only. - Click Add New Topic Subscription
- Add the same topic (
sms2mqtt/messages/#
) that is used in the Twilio Function and clik Subscribe - Send a test text message to the Twilio Phone Number
- Monitor the Web Client and you should see a message come in for the subscribed topic
Resources
Comments
Feel free to comment, provide constructive feedback, or report an error/typo in the post.
All comments can be accessed via the issues page.