IN THIS ARTICLE

    Building your IoT app just got as easy as assemble, connect, and prototype. Today, we’re excited to announce our partnership with the AT&T IoT Starter Kit, enabling developers to build and deploy IoT apps using AT&T’s variety of tools for connectivity, LTE hardware, and cloud storage, and PubNub’s Programmable Network for bidirectional data streaming between connected devices.

    This is super exciting. You can now harness the power of AT&T’s reliable wireless broadband network, combine it with the IoT Starter Kit hardware, and connect it all with PubNub. Stream temperature readings, plot geolocation coordinates, or trigger a smart device action from anywhere on Earth in realtime.

    We’re also excited to announce that we’re partnering with AT&T for the upcoming Realtime AT&T IoT Starter Kit Challenge on Hackster.io. Harnessing the power of AT&T’s new IoT Starter Kit, Flow, and PubNub, hackers across the United States will contend to see who can build the most innovative IoT app. With a ton of great prizes, we hope to see your app!

    screen-shot-2016-11-15-at-1-18-30-pm

    Introduction

    In this blog post, we’ll walkthrough how to implement PubNub on the AT&T IoT Starter Kit board. The AT&T IoT Starter Kit is a powerful embedded computer with a built in network connection, based on the NXP FRDM-6K4F with an AVNET WNC-based cellular add-on shield.

    Prerequisites

    Accounts

    Before you begin, be sure you first:

    1. Create a PubNub Account

    Device Initialization and Setup with AT&T

    In addition to creating the required accounts, be sure that you’ve set up your AT&T IoT Starter Kit hardware. You’ll need to register and initialize the SIM card before proceeding. The quickstart page is provided by AT&T to help you accomplish this task. The quickstart page also links to the Starter Kit Guide, which provides a breadth of helpful information on all things relating to the Starter Kit.

    Terminal Setup

    Once you have setup the hardware, in order to view debug information directly from the device, you’ll need to setup a Terminal app, and connect the AT&T IoT Starter Kit with it. We’ve had great success with Tera Term, but you can use whichever terminal you prefer. Just be sure you set up the serial configuration correctly — check out this reference from mbed.org on how to setup terminals with your device (including Tera Term).

    NOTE: In your terminal setup, be sure you set the baud rate to 115200, and also under “New Line”, set “Receive” to “LF”.

    Installing and Running the Sample Project

    PubNub and AT&T have made it really easy for you to be publishing and receiving messages in realtime using the ready-to-run PubNub for AT&T IoT Starter Kit client SDK and demo application. We’ll walk through the simple steps of getting it up and running:

    1. Login to mbed.org.
    2. Import the demo application.
    3. Project Overview.
    4. Compile.
    5. Deploy to device.
    6. Verify operation on hardware console.
    7. Verify operation on PubNub web demo console.
    8. Modify the app to run with your keys and your logic.
    9. Import PubNub into an existing AT&T Starter Kit Project.

    Login to mbed.org

    As noted earlier, you’ll need to have your mbed.org credentials to login to mbed.org. Once you’ve signed up, login to the mbed.org developer site.

    pubnub-att-iot-starter-kit-1

    Import the Demo Application

    After you’ve logged in, head straight to the demo app’s mbed home page. Once on the page, click Import into Compiler.

    pubnub-att-iot-starter-kit-2

    NOTE: If this is your first time importing an app targeted for the FRDM-K64F board, you may be prompted to import the platform and choose a default template for that platform. If this happens, just be sure to import the FRDM-K64F platform from the options provided:

    pubnub-att-iot-starter-kit-3

    In addition, mbed.org may prompt you to install a template. If so, just accept the default template and options.

    If you feel out of sync or disoriented after being prompted by these potential extra steps, don’t worry! You can always restart from the top of this Login to mbed.org section without any negative side effects.

    After you click Import into Compiler, you will be brought to your IDE workspace, with the Import Program dialog in focus:

    pubnub-att-iot-starter-kit-4

    You can safely accept the defaults, and click Import.

    After the program imports, the dialog will disappear, and the IDE will display the demo application loaded into the mbed.org IDE:

    pubnub-att-iot-starter-kit-5

    Before we move on to the compile step, let’s quickly take a look at the anatomy of this project to better understand what it will be doing.

    Project Overview

    This demo application imports a couple unique libraries:

    • WNCInterface
    • PubNub Sync Interface

    Of specific interest are the WNC modem library (WNCInterface) and PubNub Sync interface library (pubnub-mbed2-sync.) As one may expect, these libraries provide the interface to the cellular modem stack, as well as the PubNub logic layer that rides on top of it.

    If we click into main.cpp, we’ll see about 80 lines of code that makes up our actual demo application. Reading from top to bottom, we see the code that:

    1. Includes the required libraries.
    2. Defines the serial configuration.
    3. Provides a helper function that lets us easily generate and assign a UUID (device identifier.)
    4. Defines the main function which in addition:
      1. Initializes the cellular modem.
      2. Creates the PubNub instance with default demo keys.
      3. Assigns a UUID to the instance.
      4. Infinitely publishes.
      5. Infinitely subscribes.

    It’s really barebones and is intended as a starting point if you’re building your app from scratch and need a ready-to-build off PubNub configuration as a foundation. Feel free to tweak it as you need! But before you do, lets see how it runs out of the box.

    Compile

    The app comes set up with some sane defaults. These defaults enable us to run the app out of the box to test it before proceeding with any customizations.

    To compile it, just click the Compile button located at the top of the IDE:

    pubnub-att-iot-starter-kit-6

    Upon successful compile, a file called Pubnub_ATT_IoT_SK_WNC_sync_K64F.bin is prompted for download. Download this file to your hard drive.

    Deploy to Device

    To deploy to your AT&T IoT Starter Kit hardware, connect it to your PC or Mac per the AT&T Quickstart guide instructions. You should see an MBED device drive mapping appear on your PC or Mac. For example, on PC, it may look something like this in File Explorer:

    pubnub-att-iot-starter-kit-7

    To deploy this app to the device, just drag the file Pubnub_ATT_IoT_SK_WNC_sync_K64F.bin to the MBED drive.

    Make sure your terminal app is connected to the AT&T IoT Starter Kit hardware:

    pubnub-att-iot-starter-kit-8

    And then power-cycle the AT&T IOT Starter Kit device.

    Verify operation on hardware console

    Keep an eye on the hardware-connected terminal as the device comes back up after power cycling. After 30s or so, you should begin to get output of the modem I/O:

    pubnub-att-iot-starter-kit-9

    If you can see the above output, you’re in a good place!

    Verify Operation on PubNub Web Demo Console

    In addition to debugging on the hardware device, you can also debug the PubNub message data on nearly any platform, including web.

    This link provides a pre-configured console connecting with the demo keys and the hello_world channel.

    NOTE: If the system queries you to use the new console, reply no. You can always revert to being prompted to use the new console by deleting your cookies for pubnub.com and reloading the console page.

    If you end up using your own keys and/or changing the channel name, you’ll need to change the values in this console to reflect that, and click Unsubscribe then Subscribe again for the changes to take place.

    pubnub-att-iot-starter-kit-10

    Modify The App To Run With Your Keys and Your Logic

    Once you’ve verified the app runs with the defaults, it’s easy to begin tweaking it to perform custom logic. The first major configuration changes are to switch from the default keys to your own keys.

    Changing this line will accomplish that:

    pubnub_init(pbp, "demo", "demo");
    

    The second parameter is the publish key, and the third parameter is the subscribe key.

    Next, to change the channel it is publishing and subscribing on, changing the second parameter in the publish and subscribe calls will accomplish that task:

    pubnub_publish(pbp, "hello_world", "\"Hello world from MBed WNC!\"");
    pubnub_subscribe(pbp, "hello_world", 0);
    

    Import PubNub Into Existing AT&T IoT Starter Kit Project

    If you already have an existing AT&T IoT Starter Kit project, you can just as import PubNub into it as well:

    1. Import the Pubnub library by URL:

    https://os.mbed.com/users/sveljko/code/Pubnub_mbed2_sync/

    2. If your MBed project/program doesn’t already use it, import the WNC modem library by URL: http://developer.mbed.org/teams/Avnet/code/WNCInterface/#75cf1e1c921c

    NOTE: The latest revision at the time of this writing has build issues, but we don’t need it, so use the specific revision from the above URL.

    3. Add a `pubnub_config.h` to your program. You can copy the contents from the sample program ( https://os.mbed.com/users/sveljko/code/Pubnub_ATT_IoT_SK_WNC_sync/file/dcb02cfdc63c/pubnub_config.h/)

    and then tinker with it, if you wish. All the “knobs” are documented, so here we’ll look at only the “where to log” configuration, near the end of `pubnub_config.h`:

    #include <MODSERIAL.h>
    extern MODSERIAL pc;
    #define PUBNUB_LOG_PRINTF(...) pc.printf(__VA_ARGS__)
    

    This expects that in your program somewhere you define the `MODSERIAL pc` global object. In the sample program, it’s defined in `main.cpp`:

    MODSERIAL pc(USBTX,USBRX,256,256);
    

    Of course, you can `#define PUBNUB_LOG_PRINTF(...)` to whatever you wish to use for PubNub logging.

    4. If your MBed project/program doesn’t already use/initialize it, initialize the WNC modem/library. Just define an object of class `WNCInterface` and then call its `init` and `connect` member functions. This is how it’s done in the sample program at https://os.mbed.com/users/sveljko/code/Pubnub_ATT_IoT_SK_WNC_sync/file/dcb02cfdc63c/main.cpp/:

     WNCInterface eth;
        int main()
        {
            // .... some other init code, like serial port (`pc`)
            pc.printf("init() returned 0x%04X" CRLF, eth.init(NULL,&pc));
     	   eth.connect();
            pc.printf("IP Address: %s" CRLF, eth.getIPAddress());
           // now modem init is done, you can use Pubnub C-core APIs
    

    5. After the modem has be initialized, you can use the Pubnub C-core APIs like on any other supported platform.

    Conclusion

    This tutorial served as a general introduction to using PubNub Data Streams with the AT&T IoT Starter Kit. Publish and Subscribe operations, along with setup and debug against a new or existing app were demonstrated.

    If you have any feedback or support questions please feel free to contact us at support@pubnub.com.

    If you’d like more info on seeing PubNub work with AT&T, check out these webinars on AT&T Flow Designer and the AT&T Iot Starter Kit:

    Try PubNub today!
    Build realtime applications that perform reliably and securely, at global scale.
    Try Our APIs
    Try PubNub today!

    More From PubNub