0

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
Dark Patate
  • 211
  • 2
  • 10

2 Answers2

1

You have something different in the configuration files which prevents dhcpcd from starting wpa_supplicant. This is how the service status looks on my system:

pi@raspberrypi:~ $ systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2021-09-24 13:30:39 CEST; 2 weeks 4 days ago
 Main PID: 442 (dhcpcd)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/dhcpcd.service
           ├─  442 /sbin/dhcpcd -q -b
           └─21837 wpa_supplicant -B -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0 -Dnl80211,wext

Note your log doesn't have the last line that mine has.

You could try using raspi-config to configure your WiFi, then systemctl restart dhcpcd if you want to avoid the reboot.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
0

Default networking on Raspberry Pi OS uses dhcpcd which starts wpa_supplicant with a hook, it is unclear what attempting to run wpa_supplicant would actually do.

You are connected by Ethernet to something, but not wireless. using static address 192.168.4.1/24 fills me with trepidation (particularly by someone who states "I don't know that much about networking"), but you have OBVIOUSLY changed something.

Normally you would restart networking with sudo systemctl restart dhcpcd but if you are attempting to connect to a different network which may have different settings who knows what will happen.

You should try and repeat systemctl status dhcpcd.

Milliways
  • 62,573
  • 32
  • 113
  • 225