Hi @ all,
by working on a MQTT project using IoT SDK v1.0.0 (SDK v14.1) we discovered problems with TCP packets not being transmitted.
Using lwIP, transmitting TCP packets appears to work as follows:
- Put packet (or multiple) on the tx queue using tcp_write(...)
- Flush the queue to transmit packets using tcp_output(...)
In mqtt_transport_lwip.c, which "forwards" MQTT packets to lwIP, the function mqtt_client_tcp_write() does call tcp_write() but not tcp_output().
The reason why TCP packets are transmitted most of the time seems to be because tcp_output() is called in some handlers of lwIP. For instance in tcp_close_shutdown_fin() in tcp.c which seems to be called upon receiving a FIN message by the peer.
We discovered this issue by monitoring the traffic with Wireshark. Our last TCP packet was transmitted only after the nRF received a FIN message.
We successfully fixed this issue by *adding tcp_output((struct tcp_pcb )p_client->tcp_id); in mqtt_transport_lwip.c after line 156.
We are not sure if this is the best solution, but it worked for us. Furthermore the lwIP MQTT implementation in lwip/arc/apps/mqtt/mqtt.c uses the same principle by calling tcp_output() at the end of mqtt_output_send().
Best Regards, Carl