liamw9534 / pyconnman

A library for managing network connectivity using Python, ConnMan and DBus
Apache License 2.0
11 stars 11 forks source link

Not working when connecting for the first time? #2

Open telarium opened 7 years ago

telarium commented 7 years ago

I'm running into an issue when using the demo.py example or my own script and connecting to a wifi network for the first time. For example:

CONN> list-services
CONN> agent-start /test/agent ssid=myNetwork passphrase=myPassphrase
CONN> service-connect /net/connman/service/wifi_xxxxx__managed_psk

This eventually results in an error:

Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken

However, if I use connmanctl to manually connect at least once, it does work. For example:

connmanctl connmanctl> agent on connmanctl> connect wifi_xxxxx__managed_psk Agent RequestInput wifi_xxxxxmanaged_psk Passphrase = [ Type=psk, Requirement=mandatory ] Passphrase? myPassword `connmanctl> Connected wifi_xxxxxmanaged_psk`

Now it will connect, and I can use the same demo.py script to disconnect or reconnect. But for any new wifi network, I have to use connmanctl first (which creates the /var/lib/connman/wifi* folder with the saved settings)

Any idea why this would be the case and how I might get around the problem?

liamw9534 commented 7 years ago

Check the wifi technology is enabled as it sometimes defaults as disabled.

Also check to ensure no other agent is running eg in your window manager. It is only permitted to have one agent running.

Finally you might want to disconnect any other network interfaces eg ethernet in case this is messing with the connection management.

On 28 Sep 2017 00:30, "Andrew Langley" notifications@github.com wrote:

I'm running into an issue when using the demo.py example or my own script and connecting to a wifi network for the first time. For example:

CONN> list-services CONN> agent-start /test/agent ssid=myNetwork passphrase=myPassphrase CONN> service-connect /net/connman/service/wifi_xxxxx__managed_psk

This eventually results in an error:

Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken

However, if I use connmanctl to manually connect at least once, it does work. For example:

connmanctlconnmanctl> agent on connmanctl> connect wifi_xxxxxmanaged_pskAgent RequestInput wifi_xxxxxmanaged_psk Passphrase = [ Type=psk, Requirement=mandatory ] Passphrase? myPasswordconnmanctl> Connected wifi_xxxxx__managed_psk`

Now it will connect, and I can use the same demo.py script to disconnect or reconnect. But for any new wifi network, I have to use connmanctl first (which creates the /var/lib/connman/wifi* folder with the saved settings)

Any idea why this would be the case and how I might get around the problem?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/liamw9534/pyconnman/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AGcZTxD-YyKWD5EzVUNZLJBVCefLw_hJks5smtqEgaJpZM4PmiCF .

telarium commented 7 years ago

I have made sure that no other agent is running (most of the time this issue appears on a fresh install when the device has never connected to a network before.)

I do ensure that the wifi interface technology is enabled first. There is no ethernet connection (the devices I've tested actually don't have onboard ethernet), and the device has not been issued a previous IP address on any of the wlan interfaces.

The result is still the same: It will not connect until I manually connect at least one time with connmanctl. Once I do that, everything works as expected until I try to connect to new wifi access point that I haven't already connected to previously.

telarium commented 7 years ago

As an alternative, I tried using gonnman (a Connman dbus utility written in Go), and it doesn't seem to have this issue.

ppladde commented 2 years ago

Hi telarium, I am also facing exactly same issue. have you resolved it? if so, will you please give me any hint for the same. Thanks.

telarium commented 2 years ago

Unfortunately no. I ended up doing a hack where I used pexpect with connmanctl instead of using the dbus to connect to a network. I don't know why, but going that route doesn't run into this issue. So essentially, I ended up using pyconnman for everything except for connecting to a network.

For reference, feel free to see my "solution" in my Python script connect function:

https://github.com/telarium/google-assistant-onboarding/blob/master/wifiConnmanManager.py

ppladde commented 2 years ago

Thank you so much @telarium, Your "connect" function is working perfect for me as well.

mstubley commented 1 year ago

I've just been looking at this issue. If you run the demo twice one with the agent-start in and one with the service-connect in then it works fine. Is is possible the connect is synchronous and blocking the agent returning the credentials ? You can get similar behaviour using the test scripts from the connman source:

https://kernel.googlesource.com/pub/scm/network/connman/connman/+/refs/heads/master/test/