I'm working on a project where I want to send data from different sensors connected to the RPi 3B+
GPIO pins using python to both collect the data sent from the sensors to the pins and to send a POST request with that information embedded to an external HTTP server
. This HTTP server is going to perform as a control station for many other Pis.
The problem I have is that I can't get the HTTP control server to acknowledge what to do with the incoming POST requests sent by the Pi, so it can finally output some sort of text like "measure received".
How I'm doing it:
- Installed XAMPP on my PC to simulate the HTTP control server.
- Installed Raspbian 9 Lite on the Pi along with Python requests library.
- Tested connection from the Pi to the XAMPP server using links2 CLI explorer.
- Tested the example code from Python requests to POST data to the HTTP control server (IP: 192.168.0.9).
- The server responds with a 200 OK, but I don't really know how to proccess or even read that POST request.
This is the code in the raspberry.
pi@raspberrypi:~ $ more python_requests_example.py
import requests
payload = {'name' : 'test payload' }
p = requests.post('http://192.168.0.9/index.php', payload)
print(p.status_code)
When I run it, the code outputs the following:
pi@raspberrypi:~ $ python python_requests_example.py
200
I captured packets on the HTTP control server, and I see the both the POST and the 200 OK, I also see the payload embedded in the POST package. (https://i.stack.imgur.com/yClF4.jpg)
I opted not to install a whole web server (like LAMP) on the Pi because it won't be really used.
So, for the imputted data provided by the RPi sensors I'm using Python, and the plan is to then send this information to the HTTP control server.
I also would like to proccess this POST request purely with PHP (if possible or if not too hard). I also saw that I can POST from the RPi as json format, I don't have much experience with it, but if it would be better I can dig more about it.
If something is not clear please tell me and I'll try to complement.