I have hardware based on a microcontroller with Ethernet communication.
There is a TCP server in the microcontroller.
To configure the hardware, I have an application made in C# for android.
The application, in turn, has a TCP client.
For the app to find my hardware, what I'm doing is pinging each of the addresses of the same network segment of my mobile. That is, if the IP address of my mobile is 192.168.0.xx, I ping from the address 192.168.0.1 to the address 192.168.0.255.
Those addresses that respond, I try to open a socket and send a data frame, if the answer is correct, I assume that I have found a hardware in my local network (there could be more than one connected)
Obviously those IP addresses that don't respond, or that the socket cannot be opened or that they respond to something wrong are discarded.
Those valid addresses are displayed in a list for the user to choose with which to interact.
Also, these valid addresses are saved in the application so that the next time the app is opened, it will automatically connect to the stored addresses, avoiding the scanning of the IP addresses.
This seems correct to me the first time the user installs the hardware and configures with the app
The problem is that I was informed that there are users that their routers are configured to renew their IP addresses once a month.
If this happens, the app should again perform a scan of all the IP addresses again, and this is somewhat cumbersome, since scanning all the IPs takes some time, I don't think users are happy configuring their app and hardware once a month.
Another cumbersome solution could be to use static IP addresses, but I don't think that's a good idea either.
Any suggestions on how to improve this?