friedrith / node-wifi

📶 NodeJS tool to manage wifi (connections, scans)
MIT License
398 stars 161 forks source link

Error: spawn nmcli ENOENT (Linux/Raspberry Pi) #167

Open WesWeCan opened 3 years ago

WesWeCan commented 3 years ago

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

Possible Solution

Steps to Reproduce (for bugs)

Run wifi.scan() on raspberry pi in node.js project

Your Environment

Raspberry Pi - Node 14

friedrith commented 3 years ago

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?

WesWeCan commented 3 years ago

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.

WesWeCan commented 3 years ago

I have tried to run the nmcli command via the node CLI, this seems where the error stems from:

error.txt

So via Bash the command seems to work as intended, but when done via a node environment it doesn't work.

friedrith commented 3 years ago

I see several possibilities:

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:

Check if you have any good result or another fail.

WesWeCan commented 3 years ago

This seems to work as I get the same list as mentioned earlier!

friedrith commented 3 years ago

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.

WesWeCan commented 3 years ago

Ok! Thanks in advance. Hit me up when the beta is released.

I will test it with dhcpcd enabled, and disabled then.

friedrith commented 3 years ago

Hi, an alpha is available on npm. You can install it using the command: npm i node-wifi@2.1.0-alpha.1. Tell me if it is fixing your situation.

WesWeCan commented 3 years ago

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.

friedrith commented 3 years ago

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.

WesWeCan commented 3 years ago

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?

friedrith commented 3 years ago

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.

lclnrd commented 2 years ago

Same behavior on Raspberry pi / Debian 11.6. Any update on this ?

fosteman commented 2 years ago

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

fosteman commented 2 years ago

Apparently, I have been lacking network-manager installed since I'm running on Armbian Lite