How to check (programmatically) if connected
-
Hi there,
Just got my Omega2+ yesterday, and can't believe how easy it is to get up and running.
For my project though, I'm trying to figure out a way to programmatically determine whether or not I'm connected to wifi. Sure, I supposed I could call ifconfig, and grep out something to determine, but I'd rather have either an API method, or some more reliable way.
Does this exist?
-
@Dwayne-King I use your grep method on ifconfig every 10 minutes to look for the presence of apcli0 and a partial match to 'inet addr:192.168.' - if not found I call wifimanager. Works well for me as I have a list of over 40 possible access points in 192.168.. range while my devices travel
-
Do you only care if you are connected to WiFi, or do you also care if your packets can go anywhere upstream?
ie, how do you want to handle the case of being connected to a router, when the cable modem upstream of it is down?
-
Thanks for your replies. Let me describe a little better what I'm trying to do.
I built a simple data logger, that I want to be smart enough to turn only attempt to transfer data to my server when it's "home". If I'm out driving in my car with it, I don't want it to be trying constantly to get to it's server. Heck, I could even turn wifi off at that point and conserve battery.
Does this make sense?