I’ve previously written code to use an ESP32 board as a simple HTTP POST server which works fine except for the unreliability of WiFi, so I’ve bought an ESP32-P4-ETH with an onboard Ethernet phy.
Using examples, I can get this to connect to my network and respond to ping etc., but can’t figure out how to get it to hear and respond to a POST message.
The working code from the Wifi board is shown below. I’ve stripped out all of the stuff which I don’t think is needed to help me with my problem;
Any help greatly appreciated.
#include <WiFi.h>
WiFiServer Server(80);
void loopHTTP()
{
char postMsg[128] = "";
int i=0;
WiFiClient loxListen = Server.available();
if (loxListen)
{
boolean currentLineIsBlank = true;
while (loxListen.connected())
{
while(loxListen.available())
{
char c = loxListen.read();
if (c == '\n' && currentLineIsBlank)
{
while(loxListen.available())
postMsg[i++] = loxListen.read();
ProcessReceivedMessage(); //Process the received message
loxListen.println("HTTP/1.0 200 OK");
loxListen.println("Content-Type: text/html");
loxListen.println();
loxListen.println("<HTML><BODY>OK</BODY></HTML>");
loxListen.stop();
}
else if (c == '\n')
currentLineIsBlank = true;
else if (c != '\r')
currentLineIsBlank = false;
}
}
}
}
void setup()
{
WiFi.begin("myssid", "mypassword");
Server.begin();
}
void loop()
{
loopHTTP();
delay(100);
}