void loop() { if (wifly.available() > 0) { /* See if there is a request */ if (wifly.gets(buf, sizeof(buf))) { if (strncmp_P(buf, PSTR("GET /ping"), 9) == 0) { /* GET request */ #ifdef DEBUG Serial.println(F("PONG XML requested")); #endif while (wifly.gets(buf, sizeof(buf)) > 0) { //Skip rest of request } sendPong(); } else if (strncmp_P(buf, PSTR("GET /data"), 9) == 0) { /* POST request */ #ifdef DEBUG Serial.println(F("DATACOLLECTOR XML: sendind sensors data")); #endif while (wifly.gets(buf, sizeof(buf)) > 0) { //Skip rest of request } // discard rest of input // wifly.flushRx(); sendSensorsDataXML(); } else { // Unexpected request #ifdef DEBUG Serial.print(F("Unexpected: ")); Serial.println(buf); Serial.println(F("Sending 404")); #endif while (wifly.gets(buf, sizeof(buf)) > 0) { //Skip rest of request } // discard rest of input wifly.flushRx(); send404(); } } } }
boolean receivePacket(UDPpacket& packet, WiFly& wifly) { boolean ret; char buf[100]; ret = wifly.gets(buf, sizeof(buf)); packet.data += buf; // do { // rByte = wifly.read(); // //Serial.println(rByte); // packet.data = packet.data + (char) rByte; // if((char)rByte == '\n') { // break; // } // }while(rByte != -1); packet.dataLength = packet.data.length(); wifly.getHostIP(packet.ip, sizeof(packet.ip)); packet.port = wifly.getHostPort(); return true; // if(!packet.data.compareTo("-1")) // return false; // else // return true; }