wifi-connect
wifi-connect copied to clipboard
Forget ssid
How can I forget a ssid from the raspberry pi?
Before starting wifi-connect I call these commands:
nmcli connection down id "ssid" || true
nmcli connection delete id "ssid" || true
To remove all existing wifi-connections I call:
nmcli con show | grep wifi | awk '{print $2}' | while read line; do nmcli con down uuid $line && nmcli con delete uuid $line; done
Similar approach:
nmcli --pretty --fields UUID,TYPE con show | grep wifi | awk "{print $1}" | while read line; do nmcli con delete uuid $line; done
Don't forget to install network-manager with your dockerfile for it to work but to avoid issues, be sure to mask the service:
RUN apt-get update && apt-get install -y network-manager && systemctl mask NetworkManager.service
See https://www.balena.io/docs/reference/OS/network/2.x/#changing-the-network-at-runtime for the warnings and issues network manager can cause.
Alternatively, build a Python script solution: https://github.com/balena-io/wifi-connect/issues/270
Hi @m I also want to remove all wifi connection programmatically in the container. I was able to delete the specific connection with the following commands.
nmcli connection down id "ssid" || true nmcli connection delete id "ssid" || true
But what I really want to is delete all wifi connections in my django container. Otherwise, is it possible to run those commands on hostOS in the container? Here are all settings for django service in docker-compose.yml file
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile-dev
network_mode: "host"
privileged: true
volumes:
- ./:/app/
- /run/dbus/system_bus_socket:/host/run/dbus/system_bus_socket
depends_on:
- db
restart: always
devices:
- "/dev/ttyAMA0:/dev/ttyAMA0"
cap_add:
- NET_ADMIN
environment:
- DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"
To use nmcli command in the container, I installed Network-manager by the following command.
apt-get update && apt-get install -y network-manager && systemctl mask NetworkManager.service
And I run executed the following command in the container
nmcli connection down id "TP-LINK-REAL3D" || true nmcli connection delete id "TP-LINK-REAL3D" || true
But I got the following error.
How can I solve this error?
Thanks in advance.
Anatoli
From https://github.com/balena-io/wifi-connect#balenaos-multicontainer-app it seems that you are missing
labels:
io.balena.features.dbus: '1'
in your docker-compose file.
Thanks for your reply! @avandermeer
I know that labels option is only needed if I use Ballena OS. Right? I installed raspbian OS on my raspberry pi4. And the base image of Dockerfile for django service is python3.7.3.
So I didn't add label option to docker-compose.yml file
You seem to have professional experience in this field. I really hope you give me a good solution to realize my ultimate goal.
- How can I delete and deactivate the already configured wifi network connection in the container? Is it necessary to install network-manger in the container? I think there is a way to do that without installing network manager in the container
- I also tried the following command to delete all the network connection, but it didn't work
- Even though network manager is installed in the container, but I still have an error. how can I fix it?
sudo nmcli con show | grep wifi | awk '{print $2}' | while read line; do nmcli con down uuid $line && nmcli con delete uuid $line; done
pi@raspberrypi:~/DTECTS_SW_Server_Side $ sudo nmcli con show | grep wifi | awk '{print $2}' | while read line; do nmcli con down uuid $line && nmcli con delete uuid $line; done Connection 'Ergsense' deactivation failed: Not authorized to deactivate connections Error: Connection deletion failed: Insufficient privilegesError: not all connections deleted.
Similar approach:
nmcli --pretty --fields UUID,TYPE con show | grep wifi | awk "{print $1}" | while read line; do nmcli con delete uuid $line; done
Don't forget to install network-manager with your dockerfile for it to work but to avoid issues, be sure to mask the service:
RUN apt-get update && apt-get install -y network-manager && systemctl mask NetworkManager.service
See https://www.balena.io/docs/reference/OS/network/2.x/#changing-the-network-at-runtime for the warnings and issues network manager can cause.
Alternatively, build a Python script solution: #270
Hi Installing network manager inside the container is for running nmcli commands in the container? I installed network manager manually in the container and run nmcli. Of course, I used your command to install it. However, I still can't run nmcli in the container. Can you check my screenshot in above? My host OS is Raspbian and network manger is already installed on host OS. I really want to use nmcli commands in the container. Is there any good solution for it? Thanks. Anatoli
I know that labels option is only needed if I use Ballena OS. Right?
It will only work in Balena OS/with Balena Engine, but you will likely need to achieve the equivalent of this in other environments too.
Try adding -v /var/run/dbus:/var/run/dbus to your docker run command (or to '/host/run/dbus/system_bus_socket' as the error message indicates. This will mount the dbus controller in to your container, similar to what the label does in Balena.
Depending on what kind of permissions are required you may need to add --privileged to the container too, but try without as wouldn't recommend adding it unless necessary as it's generally not good practice security wise.
Try searching/reading around mounting DBus into Docker container for more info. As this is outside of the Balena infrastructure and not related to Balena software/wifi-connect you may be better off trying other forums for more info.
To remove all existing wifi-connections I call:
nmcli con show | grep wifi | awk '{print $2}' | while read line; do nmcli con down uuid $line && nmcli con delete uuid $line; done
Hi @avandermeer
I was able to run nmcli commands in my container. It works well. However, the above command you shared for removing all wifi network connections doesn't work. I get the following error when I try it.
What's the wrong? I can remove the specific network connection using nmcli command.
How can I remove all wifi network connections?
I hope you will get back to me with a good solution asap. Thanks in advance. Jense
@jense-arntz sorry for the delay; you have to run every command with the right permissions, in your example you only put sudo
before the first command (nmcli con show
). The second and third time you call nmcli
(in the while loop), sudo is missing. In other words; put sudo
before every occurence of nmcli
.