Forked mbed official WiflyInterface (interface for Roving Networks Wifly modules) which includes the possibility to use TCPSocketServer::accept as a non-blocking cal.
Dependents: WiFlyHTTPServerSample MultiThreadingHTTPServer
Fork of WiflyInterface by
Diff: Wifly/Wifly.cpp
- Revision:
- 5:48d55083d2ff
- Parent:
- 4:0bcec6272784
- Child:
- 6:120296f9f865
- Child:
- 7:e42b7fa7ef70
--- a/Wifly/Wifly.cpp Thu Dec 20 15:08:58 2012 +0000 +++ b/Wifly/Wifly.cpp Sat Jun 01 15:03:14 2013 +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__); @@ -43,7 +43,7 @@ Wifly * Wifly::inst; Wifly::Wifly( PinName tx, PinName rx, PinName _reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec): - wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), buf_wifly(256) + wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), buf_wifly(512) { memset(&state, 0, sizeof(state)); state.sec = sec; @@ -113,7 +113,7 @@ continue; // ssid - sprintf(cmd, "set w s %s\r", ssid); + sprintf(cmd, "set wlan ssid %s\r", ssid); if (!sendCommand(cmd, "AOK")) continue; @@ -158,9 +158,11 @@ if (!sendCommand("join\r", "Associated", NULL, 10000)) continue; } - + if (!sendCommand("save\r", "Stor")) continue; + + enableTime(1); exit(); @@ -299,6 +301,53 @@ buf_wifly.flush(); } +int Wifly::enableTime(int minutes, const char* ntp_address) +{ + char cmd[30]; + + //let module automatically conntect to timeserver and get the actual time + sprintf(cmd, "set t e %d\r", minutes); + if (!sendCommand(cmd, "AOK")) { + ERR("Failed to modify time function !"); + return -1; + } + + //set the NTP server address + sprintf(cmd, "set t a %s\r", ntp_address); + if (!sendCommand(cmd, "AOK")) { + ERR("Failed to modify time server address !"); + } + + if (!sendCommand("set option format 1\r", "AOK")) { + ERR("Failed to set option format to ASCII !"); + } + + if (!sendCommand("set time zone 0\r", "AOK")) { + ERR("Failed to set time zone !"); + } + + sendCommand("time\r", NULL, NULL); + + flush(); + + exit(); + + return 0; +} + +string Wifly::getTime(bool uptime) +{ + char buf[100]; + +// sendCommand("time\r", NULL, NULL, 10000); + if (!sendCommand("show time\r", NULL, buf, 10000)) + return ""; + INFO("\r\nReceived Time : %s\r\n", buf); + + exit(); + return buf; +} + bool Wifly::sendCommand(const char * cmd, const char * ack, char * res, int timeout) { if (!state.cmd_mode) { @@ -483,7 +532,6 @@ found = checking.find(ACK); if (found != string::npos) { wait(0.01); - //We flush the buffer while (wifi.readable()) wifi.getc();