void readResponse (char *buf, int max_len, int content_len) { // Read content. int len = wifly.readBytes(buf, max_len > content_len ? content_len : max_len); buf[len] = '\0'; // insurance // Flush buffer. while (wifly.available() > 0) { wifly.read(); } }
/* Connect the WiFly serial to the serial monitor. */ void terminal() { while (1) { if (wifly.available() > 0) { Serial.write(wifly.read()); } if (Serial.available() > 0) { wifly.write(Serial.read()); } } }
void loop() { int available; if (wifly.isConnected() == false) { Serial.println("Connecting"); if (wifly.open("192.168.1.100", 4001)) { Serial.println("Connected"); } else { Serial.println("Failed to open"); } } else { available = wifly.available(); if (available < 0) { Serial.println("Disconnected"); } else if (available > 0) { Serial.write(wifly.read()); } } }