1

I know this is a Very Bad Idea™️ with regards to security, I'm ok with that. (Everything is over SSL, so meh.)

I have a small wandering Raspberry Pi powered bot, that I'd like to keep in touch with. Which means the bot should try its darnedest to connect to my server. It has Wifi, but no cell chip.

I live in a techie area, so there are plenty "Free WiFi Just Enter Your Email or accept our TOS" access points, so even an open SSID doesn't mean a usable SSID.

Is there a way (small app or script or whatever) that will cycle through all open access points until it finds one that allows a connection to the server - AND will resume scanning if it gets cut off or if the throughput gets too weak?

I'm fine running python, bash, whatever raspbian (Debian) supports. And the "outages" when it doesn't have any connection are the cost of doing business.

1

I do not know of any ready-made tool that can be used for your purpose, but you could build one yourself.
The necessary tools and programs are available on Raspbian.


Luckily, wpa-supplicant allows for interactive control of scanning for networks and manually connecting to networks.
To be specific you can either use the program wpa_cli or use the wpa_ctrl API in c, which is also the basis for wpa_cli.

wpa_cli allows you to

  1. scan for SSIDs and show results:

    wpa_cli -i wlan0 SCAN
    wpa_cli -I wlan0 SCAN_RESULTS
    
  2. get detailed information about the SSIDs (including signal strength, encryption, etc.):

    wpa_cli -i wlan0 BSS 0
    

    Hint: replace 0 with the idx of the SSID from the SCAN_RESULTS output you want to know more about.

  3. connect to a specific SSID that fits your criteria

    sudo wpa_cli -i wlan0 ADD_NETWORK
    sudo wpa_cli -i wlan0 SET_NETWORK 0 ssid "SSID"
    sudo wpa_cli -i wlan0 SET_NETWORK 0 psk "passphrase"
    sudo wpa_cli -i wlan0 ENABLE_NETWORK 0
    

    Note: replace 0 with the number that is printed to stdout after ADD_NETWORK

  4. disconnect from SSID

    sudo wpa_cli -i wlan0 DISCONNECT
    

You will have to do some parsing of the output of those commands obviously.


In order to check, if the connection to your server is possible after connecting to the SSID, you could simply evaluate the results of a ping call.


And now you simply have to put everything together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.