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 :
- mbed NXP LPC1768
- mbed application board,
- Sprint 598U modem
- 9v, 1.2A DC power adaptor, 1.3mm centre-positive
Workshop notes¶
Hardware Setup¶
mbed application board | Wiring 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
00001 #include "mbed.h" 00002 #include "SprintUSBModem.h" 00003 #include "HTTPClient.h" 00004 00005 void test(void const*) 00006 { 00007 SprintUSBModem modem(p18); 00008 HTTPClient http; 00009 char str[512]; 00010 00011 Thread::wait(5000); 00012 printf("Switching power on\r\n"); 00013 00014 modem.power(true); 00015 00016 int ret = modem.connect(); 00017 if(ret) 00018 { 00019 printf("Could not connect\r\n"); 00020 return; 00021 } 00022 00023 //GET data 00024 printf("Trying to fetch page...\r\n"); 00025 ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); 00026 if (!ret) 00027 { 00028 printf("Page fetched successfully - read %d characters\r\n", strlen(str)); 00029 printf("Result: %s\r\n", str); 00030 } 00031 else 00032 { 00033 printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode()); 00034 } 00035 00036 //POST data 00037 HTTPMap map; 00038 HTTPText text(str, 512); 00039 map.put("Hello", "World"); 00040 map.put("test", "1234"); 00041 printf("Trying to post data...\r\n"); 00042 ret = http.post("http://httpbin.org/post", map, &text); 00043 if (!ret) 00044 { 00045 printf("Executed POST successfully - read %d characters\r\n", strlen(str)); 00046 printf("Result: %s\r\n", str); 00047 } 00048 else 00049 { 00050 printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode()); 00051 } 00052 00053 printf("Disconnecting\r\n"); 00054 00055 modem.disconnect(); 00056 00057 printf("Disconnected\r\n"); 00058 00059 modem.power(false); 00060 00061 printf("Powered off\r\n"); 00062 00063 while(1) { 00064 } 00065 } 00066 00067 00068 int main() 00069 { 00070 DBG_INIT(); 00071 DBG_SET_SPEED(115200); 00072 DBG_SET_NEWLINE("\r\n"); 00073 Thread testTask(test, NULL, osPriorityNormal, 1024 * 5); 00074 DigitalOut led(LED1); 00075 while(1) 00076 { 00077 led=!led; 00078 Thread::wait(1000); 00079 } 00080 00081 return 0; 00082 }
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