Simple websocket client based on the original with a few added features such as: - setBaud() - set the baud rate for the communication - Initialize() - mimics the constructor - chaged read() to readmsg() to avoid confusion with other functions
Dependents: IoT_Ex BatteryModelTester BatteryModelTester
Fork of WebSocketClient by
Diff: Websocket.cpp
- Revision:
- 15:9df4ffc6ce48
- Parent:
- 14:bf42271bde6a
- Child:
- 16:a8c6ee37356f
diff -r bf42271bde6a -r 9df4ffc6ce48 Websocket.cpp --- a/Websocket.cpp Thu Mar 31 20:38:54 2016 +0000 +++ b/Websocket.cpp Fri Apr 01 00:56:01 2016 +0000 @@ -3,18 +3,24 @@ #define MAX_TRY_WRITE 20 #define MAX_TRY_READ 10 +// #define DEBUG +#define INFOMESSAGES //Debug is disabled by default -#if 1 -#define DBG(x, ...) pc.printf("[WebSocket : DBG]"x"\r\n", ##__VA_ARGS__); -#define WARN(x, ...) pc.printf("[WebSocket : WARN]"x"\r\n", ##__VA_ARGS__); -#define ERR(x, ...) pc.printf("[WebSocket : ERR]"x"\r\n", ##__VA_ARGS__); +#ifdef DEBUG +#define DBG(x, ...) pc.printf("[WebSocket : DBG] "x"\r\n", ##__VA_ARGS__); +#define WARN(x, ...) pc.printf("[WebSocket : WARN] "x"\r\n", ##__VA_ARGS__); +#define ERR(x, ...) pc.printf("[WebSocket : ERR] "x"\r\n", ##__VA_ARGS__); #else #define DBG(x, ...) #define WARN(x, ...) #define ERR(x, ...) #endif -#define INFO(x, ...) pc.printf("[WebSocket : INFO]"x"\r\n", ##__VA_ARGS__); +#ifdef INFOMESSAGES +#define INFO(x, ...) pc.printf("[WebSocket : INFO] "x"\r\n", ##__VA_ARGS__); +#else +#define INFO(x, ...) +#endif Websocket::Websocket(char * url) { fillFields(url); @@ -30,6 +36,11 @@ socket.set_blocking(false, 400); } +void Websocket::setBaud(int baudrate){ + socket.setBaud(baudrate); + return; +} + void Websocket::fillFields(char * url) { int ret = parseURL(url, scheme, sizeof(scheme), host, sizeof(host), &port, path, sizeof(path)); if(ret)