User Manual

To read incoming data in the receive callback handler, you need to use the pTCP pointer, as shown in the sample code
below:
Example: Callback Based HTTP Request
The following example shows how you can register and use the two TCP callbacks, and performs a simple TCP
operation. It opens a TCP socket to an HTTP server using port 80, requests a page, displays any incoming response
data, and then waits for the HTTP server to close the TCP connection (which will show up as a disconnect callback):
// Set the callback handlers for RX and disconnect
tcp.setReceivedCallback(receive_callback);
tcp.setDisconnectCallback(disconnect_callback);
void receive_callback(void)
{
int c;
// Print out any bytes available from the TCP server
while ( (c = tcp.read())> 0 )
{
Serial.write( (isprint(c) || iscntrl(c)) ? ((char)c) : '.');
}
}
void disconnect_callback(void)
{
Serial.println();
Serial.println("-------------------");
Serial.println("DISCONNECT CALLBACK");
Serial.println("-------------------");
Serial.println();
}
#include <adafruit_feather.h>
#define WLAN_SSID "SSID"
#define WLAN_PASS "PASSWORD"
#define WLAN_SECURITY ENC_TYPE_AUTO
#define TCP_DOMAIN "www.adafruit.com"
#define TCP_FILENAME "/testwifi/index.html"
#define TCP_PORT 80
void receive_callback ( void );
void disconnect_callback ( void );
AdafruitTCP tcp;
void setup()
{
Serial.begin(115200);
// Wait for Serial port to connect. Needed for native USB port only
while (!Serial) { delay(1); }
// Attempt to connect to the AP using the specified SSID/key/encoding
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 80 of 202