Hotspot mode toggle on Librem 5

I’m using my L5 as a daily driver these days, and have already discovered the great joy of firing a script to do frequent tasks using an icon in the app drawer.

One task I find myself doing a lot of is toggling hotspot mode. I’d love to be able to call the same code that does this task when accessing it from Settings > Wi-Fi > vertical ellipsis menu > Turn On Wi-Fi Hotspot…

Does anyone know the CLI way to call that action?

Thanks!

4 Likes

I didn’t know the answer to your question either, but I got curious and looked into the code of Gnome Settings Manager, which is the actual name for the Settings app. Turns out that the code for the hotspot UI is entirely in cc-wifi-hotspot-dialog.c. The part where the action happens seems to be inside the cc_wifi_hotspot_dialog_response function.

That function is for handling the UI response to hitting a button in the hotspot dialog. If you hit the Turn On button, the UI code talks to the NetworkManager client library, telling it to make stuff happen.
So the code itself doesn’t give us a simple CLI invocation that we could copy and paste. However, NetworkManager comes with a CLI tool, nmcli, which comes pre-installed on the Librem 5 and which should cover most of NetworkManager’s feature set.

One way to toggle the hotspot in the CLI would be: look at the calls to NetworkManager one by one and try to replicate that via nmcli calls.

However, there’s still an easier way. Note that the UI handler code creates a NetworkManager connection named Hotspot but never bothers to delete that connection. Instead, it leaves the connection persistent, even after you’ve stopped the hotspot. You can confirm that by stopping your hotspot and then running nmcli connection show. Its output should include an entry that says Hotspot.

Let’s piggy-back on that: configure your hotspot just once via Settings, and turn it on once and then off again. From now on, you can turn on the hotspot by running a single CLI command:

sudo nmcli connection up Hotspot

After a few seconds, the hotspot should be active.

To turn off the hotspot, run:

sudo nmcli connection down Hotspot

Let me know if that helps.

3 Likes

This did the trick! That was the last bit of knowledge I needed to now have a one-touch hotspot toggle on my app launcher. Cheers!

1 Like