Example project showing temperature posted to sockets.mbed.org
Dependencies: LM75B SprintUSBModem WebSocketClient mbed-rtos mbed
Fork of SprintUSBModemWebsocketTest by
Revision 2:72c06f2902d5, committed 2012-11-01
- Comitter:
- chris
- Date:
- Thu Nov 01 03:00:53 2012 +0000
- Parent:
- 1:380f5db5d004
- Commit message:
- Make it an infinite loop, and posting data "WO"
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 380f5db5d004 -r 72c06f2902d5 main.cpp --- a/main.cpp Wed Oct 31 19:32:31 2012 +0000 +++ b/main.cpp Thu Nov 01 03:00:53 2012 +0000 @@ -1,78 +1,68 @@ -#include "mbed.h" -#include "SprintUSBModem.h" -#include "Websocket.h" -#include "LM75B.h" - -void test(void const*) -{ - LM75B tmp(p28,p27); - - SprintUSBModem modem(p18); - Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); - char recv[128]; - char msg[32]; - - 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; - } - - bool c = ws.connect(); - printf("Connect result: %s\r\n", c?"OK":"Failed"); - - for(int i = 0; i < 10000; i++) - { - if(!(i%100)) - { - sprintf(msg, "Temp = %.1f",tmp.read()); - int ret = ws.send(msg); - if(ret<0) - { - printf("Timeout\r\n"); - ws.close(); - c = ws.connect(); - printf("Connect result: %s\r\n", c?"OK":"Failed"); - } - } - - if (ws.read(recv)) { - printf("rcv: %s\r\n", recv); - } - - } - - 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; -} +#include "mbed.h" +#include "SprintUSBModem.h" +#include "Websocket.h" +#include "LM75B.h" + +void test(void const*) +{ + LM75B tmp(p28,p27); + + SprintUSBModem modem; + // view at http://sockets.mbed.org/demo/viewer + Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo"); + + char recv[128]; + char msg[32]; + + modem.power(true); + + int ret = modem.connect(); + if(ret) { + printf("Could not connect\r\n"); + return; + } + + bool c = ws.connect(); + printf("Connect result: %s\r\n", c?"OK":"Failed"); + + while (1) { + + sprintf(msg, "Temp = %.1f",tmp.read()); + int ret = ws.send(msg); + if(ret<0) { + printf("Timeout\r\n"); + ws.close(); + c = ws.connect(); + printf("Connect result: %s\r\n", c?"OK":"Failed"); + } + Thread::wait(1000); + + } + + 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; +}