Check if my device is connected

Hello everyone.

My device periodically grabs some data from Internet. I want that my device starts to search another networks if the current network fails.

How is the proper way to check it? I’m using is_linked(), but I experienced some weird behaviours (for example, if I turn off my network and some time later I turn it on, my device is unable to connect to it).