HTTP Post ESP8266 + Arduino Zero

Hi all!

I'm running this sketch, but I get no response...

#include "WiFiEsp.h"



char ssid[] = "Twim";            // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "arduino.cc";

// Initialize the Ethernet client object
WiFiEspClient client;

void setup()
{
	// initialize serial for debugging
	Serial.begin(115200);
	// initialize serial for ESP module
	Serial1.begin(9600);
	// initialize ESP module
	WiFi.init(&Serial1);

	// check for the presence of the shield
	if (WiFi.status() == WL_NO_SHIELD) {
		Serial.println("WiFi shield not present");
		// don't continue
		while (true);
	}

	// attempt to connect to WiFi network
	while ( status != WL_CONNECTED) {
		Serial.print("Attempting to connect to WPA SSID: ");
		Serial.println(ssid);
		// Connect to WPA/WPA2 network
		status = WiFi.begin(ssid, pass);
	}

	// you're connected now, so print out the data
	Serial.println("You're connected to the network");
	
	printWifiStatus();

	Serial.println();
	Serial.println("Starting connection to server...");
	// if you get a connection, report back via serial
	if (client.connect(server, 80)) {
		Serial.println("Connected to server");
		// Make a HTTP request
		client.println("GET /asciilogo.txt HTTP/1.1");
		client.println("Host: arduino.cc");
		client.println("Connection: close");
		client.println();
	}
}

void loop()
{
	// if there are incoming bytes available
	// from the server, read them and print them
	while (client.available()) {
		char c = client.read();
		Serial.write(c);
	}

	// if the server's disconnected, stop the client
	if (!client.connected()) {
		Serial.println();
		Serial.println("Disconnecting from server...");
		client.stop();

		// do nothing forevermore
		while (true);
	}
}


void printWifiStatus()
{
	// print the SSID of the network you're attached to
	Serial.print("SSID: ");
	Serial.println(WiFi.SSID());

	// print your WiFi shield's IP address
	IPAddress ip = WiFi.localIP();
	Serial.print("IP Address: ");
	Serial.println(ip);

	// print the received signal strength
	long rssi = WiFi.RSSI();
	Serial.print("Signal strength (RSSI):");
	Serial.print(rssi);
	Serial.println(" dBm");
}

This is the output
"Starting connection to server...
Connected to server

Disconnecting from server..."

What should I see on the serial monitor?

What is the relationship between the GET command that the code you posted makes and the POST in your thread title?

What should I see on the serial monitor?

Now? Or after you add the necessary code that you are missing?

   while(client.connected())
   {
	while (client.available())
        {
		char c = client.read();
		Serial.write(c);
	}
   }

You've already told the server to close the connection, so, once you've read all the data that it returns, stopping the client is not not necessary. Going into an infinite loop is not necessary.

The problem that you have now is that it takes only a few (hundred) nanoseconds between sending the GET request and seeing whether the server has sent back any data. In that time, of course it hasn't. So, you read all of nothing, and forcibly close the connection, loosing any data. Then, you stick your head in the sand and do nothing.

Hi PaulS,

yes,my mistake on thread title ::slight_smile: ; however, I've tried another example sketch on the WiFiEsp library

,WebClient Repeating and it works.

Thank you for your reply.