WiflyInterface library (interface for Roving Networks Wifly modules)
Dependents: IOT-Websocket_Wifly_HelloWorld WiFly_NSDL_HelloWorld IOT-Project-LED-ControlTelnet IOT-Project-Wifly-Xively ... more
Fork of WiflyInterface by
Diff: Wifly/Wifly.cpp
- Revision:
- 8:68617e1f704c
- Parent:
- 4:0bcec6272784
- Child:
- 9:a27cf731e79a
--- a/Wifly/Wifly.cpp Wed Oct 23 14:34:33 2013 +0000 +++ b/Wifly/Wifly.cpp Tue Feb 25 00:47:17 2014 +0000 @@ -22,7 +22,7 @@ #include <algorithm> //Debug is disabled by default -#if (0 && !defined(TARGET_LPC11U24)) +#if (1 && !defined(TARGET_LPC11U24)) #define DBG(x, ...) std::printf("[Wifly : DBG]"x"\r\n", ##__VA_ARGS__); #define WARN(x, ...) std::printf("[Wifly : WARN]"x"\r\n", ##__VA_ARGS__); #define ERR(x, ...) std::printf("[Wifly : ERR]"x"\r\n", ##__VA_ARGS__); @@ -67,7 +67,7 @@ bool Wifly::join() { - char cmd[20]; + char cmd[75]; for (int i= 0; i < MAX_TRY_JOIN; i++) { @@ -302,7 +302,9 @@ bool Wifly::sendCommand(const char * cmd, const char * ack, char * res, int timeout) { if (!state.cmd_mode) { - cmdMode(); + if (!cmdMode()) { + return false; + } } if (send(cmd, strlen(cmd), ack, res, timeout) == -1) { ERR("sendCommand: cannot %s\r\n", cmd); @@ -315,13 +317,15 @@ bool Wifly::cmdMode() { // if already in cmd mode, return - if (state.cmd_mode) + if (state.cmd_mode) { return true; - + } if (send("$$$", 3, "CMD") == -1) { - ERR("cannot enter in cmd mode\r\n"); - exit(); - return false; + if (send("\r\n", 3, ">") == -1) { + ERR("cannot enter in cmd mode\r\n"); + exit(); + return false; + } } state.cmd_mode = true; return true; @@ -416,7 +420,7 @@ char Wifly::getc() { - char c; + char c = 0xcc; while (!buf_wifly.available()); buf_wifly.dequeue(&c); return c;