Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: UbloxUSBModem WebSocketClient mbed
websocketstest.cpp
00001 00002 #include "websocketstest.h" 00003 #include "Websocket.h" 00004 00005 void websocketstest(CellularModem& modem, const char* apn, const char* username, const char* password) 00006 { 00007 char msg[2048] = {0}; 00008 Timer t; 00009 00010 t.start(); 00011 modem.power(true); 00012 Thread::wait(1000); 00013 int ret = modem.connect(apn, username, password); 00014 if(ret) 00015 { 00016 error("Modem connect failed: %s line %d\n", __FILE__ , __LINE__); 00017 } 00018 00019 // See the output on http://sockets.mbed.org/sg_test/viewer 00020 Websocket ws("ws://sockets.mbed.org:443/ws/sg_test/rw"); 00021 00022 for(int i=0; i<0x7fffffff; ++i) 00023 { 00024 ws.connect(); 00025 // create json string with acc/tmp data 00026 sprintf(msg, "Testing mbed Websockets Loop: %d", i); 00027 ws.send(msg); 00028 wait(0.5f); 00029 memset(msg, 0, 2048); 00030 00031 if (ws.read(msg)) 00032 { 00033 printf("rcv: %s\r\n", msg); 00034 } 00035 else 00036 { 00037 printf("Loop %d ws.read() returns 0\n \t %s, line %d @ %6.2f seconds\n", i, __FILE__, __LINE__, t.read()); 00038 wait(5.0f); 00039 } 00040 ws.close(); 00041 } 00042 00043 t.stop(); 00044 modem.disconnect(); 00045 modem.power(false); 00046 00047 puts("Powered off Test Complete"); 00048 }
Generated on Mon Jul 18 2022 10:01:18 by
