node-wifi icon indicating copy to clipboard operation
node-wifi copied to clipboard

Add sudo and timeout options to linux-connect

Open KeithYeh opened this issue 4 years ago • 0 comments

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

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Refactorization (non-functional change which improve code readability)

KeithYeh avatar Oct 30 '20 14:10 KeithYeh