I have a application, where a number of digimesh units are statically posistioned, and some that will be mobile. If the network is setup, and one of the units moves out of range of the network and loses connection…and it then returns into the network area and will try to re establish a connection…
I have been trying a few things to handle the errors( ie…try /except) that result when the mobile unit tries to send a message to the known network. I see there is a discovery path to find networks and maybe this one way to handle this…
The question is:
what is the best way to handle or manage losing the link connection to the network if lost, and to then find the network again and reconnect?
Are there any micropython examples for handling this type of case?
Thanks in advance…bert
Handling network disconnections in a digimesh application can be crucial. Utilizing a try/except approach is a good start. You can consider implementing a reconnection mechanism within the except block. Here’s a high-level example in MicroPython:
from digimesh import DigiMesh
# Your code to establish a connection goes here
# Your code to send data to the network goes here
except Exception as e:
# Handle disconnection and reconnection
print("Attempting to reconnect...")
# Other main loop tasks
if __name__ == "__main__":
In this example,
establish_connection() is a function that contains the code to connect to the digimesh network. If an exception occurs during the main loop (indicating a network issue), the script will print an error, attempt to reconnect, and then resume its operations.
Remember to customize this example based on your specific implementation, and consider using the digimesh discovery path if needed for dynamic network changes.
Please note that the actual code will depend on the specifics of your digimesh library and the way you’ve set up your network connection. Check the documentation for the library you’re using for more accurate guidance.
Thanks for the reply and coding!
After some more reading, trials and errors, I actually came up with something similar to what you are showing!
Glad it confirms my thinking!
I did not know if there was a different, or more accepted way to handle this, but seems like its working.
Currently testing things out in this area and noticing some other points that may be an issue as the network is lost or accepted.
I will try to keep this thread alive…