wifly/socket interface for wifly modules
Dependents: WiFi neurGAI_WIFI thingspeak thingspeak2
Diff: Socket/UDPSocket.cpp
- Revision:
- 11:b912f91e3212
- Parent:
- 6:f281180726e8
- Child:
- 13:108340829acc
--- a/Socket/UDPSocket.cpp Thu Aug 23 16:03:52 2012 +0000 +++ b/Socket/UDPSocket.cpp Fri Aug 24 13:07:01 2012 +0000 @@ -29,8 +29,7 @@ int UDPSocket::init(void) { - if (!wifi->sendCommand("set ip proto 1\r", "AOK")) - return -1; + wifi->setProtocol(UDP); wifi->exit(); return 0; } @@ -38,21 +37,15 @@ // Server initialization int UDPSocket::bind(int port) { - // use udp auto pairing - char cmd[20]; - if (!wifi->sendCommand("set ip proto 1\r", "AOK")) - return -1; - if (!wifi->sendCommand("set ip flags 0x40\r", "AOK")) - return -1; - if (!wifi->sendCommand("set ip host 0.0.0.0\r", "AOK")) - return -1; - if (!wifi->sendCommand("set ip remote 0\r", "AOK")) - return -1; - sprintf(cmd, "set ip local %d\r", port); + char cmd[17]; + + // set udp protocol + wifi->setProtocol(UDP); + + // set local port + sprintf(cmd, "set i l %d\r", port); if (!wifi->sendCommand(cmd, "AOK")) return -1; - if (!wifi->sendCommand("save\r", "Stor")) - return -1; wifi->exit(); return 0; } @@ -124,14 +117,16 @@ if (!endpoint_configured) { host = ep.get_address(); if (host[0] != '\0') { - sprintf(cmd, "set ip host %s\r", host); + // set host + sprintf(cmd, "set i h %s\r", host); if (!wifi->sendCommand(cmd, "AOK")) return false; - sprintf(cmd, "set ip remote %d\r", ep.get_port()); + + // set remote port + sprintf(cmd, "set i r %d\r", ep.get_port()); if (!wifi->sendCommand(cmd, "AOK")) return false; - if (!wifi->sendCommand("save\r", "Stor")) - return false; + wifi->exit(); endpoint_configured = true; return true;