I am not sure about the whole thing. But this is what I observed and thought is wrong. I might be completely wrong here. Here is the explanation :
Send ping periodically.
This has been done because, our logic of send ping only when data is unavailable looks erroneous. We clear the keep_alive timer on every send ok. It has been observed that send Ok is the ack from gen-tcp to app. So even when the network is gone, we get send_ok. This dismisses our assumption where we treat send_ok as ack and resets the keep_alive timer. If we send the ping periodically, irrespective of data from device, we can detect the network availability correctly.
I am not sure about the whole thing. But this is what I observed and thought is wrong. I might be completely wrong here. Here is the explanation :
Send ping periodically. This has been done because, our logic of send ping only when data is unavailable looks erroneous. We clear the keep_alive timer on every send ok. It has been observed that send Ok is the ack from gen-tcp to app. So even when the network is gone, we get send_ok. This dismisses our assumption where we treat send_ok as ack and resets the keep_alive timer. If we send the ping periodically, irrespective of data from device, we can detect the network availability correctly.