How should modem disconnects/reconnects be handled in unstable connections? (IDFGH-11995) #527
Replies: 8 comments
-
Hi, the general suggestion would be to follow the reconnection procedure shown in this example: As for unstable environments, it's hard to give a recommendation, other than to wait a bit with some back-off time and try again later?
Could you please elaborate? The modem library doesn't correctly enter the data mode, or is stuck somewhere? If so, this could be a real issue, because the modem library must correctly restart all operations and work seamlessly without hard resets! we've had a few similar reports, always turned out that esp_modem could deinit and re-init properly. Other ideas to approach the issue is to basically listen to all PPP state change events and react whenever the connection breaks/starts to terminate (should come sooner than |
Beta Was this translation helpful? Give feedback.
-
Hi and thanks for the detalied response. When I was saying that it didn't work I meant that the modem wasn't accepting the reconnect commands. Turns out I just needed to switch back to command mode... However, with your guidelines I have come to a better solution but know I have other problems. The connect code is as follows:
Basically I:
This works correctly (there's some issue where the system hangs for 30 seconds but I will worry about that later). However, now when the connection is unstable or bad (I simulated this by disconnecting the antena) several things cna happen:
From there the system WDT timer timeouts after 3 minutes and resets everything
In both cases the issue seems clear to me: the system doesn't detect something is wrong with the connection. And I think this is what you were trying to explain here:
So do you thing that checking for an IP should give me information on the connection state? Because from case @2 the IP is acquired. Does this mean that I will have to continuously switch between command mode and data mode to get the IP address via AT command? |
Beta Was this translation helpful? Give feedback.
-
Yes, this could be an indication whether we'd be able to connect before we start connecting, so I think it's useful as a quick check.
of course, this won't help when we're already connected and we lose the IP.
Note, that this library also supports CMUX mode, you can run AT commands while connected. But in general, I think what could be helpful in general would be some kind of try-connect-backoff mechanism with early feedback. Here the "try-connect" part could be checking the rssi, maybe trying to acquire an IP, checking PPP phase events. |
Beta Was this translation helpful? Give feedback.
-
That is exactly what happens: The HTTP connections fail but there are no events from PPP even after enabling I'm considering using CMUX mode so that at least I can check the IP address continuously. However, when I change to that mode the modem doesn't connect:
The modem aparently enters CMUX mode successfully (ignore the mentions to MODE_DATA on the log, I just haven't changed that) but then I can see from the PPP events that the connection fails. On that fail the system retries the connection process (done by me) but at this point the watchdog ends up being triggered. Taking a look at the example it doesn't seem like I'm doing anything differently. On some cases the WDT triggers inmediatelly on the first connect try:
|
Beta Was this translation helpful? Give feedback.
-
Yes, this possibly means the connection got unstable somewhere between the device and the cellular network, but the PPP connection and lower layers are stable. There's not much that could be done on the modem layer, the only suggestion would be to periodically check connection on the application layers, like pinging some addresses, using TCP keepalive, MQTT pings, etc.
I think that's probably not needed after all (in your application), as checking the IP address makes only sense before you start connecting.
The log says that the
A quick and easy check is to run the (unchanged) example with your device. Chances are that there might still be some issues with CMUX mode with your device |
Beta Was this translation helpful? Give feedback.
-
I have seen the issue device lost IP after running for a day, after research I think this is due to DHCP Lease Renewal: If your IoT device is obtaining its IP address dynamically using DHCP (Dynamic Host Configuration Protocol), the lease duration provided by the ISP might be expiring after a day. This would require the device to renew its IP address periodically. Ensure that your device is configured to renew its DHCP lease appropriately. I am looking for a way to retrieve the IP address instead of hard reset device. |
Beta Was this translation helpful? Give feedback.
-
I don't think this is a issue for us. Due to power usage concerns we only connect to the internet once or twice a day and this connection (if there isn't an OTA update pending) lasts fors 30-40 seconds. |
Beta Was this translation helpful? Give feedback.
-
converted this to a discussion as there's not much we can do at the library level, just to give a few recommendations for general use cases |
Beta Was this translation helpful? Give feedback.
-
Answers checklist.
General issue report
We currently have ~1000 devices deployed across Spain with a SIM7080G modem.
In general lines they work well, even the OTA.
However, in general we cannot guarantee a 100% success when it comes to updating via OTA or simply connecting to the internet.
The devices connect once every 24h, and sometimes that connection fails and so it becomes a connection every 48 or even 72h.
Up until now we were doing the following on
IP_EVENT_PPP_LOST_IP
:So basically every time the connection got lost we would call
modem_restart()
which would basically initialize the modem again viaesp_modem_get_signal_quality()
andesp_modem_set_mode(dce, ESP_MODEM_MODE_DATA);
This doesn't work. And so what ends up working is straight reseting the ESP via
esp_restart()
and reseting the module by powering it down and powering it up again.With this procedure the modem has a higher success of obtaining an IP. But the problem is that sometimes it takes 10-12min for that connection to be achieved. This is unacceptable mainly from a power usage standpoint.
So the question is, what should be the correct procedure for forcing the SIMCOM modem to try to reconnect?
Beta Was this translation helpful? Give feedback.
All reactions