I want to connect my Raspberry Pi 4B to my Wifi network via CLI (technically, by node.js/python scripts) without rebooting it.
For the moment I am modifying the /etc/wpa_supplicant/wpa_supplicant.conf
file by adding my Wifi info:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
ssid="SSID"
psk="pass"
key_mgmt=WPA-PSK
}
Then, I found I should run the command sudo wpa_cli -i wlan0 reconfigure
to run the wifi with the new data, but unfortunately, it doesn't work. I got the message OK
, but when I check ifconfig
, I have no IP on wlan0.
I tried also to do
sudo ifconfig wlan0 down
sudo ifconfig wlan0 up
without success. And then I tried
sudo killall wpa_supplicant
sudo wpa_supplicant -i wlan0 -D wext -c/etc/wpa_supplicant/wpa_supplicant.conf -B
And again, it failed, giving me the following error message:
Successfully initialized wpa_supplicant
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
What would be the give why to apply the new wpa_supplicant.conf
file, or if there is another way to connect the RPi to Wifi without GUI and reboot.
PS: I am running the following Raspian 10 (buster)
PPS: I followed the solutions of that post, but no one could work.
EDIT: the result of the command systemctl status dhcpcd
* dhcpcd.service - dhcpcd on all interfaces
Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-09-13 15:00:46 JST; 2h 16min ago
Process: 397 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b (code=exited, status=0/SUCCESS)
Main PID: 457 (dhcpcd)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/dhcpcd.service
`-457 /sbin/dhcpcd -q -b
Sep 13 16:10:26 raspberrypi dhcpcd[457]: eth0: carrier lost
Sep 13 16:10:26 raspberrypi dhcpcd[457]: eth0: deleting address fe80::c62c:bf9d:e38d:ee8f
Sep 13 16:10:26 raspberrypi dhcpcd[457]: eth0: deleting route to 192.168.4.0/24
Sep 13 17:17:33 raspberrypi dhcpcd[457]: eth0: carrier acquired
Sep 13 17:17:33 raspberrypi dhcpcd[457]: eth0: IAID 01:4c:5c:00
Sep 13 17:17:33 raspberrypi dhcpcd[457]: eth0: adding address fe80::c62c:bf9d:e38d:ee8f
Sep 13 17:17:33 raspberrypi dhcpcd[457]: eth0: probing address 192.168.4.1/24
Sep 13 17:17:34 raspberrypi dhcpcd[457]: eth0: soliciting an IPv6 router
Sep 13 17:17:38 raspberrypi dhcpcd[457]: eth0: using static address 192.168.4.1/24
Sep 13 17:17:38 raspberrypi dhcpcd[457]: eth0: adding route to 192.168.4.0/24
EDIT 2 :
I also added a static IP on eth0 by editing the file /etc/dhcpcd.conf
:
interface eth0
static ip_address=192.168.4.1/24