I'm working on a project that allows me to send specific data to a local Website (XAMPP server) but I tried this using arduino and it worked perfectly but when I tried to convert arduino into python i didn't succeed ,
Arduino Code :
Code: Select all
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200); //Serial connection
WiFi.begin("SSID", "PASS"); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
HTTPClient http; //Declare object of class HTTPClient
String code = "1245564331";
String url = "http://192.168.1.100:80/info.php?request=";
http.begin(url+code); //Specify request destination
// http.addHeader("Content-Type", "text/plain"); //Specify content-type
header
int httpCode = http.POST("Message from ESP8266"); //Send the request
String payload = http.getString(); //Get the response
payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
}
}
void loop() {
if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
}else{
Serial.println("Error in WiFi connection");
}
delay(30000); //Send a request every 30 seconds
}
Python code that bugged :
Code: Select all
import http.client
conn = http.client.HTTPConnection("http://192.168.8.100:80/info.php?request = sam")
conn.request("HEAD","/info.php?request = sam")
res = conn.getresponse()
print (res.status, res.reason)
# Result:
print("200 OK")
print("The pastebin URL is:%s"%pastebin_url)
Anyone can help me in converting it ?
Best Regards ,
Polos