SprintUSBModem

The Sprint USB598 modem enables an mbed microcontroller to the internet through the Sprint network, as well as send/receive SMS messages.

The kit shown below can be purchased from Sprint and comprises of :

Workshop notes

Hardware Setup

/media/uploads/chris/sprint_app-board.png/media/uploads/chris/sprint-drawing.png
mbed application boardWiring Diagram

Hello World

Here is an example application using the SprintUSBModem and the HTTPClient, enabling mbed to fetch a URL over HTTP, and print the contents.

There are various other "hello world" programs that demonstrate SMS, NTP, Socket and Websocket interfaces, as well as management commands (check balance, link status, etc). See "Resources" section below.

You'll notice that this "Hello World" program is a little more complex that others, as we're using the mbed RTOS to manage the memory and processing resources/requirement of the USB Modem driver and the TCP/IP stack.

Import program

#include "mbed.h"
#include "SprintUSBModem.h"
#include "HTTPClient.h"

void test(void const*) 
{
    SprintUSBModem modem(p18);
    HTTPClient http;
    char str[512];
    
    Thread::wait(5000);
    printf("Switching power on\r\n");
    
    modem.power(true);
    
    int ret = modem.connect();
    if(ret)
    {
      printf("Could not connect\r\n");
      return;
    }
    
    //GET data
    printf("Trying to fetch page...\r\n");
    ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
    if (!ret)
    {
      printf("Page fetched successfully - read %d characters\r\n", strlen(str));
      printf("Result: %s\r\n", str);
    }
    else
    {
      printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
    }
    
    //POST data
    HTTPMap map;
    HTTPText text(str, 512);
    map.put("Hello", "World");
    map.put("test", "1234");
    printf("Trying to post data...\r\n");
    ret = http.post("http://httpbin.org/post", map, &text);
    if (!ret)
    {
      printf("Executed POST successfully - read %d characters\r\n", strlen(str));
      printf("Result: %s\r\n", str);
    }
    else
    {
      printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
    }
    
    printf("Disconnecting\r\n");
    
    modem.disconnect(); 
    
    printf("Disconnected\r\n");
    
    modem.power(false); 
    
    printf("Powered off\r\n");

    while(1) {
    }
}


int main()
{
  DBG_INIT();
  DBG_SET_SPEED(115200);
  DBG_SET_NEWLINE("\r\n");
  Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
  DigitalOut led(LED1);
  while(1)
  {
    led=!led;
    Thread::wait(1000);  
  }

  return 0;
}

Other examples

Import programSprintUSBModemSMSTest

SMS test using a Sprint/Sierra Wireless 598U dongle

Import programSprintUSBModemNTPClientTest

NTP Client test using a Sprint/Sierra Wireless 598U dongle

Import programSprintUSBModemWebsocketTest

Websocket demo using the Sprint/Sierra Wireless 598U dongle

Library

Import librarySprintUSBModem

USB Host Library for Sprint Dongles





2 comments:

01 Nov 2012

Great work Chris! Special thanks to Donatien!

18 Feb 2014

Not able to load the HTTP test program - "remote repository not found".