Build M2M applications with HTTP

Many of the most interesting IoT applications involve multiple local devices communicating with an internet-connected gateway. Temboo can generate code for complete multi-device application scenarios, in which edge devices use a common IoT communications protocol to send Temboo requests through a gateway. The gateway handles all communication with Temboo, thereby enabling local edge devices to indirectly interact with the huge range of web-based resources supported by Temboo.

In this tutorial we discuss how to use Temboo to set up a multi-device application that uses HTTP, but we also support for MQTT and CoAP. This tutorial is based on an industrial manufacturing IoT scenario, in which edge devices powering motors trigger alerts if they sense foreign objects or unwanted vibration. Our gateway is also watching for suboptimal production line conditions, and sending alerts as necessary. You can see the whole thing in action in the video below (the video uses MQTT as opposed to HTTP).

The video and this tutorial illustrate how to use a range of popular services for handling text messaging, alerting on-call staff and filing customer support tickets, triggered from multiple devices. However, you can easily swap out any of those services based on the requirements of your particular application. For example, you could switch all alerts to email, or to any of the 2000+ processes in our Library.

Let's Get Started

The first thing we'll do is get set up with the third-party services used in the video. If you don't want to recreate our Industrial IoT application, but want to learn how to use Temboo to generate M2M code for a different application scenario, you can skip to the next section to get started setting up your gateway device.

1Before you get started, you'll need a Temboo account. If you don't already have one, you can sign up for free now.

2If our gateway device senses that our fabrication platform is off-balance, it will trigger SMS alerts via Twilio's telephony API. You can create a free Twilio account here.

3When you register with Twilio, you'll be given a Twilio phone number, along with the Account SID and Auth Token. Make sure to use the Account SID and Auth Token from your Twilio Dashboard, shown below, as opposed to the test credentials from the Dev Tools panel.

The Twilio dashboard, where you can retrieve your Auth Token and Account SID for building a HTTP gateway application

A Twilio Account SID and Auth Token in the Twilio dashboard

4You'll also need a PagerDuty account, which one of our edges will use to send alerts when it senses the presence of foreign objects. You can create a PagerDuty account here.

5Once you've created your PagerDuty account, retrieve your PagerDuty API key from the Configuration > Services menu - you'll need it later in this tutorial.

The API settings menu on the PagerDuty dashboard, where you can retrieve the API key needed to build a HTTP gateway application

The API Settings menu on the PagerDuty dashboard

6Finally, you'll need an account with Zendesk, so that one of our edges can send service requests to its manufacturer when it senses unwanted vibrations. You can create a Zendesk account on their registration page.

Configure Your HTTP Gateway

Now that you have the various accounts set up, you're ready to start building your application. We'll begin by setting up the Gateway device.

1Since our HTTP gateway device is going to be responsible for monitoring platform alignment and sending alerts via SMS, we'll start over on the Twilio > SMSMessages > SendSMS Choreo page.

2If it's not on already, turn IoT Mode on the top right of the page and make sure that you've selected a device that is capable of acting as a gateway. In this example we're using a Samsung ARTIK 10 with HTTP as our protocol.


Selecting the HTTP protocol from the Gateway dropdown

3Next, enter the details of your HTTP gateway device.

Enter and save HTTP gateway settings

Entering HTTP gateway device settings

4With your gateway device configured, populate the Twilio Choreo form with all of the details that we need to send our SMS message, using the Twilio account that we set up earlier. You can find example inputs at the bottom of the Choreo page, and you can test it out by hitting the Run button, which will trigger the SMS message directly from our website.

5We only want to trigger the SMS message if our gateway device senses significant misalignment, so we'll use a Condition to specify when the SendSMS Choreo should be run. You can adjust your condition threshold based on the values that make sense for your sensor.

Set a condition to trigger a process based on a HTTP gateway device sensor value

Setting a Condition to trigger a Choreo based on sensor value changes

6Now, scroll down to the CODE section of the Choreo and you'll find the auto-generated code for your Samsung ARTIK gateway device. Now we're ready to move on and set up our edge devices.

Auto-generated HTTP gateway device code

Auto-generated HTTP gateway device code

7Optional: In the video, we show how the gateway device can be remotely controlled via SMS. To do this, you can generate code using the Twilio > SMSMessages > GetLastMessageFromNumber Choreo. The message reading functionality can be incorporated after the SendSMS Choreo has been run. The results can be used to change the pin state.

Set Up Your Edge Devices

Now that we've configured our gateway and generated code so that it will monitor and react to changes in fabrication platform alignment, we can set up our edge devices to monitor the individual machines.

1First, add a new edge device by clicking on the +Edge tab.

Add a new HTTP edge device

Adding a new edge device

2Next, select your edge device type and how it is connected to the HTTP gateway. We're going to use a Texas Instruments LaunchPad connected via Wifi.

Select a HTTP edge device type and connectivity

Configuring the edge device type and connectivity

3Now, we're going to pick the Choreo that this edge device will run via the HTTP gateway. We want this edge device to notify a maintenance team if an obstruction is detected, so we'll use the PagerDuty > Events > TriggerEvent Choreo.

Select an edge device Choreo to call on the M2M Gateway via HTTP

Selecting a Choreo for the edge device to call via the gateway

4With our Choreo selected, we'll set up a Condition so that the PagerDuty alert is only trigged when an obstruction is detected. We'll use the same approach that we used when setting up the Condition for the gateway device earlier.

Set a condition on the edge device to call a Choreo on the M2M gateway via HTTP

Setting a condition on the edge device Choreo

5Next, using the same technique, we'll add another edge device and configure it to call the Zendesk > Tickets > CreateTicket Choreo. We'll be using an Arduino Mega to send alerts to the manufacturer of the machine that is being monitored. In our example, we're watching out for unwanted vibration patterns, but you should set a condition that's relevant for your particular hardware setup. Using this technique, you can add many edge devices to perform different physical and web-based operations relevant to your application.

Set up a second edge device to communicate with the M2M gateway via HTTP

Setting up a second edge device

6Scroll down to the CODE section on both edge devices, and you'll find that the relevant code has been generated for your Texas Instruments LaunchPad and an Arduino Mega. This means that we're ready to take our generated code for all devices, start the gateway, and run the application.

Run The Application

Now that you've generated code for you gateway and edge devices, you're ready to deploy the code and test out your M2M application. We'll start by running the HTTP gateway, then starting up the gateway and edge device Choreo programs.

1Make sure that you have the latest Temboo image or package for your gateway device - this will ensure that you have the necessary Temboo MQTT gateway libraries on your device. You can find Samsung's ARTIK images here, and for the Arduino Yún you can run: opkg upgrade temboo

2SSH into your gateway device and run the HTTP gateway, first by navigating to the location of the gateway script and then by running the script. With the gateway running, you should see feedback in your terminal window confirming that the HTTP gateway is running as expected.

Samsung ARTIK 10 gateway location

cd /opt/iothub/artik/temboo/temboo_artik_library/m2m/http

Arduino Yún gateway location

cd /usr/bin/temboo-m2m/http

Start HTTP gateway (make sure to sub in your gateway IP address)

python TembooHTTPGateway.pyc -a -s yes -d

Setting up the Temboo M2M gateway with HTTP

Starting the Temboo HTTP gateway

Now's a good time to review the script options that we're using above. We've chosen to use HTTPS to send Choreo requests to Temboo from our gateway, and to turn debug mode on so that we can monitor activity more clearly. You can adjust these options as desired.

  • -s yes|no|ifavailable, --https=yes|no|ifavailable
  • -d, --debug

Note: The Arduino Yún does not include SSL for Python by default, so you'll need to install that yourself if required. Communication with edge devices is always handled via HTTP.

For instructions on how to get set up with other protools, check out our MQTT and CoAP tutorials.

3The last step is to compile and run your gateway and edge device Choreo programs. If you haven't run Temboo code on a device before and need help with this step, we have simple getting started instructions for all devices. When the Choreo programs are running successfully, you'll be able to monitor the HTTP messages being sent to the gateway by watching the output on the terminal window that you used to start your gateway.

4That's it! You've built a multi-device M2M application that uses HTTP to communicate with with Temboo via an internet-connected gateway.


Now that you know how to generate code for multiple devices, why not check out the 2000+ Choreos in our Library and start thinking about all the possibilities for your next M2M application?

Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.