friedrith / node-wifi

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

Add sudo and timeout options to linux-connect #142

Open KeithYeh opened 3 years ago

KeithYeh commented 3 years ago

Allow users to use the connect method with sudo permission or customize waiting timeout on Linux.

Description

I use the connect code example on Raspberry Pi 4.

// connect.js
wifi.connect({ ssid: 'ssid', password: 'password' }, error => {
  if (error) {
    console.log(error);
  }
  console.log('Connected');
});

It works by using node connect.js

When I use pm2 start connect.js, the permission error was thrown.

Not sure what's the root cause yet, but using sudo can be a workaround to solve this issue.

Motivation and Context

Related issue: #10

Usage examples

// You can use sudo (need sudoer permission) or set timeout on linux
wifi.connect({ ssid: 'ssid', password: 'password', sudo: true, timeout: 10 /* seconds */ }, error => {
  if (error) {
    console.log(error);
  }
  console.log('Connected');
});

How Has This Been Tested?

Tested on Raspberry Pi 4, Raspbian OS

Types of changes