We created a website hosted by 000webhost and we're trying to post data from our nodeMCU to the database using the sketch below, but the database doesn't seem to show any received data. How do you fix this?
and below is the php code to rtecieve the data:
#include <ESP8266WiFi.h>
const char* ssid = "Jino";
const char* pass = "myinternet";
char server[] = "cdgresearch.000webhostapp.com";
WiFiClient client;
int led = 2;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,pass);
pinMode(led,OUTPUT);
digitalWrite(led, HIGH);
Serial.println("Connecting to: ");
Serial.println(ssid);
Serial.print("Connecting");
while(WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.print(".");
}
delay(300);
digitalWrite(led, LOW);
Serial.println();
Serial.println("Successfully connected to the network");
Serial.print("NodeMCU IP Address: ");
Serial.println(WiFi.localIP());
if (client.connect(server, 80)){
String data = "incoming=fromDuino&incoming2=FROMDUINO2";
client.println("POST /tag.php? HTTP/1.1");
client.println("Host: cdgresearch.000webhostapp.com");
client.println("User-Agent: 8266/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.print("\n\n");
client.println(data);
client.stop();
Serial.println("Connected to server");
}
else{
Serial.println("Failed to Connect to server...");
}
client.stop();
Serial.println("Disconnected from Server");
}
void loop() {
// put your main code here, to run repeatedly:
}