Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Mon Oct 07 22:05:31 2013 +0000
Revision:
20:39772b740985
Parent:
19:f1d893c651e5
Child:
21:3f45e53afe4f
Updated websocket test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 20:39772b740985 1
donatien 0:43ee25ebfe6b 2 #include "mbed.h"
donatien 0:43ee25ebfe6b 3 #include "SprintUSBModem.h"
donatien 0:43ee25ebfe6b 4 #include "HTTPClient.h"
sam_grove 14:cd53f77f8afe 5 #include "Websocket.h"
donatien 0:43ee25ebfe6b 6
sam_grove 20:39772b740985 7 void websocketTest(void const*)
donatien 0:43ee25ebfe6b 8 {
mike.pulice@proxy-usa.com 7:655438fd019f 9 SprintUSBModem modem(p18, true, 1);
sam_grove 20:39772b740985 10 char msg[2048];
donatien 0:43ee25ebfe6b 11
sam_grove 20:39772b740985 12 // Using C16-C20 make sure to connect mbed p18 to J2 pin 16
donatien 0:43ee25ebfe6b 13 modem.power(true);
donatien 0:43ee25ebfe6b 14 int ret = modem.connect();
donatien 0:43ee25ebfe6b 15 if(ret)
donatien 0:43ee25ebfe6b 16 {
sam_grove 20:39772b740985 17 error("Modem connect failed: %s %d", __PRETTY_FUNCTION__ , __LINE__);
donatien 0:43ee25ebfe6b 18 }
sam_grove 20:39772b740985 19
sam_grove 14:cd53f77f8afe 20 // See the output on http://sockets.mbed.org/sg_test/viewer
sam_grove 14:cd53f77f8afe 21 Websocket ws("ws://sockets.mbed.org:443/ws/sg_test/rw");
sam_grove 14:cd53f77f8afe 22 ws.connect();
sam_grove 20:39772b740985 23 for(int i=0; i<0x7fffffff; ++i)
sam_grove 14:cd53f77f8afe 24 {
sam_grove 14:cd53f77f8afe 25 // create json string with acc/tmp data
sam_grove 20:39772b740985 26 sprintf(msg, "Testing mbed Websockets Loop: %d", i);
sam_grove 20:39772b740985 27 ws.send(msg);
sam_grove 19:f1d893c651e5 28 wait(0.5f);
sam_grove 20:39772b740985 29 memset(msg, 0, 2048);
sam_grove 20:39772b740985 30
sam_grove 20:39772b740985 31 if (ws.read(msg))
sam_grove 14:cd53f77f8afe 32 {
sam_grove 20:39772b740985 33 printf("rcv: %s\r\n", msg);
sam_grove 14:cd53f77f8afe 34 }
sam_grove 20:39772b740985 35 else
sam_grove 20:39772b740985 36 {
sam_grove 20:39772b740985 37 printf("Loop %d ws.read() returns 0\n", i);
sam_grove 20:39772b740985 38 }
donatien 0:43ee25ebfe6b 39 }
donatien 0:43ee25ebfe6b 40
sam_grove 20:39772b740985 41 ws.close();
donatien 0:43ee25ebfe6b 42
sam_grove 20:39772b740985 43 modem.disconnect();
donatien 0:43ee25ebfe6b 44 modem.power(false);
donatien 0:43ee25ebfe6b 45
sam_grove 20:39772b740985 46 puts("Powered off Test Complete");
sam_grove 20:39772b740985 47 while(1);
donatien 0:43ee25ebfe6b 48 }
donatien 0:43ee25ebfe6b 49
donatien 0:43ee25ebfe6b 50 int main()
donatien 0:43ee25ebfe6b 51 {
donatien 0:43ee25ebfe6b 52
sam_grove 20:39772b740985 53 Thread task(websocketTest, NULL, osPriorityNormal, 1024 * 5);
sam_grove 20:39772b740985 54 // Thread task(httpTest, NULL, osPriorityNormal, 1024 * 5);
sam_grove 20:39772b740985 55
sam_grove 20:39772b740985 56 DigitalOut led(LED1);
sam_grove 20:39772b740985 57
sam_grove 20:39772b740985 58 while(1)
sam_grove 20:39772b740985 59 {
sam_grove 20:39772b740985 60 led = !led;
sam_grove 20:39772b740985 61 Thread::wait(1000);
sam_grove 20:39772b740985 62 }
sam_grove 20:39772b740985 63
sam_grove 20:39772b740985 64 return 0;
donatien 0:43ee25ebfe6b 65 }