mark2b / wpa-connect

wpa-connect
MIT License
61 stars 19 forks source link

Error - "address_not_allocated" #9

Closed sdima75 closed 3 years ago

sdima75 commented 3 years ago

Hello. My code.

package main

import (
    "fmt"
    "time"

    wifi "github.com/mark2b/wpa-connect"
)

func main() {
    ssid := "My_name_wifi"
    password := "My_password_wifi"
    if conn, err := wifi.ConnectManager.Connect(ssid, password, time.Second*60); err == nil {
        fmt.Println("Connected", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String())
        // fmt.Println("Connected", conn)
    } else {
        fmt.Println("Err connect: ", err)
    }
}

An error appears - "address_not_allocated". Wifi is working properly. The password is correct. Can you tell me what the problem may be?

I understand that the problem is related to the code -

func (self *connectContext) hasIP() bool {
    return self.ip4 != nil && self.ip6 != nil
}
mark2b commented 3 years ago

Hello, It looks like DHCP didn't allocate IP address (v4 & v6) for some reason. There is a loop that waits for IP allocation during timeout you provided.

sdima75 commented 3 years ago

Hello, It looks like DHCP didn't allocate IP address (v4 & v6) for some reason. There is a loop that waits for IP allocation during timeout you provided.

I only run "ifconfig" with root privileges. Could this be the reason for the error?

mark2b commented 3 years ago

You should run wpa-connect with root / sudo

sdima75 commented 3 years ago

You should run wpa-connect with root / sudo

Thank you for your help!