I am working with esp8266, and I want to access some data from my php laravel apis hosted on my laptop, so far I am unable to do so.
I have set up a mobile hotspot on my laptop and connected my phone to the laptop's hotspot.
My laptop IPv4 is : http://192.168.100.40/
and postman gives appropriate responses.
Also I check on my mobile device by connecting it to laptop's hotspot and I get appropriate responses.
here is my esp8266 code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h>
// #include <HttpClient.h>
#include <ESP8266mDNS.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
DNSServer dnsServer;
WiFiManager wifiManager;
void setup() {
Serial.begin(9600);
// WiFi.disconnect(true);
// ESP.eraseConfig();
// Connect to WiFi
WiFiManager wifiManager;
wifiManager.setTitle("esp");
wifiManager.setDarkMode(true);
wifiManager.autoConnect("esp");
// Print MAC address
Serial.print("MAC address: ");
Serial.println(WiFi.macAddress());
// Configure mDNS
if (!MDNS.begin("esp")) {
Serial.println("Error setting up MDNS responder!");
while(1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
// Start DNS server
dnsServer.start(53, "*", WiFi.softAPIP());
server.begin();
Serial.println("HTTP server started");
Serial.print("entering handle root");
// Retrieve users data
WiFiClient client;
HTTPClient http;
String url = "http://192.168.100.40:8000/api/users";
if (http.begin(client, url)) {
int httpCode = http.GET();
if (httpCode > 0) {
Serial.print(httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println("HTTP GET request successful");
Serial.println("Response: " + payload);
}
} else {
Serial.println("HTTP GET request failed");
}
http.end();
} else {
Serial.println("Unable to connect to server");
}
}
void loop() {
server.handleClient();
MDNS.update();
}
Serial monitor response: HTTP GET request failed