I am using a W5500 interfaced via SPI with an STM32F411 to perform transfers of bytes (less than 256) received from one of the serial ports of the STM32 and transmitted with HTTP protocol to a server that receives and record them on a db.
Basically, the STM32 receives via serial from another micro a buffer of bytes that maintains and transmits them when possible.
I would like to diagnose the status of the HTTP connection before the http request, e.g. during the period when I have nothing to transmit check at set time intervals whether the server is still reachable or not and notify that in advance.
I had thought about an ICMP ping but when i try to open the socket it always fail:
switch(getSn_SR(s))
{
case SOCK_CLOSED:
close(s);
IINCHIP_WRITE(Sn_PROTO(s), IPPROTO_ICMP); // set ICMP Protocol
if(socket(s,Sn_MR_IPRAW,3000,0)!=0){ // open the SOCKET with IPRAW mode, if fail then Error
printf( "\r\n socket %d fail r\n", (0)) ;
I had also thought about using a TCP Keep-Alive function, but I don’t know if that is a good idea.
It depends on what level you need to check. If you want to check at TCP/IP or other network level, then you do keep-alive and other standard stack functions (check if they are available in the chip you have chosen). However if you want to test HTTP (or any other port application listens to) then you need to do it at the application level - open port to HTTP server and perform small communication or keep port open and sometimes make a short control data exchange. What you say may be something already implemented in e.g. MQTT - check its spec. You can describe your own simple proto, for example having starting byte of 0 for just this byte ping exchange and having byte of 1 as a marker of normal data.
I can’t use MQTT cause I have to use an already existing HTTP server.
I would like to use ICMP to verify with a certain periodicity that I can reach my destination web server but the creation of this type of socket fails. See previous code snippet.
Regularly request some test page from the web server to see if it is available. Working ping does not mean web server is up and running and is available.