An example program that establishes a read-only web socket connection, and echos everything it sees to the LCD

Dependencies:   C12832_lcd SprintUSBModem WebSocketClient mbed-rtos mbed

Fork of SprintUSBModemWebsocketTest-Temp by Chris Styles

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SprintUSBModem.h"
00003 #include "Websocket.h"
00004 #include "C12832_lcd.h"
00005 
00006 void test(void const*)
00007 {
00008 
00009     SprintUSBModem modem;
00010     // Send messages at http://sockets.mbed.org/demo/sender
00011     Websocket ws("ws://sockets.mbed.org:443/ws/demo/ro");
00012 
00013     char recv[128];
00014 
00015     modem.power(true);
00016 
00017     int ret = modem.connect();
00018     if(ret) {
00019         printf("Could not connect\r\n");
00020         return;
00021     }
00022 
00023     bool c = ws.connect();
00024     printf("Connect result: %s\r\n", c?"OK":"Failed");
00025 
00026     C12832_LCD lcd;
00027     lcd.cls();
00028 
00029     while (1) {
00030 
00031         if (ws.read(recv)) {
00032             printf("rcv: %s\r\n", recv);
00033             lcd.cls();
00034             lcd.locate(0,3);
00035             lcd.printf(recv);
00036         }
00037 
00038         Thread::wait(1000);
00039     }
00040 
00041     modem.disconnect();
00042 
00043     printf("Disconnected\r\n");
00044 
00045     modem.power(false);
00046 
00047     printf("Powered off\r\n");
00048 
00049 }
00050 
00051 
00052 int main()
00053 {
00054     DBG_INIT();
00055     DBG_SET_SPEED(115200);
00056     DBG_SET_NEWLINE("\r\n");
00057     Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
00058     DigitalOut led(LED1);
00059     while(1) {
00060         led=!led;
00061         Thread::wait(1000);
00062     }
00063 
00064     return 0;
00065 }