Telestax Blog

How to setup from scratch an IoT device under $100 that sends SMS to users

In a recent demo for the VoIP User Conference, John Senay showed an Electric Imp smart device that connects via WiFi to the Internet and sends programmable event triggers to an associated agent in the cloud to RestcommONE. The cloud hosted agent for the device is then scripted to execute further intelligent tasks.

The IMP device costs under $100 and is a prime representative of a new generation of affordable IoT devices that are taking over the world faster than Big Data is. IoT devices can be now seen in flying self made drones, home appliances, cars, health monitoring gadgets and even clothes.

UPDATE: The founder and CEO of Electric Imp – Hugo Fiennes clarified in a Linked In discussion that at scale (10,000 units) the cost per device would be under $15 and by next year it would be under $10.

In this blog post we will walk through the steps of John’s demo. After reading the article you will be able to build your own IoT device and program it to communicate intelligently with humans.

IoT growth chart IoT growth trend

The IMP has a total of eleven pins, with six pins available for GPIO, to provide I2C, SPI and UART signaling.  John Senay showed the actual IDE with its three parts, one frame showed the code run on the IMP card, one frame showed the code for the agent, running in the Electric Cloud and one frame showing the live device log.

Use case:

  • Electric Imp device is connected to a local Wi-Fi network
  • The Imp observes a state change on the switch ( On or Off )
  • The Imp sends a command to the Agent in the Electric Cloud
  • The agent sends a RESTful command  to a RestcommONE instance on the Amazon Web Service Cloud
  • RestcommONE sends an SMS to specified phone number


Technical skills required:

  • Knowledge of RestcommONE
  • Knowledge of JavaScript
  • Basic electrical engineering knowledge

IoT parts needed:

Step 1 – Setting up the Hardware

  • To get started with the Electric Imp please follow the User Guide and Getting started docs HERE
  • Now let’s build the smart button gadget by following the steps HERE
  • See the complete wired setup on the image below:


Step 2 – Creating RVD application

  • Go to RestcommONE Admin UI
  • Create Voice Application and bound it to registered DID
  • Drag and drop SMS. Enter the message you want RestcommONE to send to a specified number in the text are. In our case we will type: “Hello from my agent!, the Cat is out the door!!”.
  • In “To” section specify the phone number to which SMS will be sent
  • In “From” type the DID that is already bound to the application. We are using “12025520044”.
  • Once you are done Save the application



Step 3 – Setting up the Electric Imp Device

  • First we need to setup the example code
  • You are now ready to start writing code for your imp.
  • Once your imp is connected to your WiFi, go to the IDE page
  • Commission your imp as described by the imp team.
    You will notice that the Electric Imp IDE has 3 collapsible windows: Agent, Device, and Logs. Logs provides all the collected and printed information from your device and code, this is an invaluable debugging tool. Agent and Device are where we will be putting our code. The Agent is the server side code, this code runs on Electric Imp’s servers and allows you to execute heavier tasks including HTTP requests. The Device code is the code runs on the physical imp card, an ARM M3 microcontroller, that will be inserted into your device. Electric Imp has created an easy way to pass messages from the device to the agent and vice versa. First we will focus on the Agent code since this is where we will do the communication with Restcomm.
  • Copy the code below into your agent tab in the Electric Imp
const REST_SID = "ACCOUNT_ID";    // Your Restcomm Account SID
const REST_AUTH = "AUTH_TOKEN";    // Your Restcomm Auth Token
const REST_NUM = "15125555555";    // Your Restcomm Phone Number

class Restcomm {
    _baseUrl = "http://SERVER IP ADDRESS:8080/restcomm/2012-04-24/Accounts/";
    _accountSid = null;
    _authToken = null;
    _phoneNumber = null;

    constructor(accountSid, authToken, phoneNumber) {
        _accountSid = accountSid;
        _authToken = authToken;
        _phoneNumber = phoneNumber;

    function send(to, message, callback = null) {
        local url = _baseUrl + _accountSid + "/SMS/Messages"
        local auth = http.base64encode(_accountSid + ":" + _authToken);
        local headers = { "Authorization": "Basic " + auth };
        local body = http.urlencode({
            From = _phoneNumber,
            To = to,
            Body = message

    local request =, headers, body);
    if (callback == null)
        return request.sendsync();

    function Respond(resp, message) {
        local data = { Response = { Message = message } };
        local body = xmlEncode(data);
        resp.header("Content-Type", "text/xml");
        resp.send(200, body);

    function xmlEncode(data, version="1.0", encoding="UTF-8") {
        return format("<?xml version="%s" encoding="%s" ?>%s", version, encoding, _recursiveEncode(data))

    /******************** Private Function (DO NOT CALL) ********************/
    function _recursiveEncode(data) {
        local s = "";
        foreach(k, v in data) {
            if (typeof(v) == "table" || typeof(v) == "array") {
                s += format("<%s>%s</%s>", k.tostring(), _recursiveEncode(v), k.tostring());
            } else {
                s += format("<%s>%s</%s>", k.tostring(), v.tostring(), k.tostring());;
        return s

//restcomm <- Restcomm(REST_SID, REST_AUTH, REST_NUM);
// sending a message
//numberToSendTo <- "15125555555"
//restcomm.send(numberToSendTo, "Hello from my agent!, the Cat is out the door!!", function(resp) { server.log(resp.statuscode + " - " + resp.body); });
// processing messages
    function(req, resp) {
        local path = req.path.tolower();
        if (path == "/restcomm" || path == "/restcomm/") {
            // restcomm request handler
            try {
                local data = http.urldecode(req.body);
                restcomm.Respond(resp, "You just said '" + data.Body + "'");
            } catch(ex) {
                local message = "Uh oh, something went horribly wrong: " + ex;
                restcomm.Respond(resp, message);
        } else {
            // default request handler
            resp.send(200, "OK");

function button_pressed(status) {
    server.log("button pressed, sending SMS");
    restcomm <- Restcomm(REST_SID, REST_AUTH, REST_NUM);
    // sending a message
    numberToSendTo <- "15125555555"
    restcomm.send(numberToSendTo, "Hello from my agent!, the Cat is out the door!!", function(resp) { server.log(resp.statuscode + " - " + resp.body); });

device.on("button_pressed", button_pressed);


  • Once copied, change where it says FEED_ID_HERE and API_KEY_HERE to your respective Restcomm Acoount  SID and Restcomm Auth Token that you can get from Restcomm Admin UI.
  • Next it is time to setup our device code. This code may need to vary depending on the type of UART device you are trying to interface with. The basic setup provided will work with and FTDI cable or Arduino microcontroller.


// Alias the GPIO pin as 'button'

button <- hardware.pin1;

function buttonPress()
    local state =;
    if (state == 1)
        // The button is released

    } else
        // The button is pressed

        agent.send("button_pressed", "");

// Configure the button to call buttonPress() when the pin's state changes

button.configure(DIGITAL_IN_PULLUP, buttonPress);


You are now ready to test the device and receive SMS from Restcomm whenever there is a state change.

For more information:

Contact Telestax for help with your IoT and Restcomm projects.


Get awesome content in your inbox every week.

Give it a try. It only takes a click to unsubscribe.