I want a ESP8266 to get temperature data and then send it via WiFi to an Arduino over my LAN. The Arduino is connected to the LAN through an ethernet shield. The Arduino will then serve a simple webpage. I want to do it this way because the ESP will be battery powered and can be put into deep sleep mode to save battery power. I have all the hardware working, but I have no idea on how to send the temperature data from the ESP to the Arduino so it can be displayed on the webpage.
Any guidance would be greatly appreciated.
in esp8266 begin WiFiServer at port 2323. in Arduino connect EthernetClient client to esp8266 IP address and port 2323. everything you write or print to client will be received in WiFiClient returned by WiFiServer for this connection.
If the Arduino is acting as a web server, then the obvious way in my mind is to have the esp send the sensor reading as an http GET or POST request, like this:
GET /sensor.html?temp=30.5
The Arduino would detect that the "file" sensor.html was being requested and therefore know to look for the new sensor reading.
For other requests, there would be a different "file" requested, or no file requested (="/index.html"), the Arduino would serve up the page displaying the last value received.
Thanks for the input. I have never used the "GET" or "POST" requests before. Time to study I guess.
Is there a reason to use port 2323 or are other ports just as suitable?
TCP ports under 1023 are reserved as default ports for known protocols. 23 is default port for telnet which is plain socket communication without need of a protocol ('handshaking' is optional). Often 'doubled' port numbers are used for alternative access, like 8080 as alternative for http protocol default port 80, or 2323 indicating telnet.
Telnet can be accessed from telnet client which is a simple way to test your server. But telnet client on linux tries 'handshaking' protocol after connection on port 23 and doesn't try it on other port.
If you opt for a http request, you must hold to the protocol, but there is no need to have a fake filename in the GET line like Paul suggest. You can write there what you want and for example one character is simpler to parse and handle like a string. For example a character can be used in switch statement.
Juraj:
If you opt for a http request, you must hold to the protocol, but there is no need to have a fake filename in the GET line like Paul suggest. You can write there what you want and for example one character is simpler to parse and handle like a string. For example a character can be used in switch statement.
Yes, these files (usually) don't exist on any file system when an Arduino is the web server. The "fake" filename is really just an identifying string that the Arduino can use to determine what is being requested by the client.
42etus:
I have never used the "GET" or "POST" requests before.
Oh yes you have, millions of times! But without knowing it. Every time you access a web page on your browser, that is a GET request.
PaulRB:
Yes, these files (usually) don't exist on any file system when an Arduino is the web server. The "fake" filename is really just an identifying string that the Arduino can use to determine what is being requested by the client.
with SD card or esp8266 SPIFFS the web server on Arduino can serve static files or logging files. here is my WebServer.ino
Thanks again, guys (gals?). juraj, I have been studying the code you linked to and it is really helping me understand.
42etus:
Thanks again, guys (gals?). juraj, I have been studying the code you linked to and it is really helping me understand.