Cheers all,
Working on a project where ESP8266 acts as client to webpage served by rpi. Need help formatting/defining POST command for ESP to send data and commands from ESP to webpage. Using Arduino IDE.
Expect it to be something similar to this:
client.print(String(“POST /motion?state=”) + String(pir_pin) + " HTTP/1.1\r\n" + "Host: " + http_site + “\r\n” + “Connection: close\r\n\r\n”);
Immediate goal is to send POST request to access python script on rpi.
Where test.php contains php code that is looking for Arm which is length 3. Arm is related to a python script where I want the ESP as a client to send the POST request to myipaddress and get it to run.
Hmmm, only thing I see wrong here is you have ‘Content_Type’, it should be ‘Content-Type’.
In general, when I have issues like this, I find that debugging on the ESP is rather difficult. I’ll usually use cURL on a desktop PC with the ‘-v’ flag to get it to spit out what is actually going over the wire. This way, you can determine if it’s an issue with the ESP or your server (Raspberry Pi). Also, you can determine any additional headers you might want to throw in.
That looks really interesting. Can you elaborate on the cURL on a desktop PC -v flag bit? Maybe list some steps that I could follow?
Regards,
Travis
I’ll let you know if your POST tip works. I’d like to think there’s no reason why it wouldn’t, but I’m coming across possible sudo issues…
If I elaborate more on what I’m doing maybe you (or anyone else) can help me get closer to success:
Using ESP8266 as client to a website hosted by RPI. The goal is to send POST commands from ESP to RPI using PHP isset($_POST… where the keyword Arm in the above POST command will be parsed by isset on RPI and trigger a python script.
If as you say there’s nothing wrong with the POST command above then I’m at a loss.
I’m also using the below GET/POST lines as a means of testing by modifying a blank webpage and/or document, but again, no luck.
These are all the headers that are actually being sent. Obviously you’d change out the server to your own. This will help you determine if the issue is on the ESP side or the PHP side (I’m no PHP expert, so you’re on your own there).
Another killer tool to help with these things is Postman: https://www.getpostman.com/. It’s a great tool for debugging HTTP Api’s.