My esp8266 is now connected to wifi however the datas won't display

Here's the code:

    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>
    int Led_OnBoard = 2;                  // Initialize the Led_OnBoard 
    const char* ssid = "";           // Your wifi Name  
    const char* password = "";          // Your wifi Password 
    const char *host = "***.***.*.*"; //Your pc or server (database) IP, example : , if you are a windows os user, open cmd, then type ipconfig then look at IPv4 Address.

    void setup() {
        // put your setup code here, to run once:
        pinMode(Led_OnBoard, OUTPUT);       // Initialize the Led_OnBoard pin as an output
        WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
         WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot
        WiFi.begin(ssid, password);     //Connect to your WiFi router
        // Wait for connection
        while (WiFi.status() != WL_CONNECTED) {
            digitalWrite(Led_OnBoard, LOW);
            digitalWrite(Led_OnBoard, HIGH);

        digitalWrite(Led_OnBoard, HIGH);
        //If connection successful show IP address in serial monitor
        Serial.println("Connected to Network/SSID");
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());  //IP address assigned to your ESP

    void loop() {
        // put your main code here, to run repeatedly:
        HTTPClient http;    //Declare object of class HTTPClient
        String PirValueSend, postData;
        int pirvalue=analogRead(A0);  //Read Analog value of PIR
        PirValueSend = String(pirvalue);   //String to interger conversion
        //Post Data
        postData = "pirvalue=" + PirValueSend;
        http.begin("http://***.***.*.*/thesis/database/database.php");     //Specify request destination
        http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
        int httpCode = http.POST(postData);   //Send the request
        String payload = http.getString();    //Get the response payload
        if(pirvalue > 0 )
            Serial.println(httpCode);   //Print HTTP return code
            Serial.println(payload);    //Print request response payload
            Serial.println("Pir Value=" + PirValueSend);
            Serial.println("No motion.");
        http.end();  //Close connection
        // delay(4000);  //Here there is 4 seconds delay plus 1 second delay below, so Post Data at every 5 seconds
        digitalWrite(Led_OnBoard, LOW);
        digitalWrite(Led_OnBoard, HIGH);
  • what's your question? – jsotola Mar 2 at 4:05
  • How to fix this? It can't connect to wifi – Chanix Mar 2 at 4:22
  • 1
    run one of the example sketches that come with the library – jsotola Mar 2 at 4:53
  • Thankyou it's connected now however my datas won't display in my homepage – Chanix Mar 2 at 5:17
  • 2
    No, it doesn't display anything. Its supposed to display the value from my sensor to my homepage – Chanix Mar 2 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.