Hello everyone, this is my first post. I choose to ask for some help since i am new with esp and that there aren't too many posts about my case.
So i am following post of random nerd tutorial to learn how to use esp32 and i tried to use http request with php in localhost like in some video (post method but interesting ) but i got -1 and 403 code errors.
I no longer know what to do after all the research i have done.
My code is here:
/*
Rui Santos
Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "my wifi";
const char* password = "my pass";
String serverName = "http://MyIP/ESP32/test.php"; //do a window + R => CMD then ipconfig
unsigned long lastTime = 0;
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("ESP32 IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if ((millis() - lastTime) > timerDelay) {
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String serverPath = serverName + "?temperature="+String(random(45));
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
Serial.print("URL: ");
Serial.println(serverPath);
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println("payload :");
Serial.println(payload);
Serial.println("----------------------------------");
http.end();%20free%20resources
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
My php script is simple: ( he is in an ESP folder in my root folder on wamp
<?php
if (isset($_GET['temperature']) && !empty($_GET['temperature'])) {
echo($_GET['temperature']);
}
?>
I got this in my serial monitor:
URL: http://MyIP/ESP32/test.php?temperature=27
HTTP Response code: -1
payload :
----------------------------------
My payload should be the value of the temperature and the http response code should be 200.
So i did some research an found in some narrow forum that -1 means that my firewall blocks my http request so i added a rule on my firewall that allows everything from the 80 port (HTTP) which i called ESP32
Then i tried my code again and i got a new error; the 403 one which says i don't have the permission
URL: http://MyIP/ESP32/test.php?temperature=30
HTTP Response code: 403
payload :
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache/2.4.54 (Win64) PHP/8.0.26 mod_fcgid/2.3.10-dev Server at MyIP Port 80</address>
</body></html>
----------------------------------
I got desperate since then because the answers are strange. I tried many things such as:
-
in this video where it is said that i should add some listen things to my http.cong file. I did this just as in the video with my IP, but nothing new .
-
I followed what was said in this post
HTTP GET Request 403 Error when trying to send Arduino RC522 data to mySQL - #3 by nberko4
I ended up modifying my phpmyadmin.conf where i don't even use a dtb
and the httpd-vhost.conf
Now i have -1 and 403 errors even if the firewall allows everything on the 80 port.
Do you have a solution to those problems or even an idea ?
Sorry if i made some mistakes while writing.