I am trying to send data to an HTTP page but I get a watchdog error.
#include <ESP8266WiFi.h>
const char* ssid = "---"; // Enter SSID here
const char* password = "---"; // Enter Password here
char server[] = "requestb.in";
String PostData = "Hello World";
WiFiClient client;
void setup() {
Serial.begin(9600);
delay(1000);
Serial.println("Connecting to ");
Serial.println(ssid);
//connect to your local wi-fi network
WiFi.begin(ssid, password);
//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
if (client.connect(server, 80)) {
// Make a HTTP request:
Serial.println("connected");
client.println("POST /1ip84q91 HTTP/1.1");
client.println("Host: requestb.in");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
}
It connects to the network but doesn't do the POST, what am I doing wrong? Thank you.
I'm using
Arduino IDE 1.6.4
NodeMCU with ESP8266
This is a test to be able to integrate it into a code that I am working on.