Wifx / gonetworkmanager

Go D-Bus bindings for NetworkManager
Other
96 stars 42 forks source link

Get Accesspoint properties from activeConnection #20

Closed GreetRobbie closed 3 years ago

GreetRobbie commented 3 years ago

Hi there!

So far the the gonetworkmanager works fine from my side!

I encounter 1 problem.

I want to have the SSID from my activeConnection

I tried the following:


nm, err :=gonetworkmanager.NewNetworkManager()

if err != nil {
fmt.Println("Could not create networkManager instance:")
fmt.Println(err.Error())
}

activeConnections, err := nm.GetPropertyActiveConnections()
if err != nil {
fmt.Println("Could not create activeConnections instance:")
fmt.Println(err.Error())
}

for _, activeConnection := range activeConnections {
   accessPoint, err := activeConnection.GetPropertySpecificObject()
   if err != nil {
       fmt.Println("Could not create access point instance:")
       fmt.Println(err.Error())
   }

   ssid, err := accessPoint.GetPropertySSID()

    if err != nil {
      fmt.Println("typeOf---")
      fmt.Println(reflect.TypeOf(accessPoint))
      fmt.Println("---")
       fmt.Println("Could not access the ssid:")
       fmt.Println(err.Error())
   }
}

This outputs:


typeOf---
*gonetworkmanager.accessPoint
---
Could not access the ssid:
No such interface “org.freedesktop.DBus.Properties” on object at path /org/freedesktop/NetworkManager/AccessPoint/3

What Do I miss?

Thanks alot!

mullerch commented 3 years ago

I've never used SpecificObject and AccessPoint.

To me there is no guarantee that all of your connections have an SpecificObject. To be coherent, accessPoint should be null in that case and your code should fail at accessPoint.GetPropertySSID(), but I'm not sure that the library will return null. I would first check what accessPoint contains.

If that really looks valid I would check with other tools (dbus-send) if /org/freedesktop/NetworkManager/AccessPoint/3 really exists. If it exists I would check if it has the org.freedesktop.DBus.Properties.

At that time you will at least know where the problem is.

GreetRobbie commented 3 years ago

@mullerch

Thanks for the reply! So in my case the accesPoint is not null and is of type *gonetworkmanager.accessPoint

I can check with dbus-send tool if the access point really exists in network manager.

Do you know another way around to get the SSID from the current active connection with gonetworkmanager?

mullerch commented 3 years ago

No, I would have started with AccessPoint too.

What version of NetworkManager do you have?

GreetRobbie commented 3 years ago

nmcli --version nmcli tool, version 1.22.10

GreetRobbie commented 3 years ago

My hypothese is that my goNetworkManager instance wasnt up to date with the latest config. Reason:

This message: No such interface “org.freedesktop.DBus.Properties” on object at path /org/freedesktop/NetworkManager/AccessPoint/3

was appearing some times when running but not always. So my hypothese again: my instance is sometimes behind with the latest config on disk or is using cache.

I am using the Settings.ReloadConnections() for now to make sure I have the latest connections config. Lets see if I get this message again

Thanks anyways!