friedrith / node-wifi

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

wifi.connect error is undefined when password is incorrect. #147

Open kaleem68 opened 3 years ago

kaleem68 commented 3 years ago

Expected Behavior

wifi.connect should always return a proper error message when the ssid is correct & password is incorrect but it returns the 'undefined'

Current Behavior

sometimes wifi.connect returns error: Error: Command failed: netsh wlan add profile filename="nodeWifiConnect.xml" when the ssid is correct & password is incorrect, but most of the time error is undefined when ssid is correct and password is incorrect.

Code

   exports.conenect_to_wifi = function(req,res){
    var ssid_para = req.params.Ssid;
    var password_para = req.body.Password;
    wifi.init({
      iface: null 
    });
    wifi.connect({ ssid: ssid_para, password: password_para }, error => {

      console.log("error is ",error);

      if (error) {
        console.log("failed to connect with wifi");
        console.log(error);
      }
      else { 
      console.log("Wifi connected");
      console.log("Connected");
      }
    });
    res.json({message: "password receive successfully"});
  }

Your Environment

sundong212 commented 3 years ago

Same problem here. The connection would fail at first but without return error messages, and the connection will fallback to the original WiFi since it has the correct profile stored. (Mac)

quanc commented 3 years ago

Same problem here