I'm working on a project where a mobile app can find and pair with a headless raspberry pi running Pi OS (Debian Buster Port) over bluetooth, send it an ssid and password and it'll create and hop on the wifi network. Everything is working but I really don't like this code that creates the wifi connection. I need the delays in there because there's no callback that I know of for the os commands and even after they finish there is some hardware delay. Just throwing out to the hive mind if there is a better way:
os.system("nmcli connection delete {}".format(ssid))
time.sleep(2)
os.system("nmcli r wifi off")
time.sleep(2)
os.system("nmcli r wifi on")
time.sleep(5)
os.system("nmcli dev wifi rescan")
time.sleep(5)
os.system("nmcli d wifi connect \"{}\" password \"{}\"".format(ssid, pw))
using the nmcli (Network Manager Command Line Interface).
Sleep seconds are guestimates - I'm looking for a way to get a callback
nmclidocs about status reporting?sudo raspi-config nonint do_wifi_ssid_passphrase <ssid> <passphrase> [hidden] [plain]so if that works i'll update the questioncan't stand code like this... give an explanation instead ... maybe something likeevent driven code would be less prone to errors