Test u-blox C027, nodejs, socketio on heroku
Dependencies: C027 EthernetInterface SocketIO WebSocketClient mbed-rtos mbed
Fork of C027_Socketio_Ethernet by
Diff: main.cpp
- Revision:
- 6:4af1b4a1b875
- Parent:
- 4:0bdab35cb164
--- a/main.cpp Tue Apr 22 21:21:49 2014 +0000 +++ b/main.cpp Sun Apr 27 13:50:16 2014 +0000 @@ -6,7 +6,7 @@ //Debug is disabled by default -#if 1 +#if 0 //Enable debug #include <cstdio> #define DBG(x, ...) std::printf("[main : DBG]"x"\r\n", ##__VA_ARGS__); @@ -68,22 +68,32 @@ eth.connect(); DBG("IP Address is %s", eth.getIPAddress()); + // server1 + //SocketIO socketio("websocket-server-c9-chau_vk.c9.io"); SocketIO socketio("nne-server1.herokuapp.com"); - //SocketIO socketio("websocketserver-tutorial11067089.rhcloud.com"); - //SocketIO socketio("websocket-server.chau_vk.c9.io:8001"); - //SocketIO socketio("websocket-server-c9-chau_vk.c9.io"); + //SocketIO socketio("nneserver1-tutorial11067089.rhcloud.com"); // is downgraded to xhr-polling + + // server2 + //SocketIO socketio("realchart-c9-chau_vk.c9.io"); + + Timer t; t.start(); - - bool c = socketio.connect(); // c is always false, (maybe because the connection is upgraded?) - DBG("Connect result: %s", c?"OK":"Failed"); + + socketio.connect(); while (1) { - int res = socketio.emit("mesage","[\"mbed SocketIO Hello World!\"]"); + socketio.connect(); + bool is_connected = socketio.is_connected(); + //DBG("Connect result: %s", is_connected?"OK":"Failed"); + + if (is_connected && (t.read() > 10)) { + int res = socketio.emit("message","0.5"); + t.reset(); // transmit every 10s + } if (socketio.read(msg)) { DBG("rcv: %s", msg); } - wait(0.1); } }