Public bug reported: Ubuntu 20.04, Linux Mint 20.3, amd64 network-manager 1.22.10-1ubuntu2.3
I wanted to script nmcli to make configuration of WiFi of IoT device easy but it is not an easy task. I assume this is a bug in nmcli design, not specific to Ubuntu... The problem. IoT devices with WiFi has to be configured in some way. WiFi parameters could be hardcoded in the code or there could be a way to configure WiFi in other way, like that device is switched to AP mode and user can connect and configure the device. ESP32 devices have WiFi Manager library for WiFi provisioning https://dronebotworkshop.com/wifimanager/ A nice example of such device is NerdMiner based on ESP32, https://github.com/BitMaker-hub/NerdMiner_v2 NerdMiner in WiFi provisioning mode creates WiFi AP with SSID NerdMinerAP and WiFi password is MineYourCoins. I found it really boring to configure this device manually and I tried to script it. It is boring to wait until user notebook founds WiFi "NerdMinerAP, it can take a minute or two, so I tried to use nmcli to automate the process... Issues: 1) I know I want to connect to AP NerdMinerAP but until notebook founds it, I cannot do that. There is no way to force nmcli to wait for NerdMinerAP: $ nmcli --wait 120 dev wifi connect NerdMinerAP Error: No network with SSID 'NerdMinerAP' found. 2) nmcli dev wifi scan returns always "Success" and error code 10. NerdMinerAP is not available: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? Success 10 NerdMinerAP is visible, error code is 10, again :-(: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? 86:FC:E6:11:22:33 NerdMinerAP Infra 1 135 Mbit/s 90 ▂▄▆█ WPA2 Success 10 --- It is possible to script that action but it is not as easy as it could be. This is a working solution: ``` #!/bin/sh BSSID="NerdMinerAP" [ -n "$1" ] && BSSID="$1" # wait until provisioning AP is visible.. while sleep 2; do echo "Waiting for WiFi $BSSID..." R="$(nmcli dev wifi list 2> /dev/null | grep $BSSID)" [ -n "$R" ] && break #nmcli device wifi rescan 2>/dev/null done # We have found it, connect to it! echo "WiFi $BSSID detected, connecting..." nmcli dev wifi connect "$BSSID" # show connection details nmcli connection show --active nmcli dev wifi show # show QR code!! Shows password... ``` ** Affects: network-manager (Ubuntu) Importance: Undecided Status: New ** Description changed: Ubuntu 20.04, Linux Mint 20.3, amd64 network-manager 1.22.10-1ubuntu2.3 I wanted to script nmcli to make configuration of WiFi of IoT device easy but it is not an easy task. I assume this is a bug in nmcli design, not specific to Ubuntu... The problem. IoT devices with WiFi has to be configured in some way. WiFi parameters could be hardcoded in the code or there could be a way to configure WiFi in other way, like that device is switched to AP mode and user can connect and configure the device. ESP32 devices have WiFi Manager library for WiFi provisioning https://dronebotworkshop.com/wifimanager/ A nice example of such device is NerdMiner based on ESP32, https://github.com/BitMaker-hub/NerdMiner_v2 NerdMiner in WiFi provisioning mode creates WiFi AP with SSID NerdMinerAP and WiFi password is MineYourCoins. I found it really boring to configure this device manually and I tried to script it. It is boring to wait until user notebook founds WiFi "NerdMinerAP, it can take a minute or two, so I tried to use nmcli to automate the process... Issues: 1) I know I want to connect to AP NerdMinerAP but until notebook founds it, I cannot do that. - There is no way to force nmcli to wait for NerMinerAP + There is no way to force nmcli to wait for NerdMinerAP: $ nmcli --wait 120 dev wifi connect NerdMinerAP Error: No network with SSID 'NerdMinerAP' found. 2) nmcli dev wifi scan returns always "Success" and error code 10. NerdMinerAP is not available: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? Success 10 NerdMinerAP is visible, error code is 10, again :-(: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? - 86:FC:E6:11:22:33 NerdMinerAP Infra 1 135 Mbit/s 90 ▂▄▆█ WPA2 + 86:FC:E6:11:22:33 NerdMinerAP Infra 1 135 Mbit/s 90 ▂▄▆█ WPA2 Success 10 --- It is possible to script that action but it is not as easy as it could be. This is a working solution: - ``` #!/bin/sh BSSID="NerdMinerAP" [ -n "$1" ] && BSSID="$1" # wait until provisioning AP is visible.. while sleep 2; do - echo "Waiting for WiFi $BSSID..." - R="$(nmcli dev wifi list 2> /dev/null | grep $BSSID)" - [ -n "$R" ] && break - #nmcli device wifi rescan 2>/dev/null + echo "Waiting for WiFi $BSSID..." + R="$(nmcli dev wifi list 2> /dev/null | grep $BSSID)" + [ -n "$R" ] && break + #nmcli device wifi rescan 2>/dev/null done # We have found it, connect to it! echo "WiFi $BSSID detected, connecting..." nmcli dev wifi connect "$BSSID" # show connection details nmcli connection show --active nmcli dev wifi show # show QR code!! Shows password... ``` -- You received this bug notification because you are a member of Ubuntu Touch seeded packages, which is subscribed to network-manager in Ubuntu. https://bugs.launchpad.net/bugs/2045186 Title: nmcli is script unfriendly Status in network-manager package in Ubuntu: New Bug description: Ubuntu 20.04, Linux Mint 20.3, amd64 network-manager 1.22.10-1ubuntu2.3 I wanted to script nmcli to make configuration of WiFi of IoT device easy but it is not an easy task. I assume this is a bug in nmcli design, not specific to Ubuntu... The problem. IoT devices with WiFi has to be configured in some way. WiFi parameters could be hardcoded in the code or there could be a way to configure WiFi in other way, like that device is switched to AP mode and user can connect and configure the device. ESP32 devices have WiFi Manager library for WiFi provisioning https://dronebotworkshop.com/wifimanager/ A nice example of such device is NerdMiner based on ESP32, https://github.com/BitMaker-hub/NerdMiner_v2 NerdMiner in WiFi provisioning mode creates WiFi AP with SSID NerdMinerAP and WiFi password is MineYourCoins. I found it really boring to configure this device manually and I tried to script it. It is boring to wait until user notebook founds WiFi "NerdMinerAP, it can take a minute or two, so I tried to use nmcli to automate the process... Issues: 1) I know I want to connect to AP NerdMinerAP but until notebook founds it, I cannot do that. There is no way to force nmcli to wait for NerdMinerAP: $ nmcli --wait 120 dev wifi connect NerdMinerAP Error: No network with SSID 'NerdMinerAP' found. 2) nmcli dev wifi scan returns always "Success" and error code 10. NerdMinerAP is not available: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? Success 10 NerdMinerAP is visible, error code is 10, again :-(: $ nmcli dev wifi list | grep NerdMinerAP; nmcli dev wifi list bssid NerdMinerAP; echo $? 86:FC:E6:11:22:33 NerdMinerAP Infra 1 135 Mbit/s 90 ▂▄▆█ WPA2 Success 10 --- It is possible to script that action but it is not as easy as it could be. This is a working solution: ``` #!/bin/sh BSSID="NerdMinerAP" [ -n "$1" ] && BSSID="$1" # wait until provisioning AP is visible.. while sleep 2; do echo "Waiting for WiFi $BSSID..." R="$(nmcli dev wifi list 2> /dev/null | grep $BSSID)" [ -n "$R" ] && break #nmcli device wifi rescan 2>/dev/null done # We have found it, connect to it! echo "WiFi $BSSID detected, connecting..." nmcli dev wifi connect "$BSSID" # show connection details nmcli connection show --active nmcli dev wifi show # show QR code!! Shows password... ``` To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/2045186/+subscriptions -- Mailing list: https://launchpad.net/~touch-packages Post to : touch-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~touch-packages More help : https://help.launchpad.net/ListHelp