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
  • 103
  • 2
  • 9
  • For example in the post, I shared in the PPS. It said it's the recommended method from 2018, so I assumed it was still true (and when I look on Google that command often came out). For dhcpcd I' don't know. I'm not really knowledgeable about networking. – Dark Patate Sep 13 '21 at 08:00
  • I'm connected in LAN directly with my PC for testing. But in the final version of my project, I'll be connected in Bluetooth (so no network connection) and I will send the Wifi info to connect the Rpi (that's already done). I just need to set up the wifi. – Dark Patate Sep 13 '21 at 08:02
  • I edited the post with the result of the command. Sorry, but because I don't know that much about networking, I don't know what could be useful. I used the previous command because it popped to me several times on different topics and pages. So I gave it a try – Dark Patate Sep 13 '21 at 08:21

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
  • 27,928
  • 6
  • 53
  • 144
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
  • 59,890
  • 31
  • 101
  • 209
  • Yeah, I changed a while ago the ethernet configuration to have static IP on it. But I forgot about it, sorry. Actually, the Pi is connected by LAN top another RPi (with WLAN deactivated). The RPi I'm trying to connect should share the internet via LAN connection on static IP on eth0. I only modified the eth0, but I forgot how exactly I did. I do not know how much eth0 and wlan0 can interfere? – Dark Patate Sep 13 '21 at 08:51
  • And for testing, now, I replaced the second Pi with my PC, in order to use SSH – Dark Patate Sep 13 '21 at 08:52
  • I edited the original post with my edit on the dhcpcd.conf – Dark Patate Sep 13 '21 at 08:55
  • I tried the command sudo systemctl restart dhcpcd but it didn't work :/ Also, the Raspberry pi website also said to use the command wpa_cli -i wlan0 reconfigure: https://www.raspberrypi.org/documentation/computers/configuration.html#using-the-command-line – Dark Patate Sep 14 '21 at 09:12
  • @DarkPatate Posting a link to a page which has ABSOLUTELY nothing to do with your assertion is futile, as is any attempt to help. There is no such claim. – Milliways Sep 14 '21 at 12:24