Getting Started with Twilio Programmable Wireless on the LinkIt ONE

At SIGNAL we launched Twilio Programmable Wireless which allows you to add cellular data to your IoT projects using a Twilio SIM card. The LinkIt ONE dev board in the SIGNAL hackpack is a perfect place to try out these new capabilities. In the next 5 minutes you’ll learn how to use the cellular functionality of this device using your Twilio SIM card.

What You’ll Need

Before we get to hacking there are a few things we need to get set up. First, we need to set up the LinkIt ONE board and make sure it is programmable using the Arduino IDE and the MediaTek LinkIt ONE SDK. The steps for getting this set up are outlined in this blog post. Once you’ve completed those steps you’ll want to also make sure to attach the cellular antenna if you haven’t already because it is needed for Twilio Programmable Wireless.

Next, we need to activate the Twilio SIM in our account. If you received a SIM card with a hackpack at SIGNAL your SIM is already activated so you can skip this activation step. Otherwise, you can activate your SIM card in the Twilio Programmable Wireless portion of the console by entering its
ICCID into the text field as shown on this screenshot:

Once you’ve activated your SIM card, plug it into the LinkIt ONE’s SIM card slot as shown in this photo:

That’s all for hardware setup.

Can I Make a Request?

The MediaTek LinkIt ONE SDK includes a library for working with the cellular functionality of the LinkIt ONE development board. To include this library in our project we’ll add it from the Library Manager in the Arduino IDE. Create a new Sketch and under the Sketch menu select Include Library > LGPRS. This will add four header files. We only need two of them: LGPRS.h and LGPRSClient.h. The top of your Sketch should look like this:

The LGPRS class allows us to attach to a GPRS network. The LGPRSClient class is what we’ll use to make an HTTP request using the LGPRS connection we’ve established using LGPRS. Add the following code underneath the two #include lines:

For this tutorial I’ve set up a URL on putsreq.com that returns “Hello world”. If you want to see it in action in your browser you can click on this link. In the code above we #define the base URL for this site in SITE_URL. We’ll use this later when we connect to the site and make an HTTP request. The next line declares an LGPRSClient variable that we’ll use to write our HTTP GET request.

All Arduino projects consist of a setup() function that initializes the project and a loop() function that runs indefinitely and does the main work for the project. We’ll start in the setup() method by turning on the cellular radio and connecting it to Twilio Programmable Wireless. Replace your setup() function with the following code:

Now would be a great time to make sure everything is working. Click the Upload button in the Arduino IDE and open up the Serial Monitor from the Tools menu. If everything is working correctly you should see “GPRS attached.” printed out in the Serial Monitor.

Next use the LGPRSClient to make a connection to SITE_URL so that we can send requests to our putsreq.com sample. Add the following code to the end of your setup() function:

We first attempt to connect to the site on port 80. If we are successful, “Connection successful” is printed in the Serial Monitor. If not, we return from setup() and print an error message. Now that we’re connected to the site we can make our HTTP GET request. Add this code to the end of your setup() function:

This code writes out the HTTP GET request lines using the LGPRS client. The response to this request will be available in the loop() function.

Write the loop() function thatreads the results of our HTTP GET request to http://putsreq.com/m3JKNFhGxaeu0KsXcdLl. Replace the loop()function in your Sketch with this code:

This code checks to see if there is data available in the client. Once the request comes in it prints out the response to our GET request character by character. At this point our example is complete. Upload the Sketch to your development board and watch Serial Monitor for the results. Here’s what it looks like running on my board:

That’s it, you just wrote your first Twilio Programmable Wireless program!

What’s next?

Now that you have Twilio Programmable Wireless working on your LinkIt ONE board, your IoT projects have access to the Internet using cellular data. Here are some things you might consider doing now that you have this working:

We’re super excited to see what you build with Twilio Programmable Wireless. If you’re at SIGNAL, come see me at the hackpack station and let’s talk about IoT. Otherwise, if you have any questions or comments you can find me on Twitter @brentschooley or email me at brent@twilio.com.

  • The sim ICCID doesn’t work in the console.

    • Randy Beiter

      Hello! I’m sorry to hear you are having issues with your ICCID, please reach out to support and we’ll get you set up.

  • Cliff Anderson

    Thanks, Brent, for these great instructions! I followed them successfully and received the “Hello World” response. I should note that I had to switch ports in order to get the Serial Monitor to display. See this post: http://www.seeedstudio.com/forum/viewtopic.php?f=42&t=5814. I hope that you’ll follow up with more blog posts, perhaps illustrating some of your proposed next steps. Great stuff!

  • Sri

    I haven’t received a Twilio SIM. Does it have to Twilio SIM or can I pick up any SIM for example – T-Mobile?

  • Sri

    Hi! I haven’t received Twilio SIM. Is there any way I can still receive it or can I use any SIM (T-Mobile or AT&T ..)?

  • Sri

    Hello. I didn’t receive Twilio SIM. Can I still get it or can I use any SIM? Just register ICCID with Twilio?

  • lish

    CLASSICAL ATM HACKERS, is the only genuine ATM cloned card vendor which i have tested and confirmed. So i met this hacker online and we emailed back & forth about an ATM card and how they create them and sells them thus was curious how this could be true. I was in trouble financially two weeks ago so i told him i need one asap. I western union some money to him and to my greatest shock, the card was shipped to me in 44 hrs. When i got it i went to a near by ATM which was across the street from my house and i asked for $9000 and it actually dispensed the fucking cash{ WHAT A MIRACLE} so since then I’ve been able to get money freely with no pin. Contact their email if you truly need this card.. (martinshackers22@gmail.com , martinshackers22@gmail.com)….

  • Techao Wei

    How to activate the device via ICCID?