node-wifi
node-wifi copied to clipboard
Error: spawn nmcli ENOENT (Linux/Raspberry Pi)
Cannot scan (and possible also connect) for WiFi networks on Linux (Raspberry Pi)
Expected Behavior
Returning a list of networks wen calling wifi.scan()
Current Behavior
The following error emerges:
Error: spawn nmcli ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19) at onErrorNT (internal/child_process.js:465:16) at processTicksAndRejections (internal/process/task_queues.js:80:21) { errno: -2, code: 'ENOENT', syscall: 'spawn nmcli', path: 'nmcli', spawnargs: [ '--terse', '--fields', 'active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags', 'device', 'wifi', 'list', 'ifname', 'wlan0' ], cmd: 'nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list ifname wlan0' }
Affected features
- [x] node API
- [ ] cli
Possible Solution
Steps to Reproduce (for bugs)
Run wifi.scan() on raspberry pi in node.js project
Your Environment
Raspberry Pi - Node 14
- OS: Rasbian
- node-wifi version ^2.0.15
- wifi card: (on linux, use command
lspci | egrep -i --color 'network|ethernet'
)
Hello,
Can you try to run the command nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list ifname wlan0
in a terminal and print the result here?
Out of the box, nothing happens. It just waits for the next command.
But if I do the following:
sudo systemctl disable dhcpcd
sudo systemctl stop dhcpcd
sudo reboot now
Then I get a list of networks in the form as the fields in your command. It is worth noting that some networks have no ssid (hidden networks perhaps?)
The errors still persists in the program.
I have tried to run the nmcli command via the node CLI, this seems where the error stems from:
So via Bash the command seems to work as intended, but when done via a node environment it doesn't work.
I see several possibilities:
- node doesn't the same access as your user in the terminal
-
nmcli
returns a none-zero error in the terminal -
child_process
has trouble on raspbian
I am currently working on a new version to stabilize these commands on linux. Can you follow these steps on your raspbian to use this new version currently in development:
-
git clone https://github.com/friedrith/node-wifi.git
-
npm install
-
node scripts/scan.js
Check if you have any good result or another fail.
This seems to work as I get the same list as mentioned earlier!
Nice 👍 . I will publish a beta version using this new implementation very soon. I might ask you to test it to be sure it is solving your problem once integrating.
Ok! Thanks in advance. Hit me up when the beta is released.
I will test it with dhcpcd enabled, and disabled then.
Hi, an alpha is available on npm. You can install it using the command: npm i [email protected]
. Tell me if it is fixing your situation.
Thank you!
I have tested it. I will try to isolate the problem better soon. It seems a production electron environment has something to do with it. When serving a development build it seems to work now, but I get the same error message when when packaged.
I will research this further. I can imagine more people are trying to do the same.
I didn't know you were using electron
. Your issue may be caused by a path problem (cf https://stackoverflow.com/questions/45149031/electron-packager-spawn-enoent). Can you try the fix?
Electron also has several threads (main
, renderer
). Be sure to use the good thread (I guess it is main
) otherwise it won't work.
Ok, I have tried a couple of different solutions. No luck so far in the past couple of weeks. I keep getting the same error.
I have tried to change the process.env.PATH
The fix-path package didn't build, so I tried to recreate the fix from the source.
Do you have another insight maybe?
From my experience, the best way to locate a problem is to split the situation into several pieces. First maybe you can isolate your code using node-wifi into a single file. Maybe could you try to run this code on the same hardware and OS but using node.js environment?
PS: don't hesitate to share your progress there so that we can iterate faster.
Same behavior on Raspberry pi / Debian 11.6. Any update on this ?
Issue still persists, any updates ?
I'm running my wlan0 in Master mode
wlan0 IEEE 802.11 Mode:Master Tx-Power=31 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:off
Apparently, I have been lacking network-manager
installed since I'm running on Armbian Lite