I can't get the data String payload = http.getString();

I want to get the data sent by my function php: da.php

that is the code: da.php:

<?php echo 10; ?>

that is my arduino code

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "MAURO"; //replace with your own wifi ssid
const char* password = "R000@2021"; //replace with your own wifi ssid password
const char* host = "192.168.0.100";

WiFiClient client;

void setup() {

Serial.begin(115200);
delay(10); // We start by connecting to a WiFi network Serial.println();
Serial.println();
WiFi.mode(WIFI_OFF);
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}

void loop(){
HTTPClient http;
http.begin(client, "http://192.168.0.100/pr1/da.php");
int httpCode = http.GET();
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
http.end();
delay(5000);
}

the response of serial monitor is
-1

test the returned code (I see you print it, what do you get)

it gives me -1

-1 is not an HTTP return code

response -1

please, can you test the code, please

I don’t have your server on my local network nor the same network configuration…

Start from a library example making a get request for a resource on the public internet. When that works you know your network and basic code is OK

Then move to your local network - I assume you have an http server somewhere, store a json file and make the get request for that

When that works you know the local network is ok too

Then insert your own server and again make that work.

Take small steps with known code. Then take this learning to write your own code

—-

PS: please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It’s barely readable as it stands and I won’t spend a minute more studying stuff I can’t read nor easily copy in the IDE. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.