Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condition changed to "offline" spontaneously, after being online. #70

Open
FireWizard52 opened this issue Sep 6, 2024 · 8 comments
Open

Comments

@FireWizard52
Copy link

          Hello @ostrya,

Google has published the new release 2.6.2 in the Google Play store.
I updated the app to this version and everything works again as before.

Thank you very much for your quick response and solving this issue.

Best regards

Originally posted by @FireWizard52 in #69 (comment)

@FireWizard52 FireWizard52 changed the title Hello @ostrya, Condition changed to "ofline" spontanously, after being online. Sep 6, 2024
@FireWizard52
Copy link
Author

FireWizard52 commented Sep 6, 2024

Hello @ostrya,

Yesterday I was very happy with your solution, but unfortunately, I found another issue, while running some tests.

I understood that the behavior of the detection principle has changed in recent updates. Am I correct?
Previously I was dependent on the publishing frequency. The higher the frequency, the quicker the information was published to the MQTT server. The drawback is of course the current consumption. I understood that the behavior has been changed in such a way that, if you connect or disconnect from the Wifi a message online, resp offline is immediately published. Correct?

My problem:

If I disconnect from my Wifi, I receive an "offline" message instantly. If I connect to my Wifi again, I receive an "online" message, but (aprox.) 30 seconds after that an "offline" message is published and the app remains in this state..
I'm able to restore the "online" condition by rebooting my phone.

Can you have a look. All log filrs are attached.

1725623018724.log
1725623073636.log
1725623092000.log

[Edit] Forget those 30 seconds, it is even 4-5 seconds and also after reboot is has problem to publish "online".

Best regards

@ostrya
Copy link
Owner

ostrya commented Sep 6, 2024

Hi @FireWizard52 , sorry to hear that it still does not work as expected. Yes, you are right - the current logic is that regardless of the publishing frequency, as soon as the device connects to or disconnects from a Wi-Fi, a message is sent.

And from the logs, it looks like there are still issues with detecting the Wi-Fi name. Repeatedly, there is a Wi-Fi disconnected: Jonas, directly followed by a Wi-Fi connected: <unknown ssid>. I'll need to look into which mechanism I used before in Android 11, maybe something changed there.

In addition, there is your point about sending offline messages immediately. If situations like yours, i.e. disconnecting and re-connecting within a few seconds, happen frequently, we probably want to introduce a waiting time between detecting the disconnect and sending an offline message. I'll need to look into that as well.

@FireWizard52
Copy link
Author

FireWizard52 commented Sep 6, 2024

good evening @ostrya ,

Thank you for your quick response.

For your information Jonas is the network name.

The MQTT server (broker) is a local one and so the route will change.

The waiting time is probably a good idea, as, because of the connected/disconnected cycle and vice versa. the network topology changes. Perhaps a small waiting time will already be sufficient

However I did not disconnect and reconnect within seconds. Mostly it was more than a minute.
Perhaps test the availability of the MQTT server, before sending a message (both for connected and disconnected WiFi)
But I'm not sure that the issue I see, that de phone sends "offline" after sending "online" might be caused by the Network Topology change.

Another issue is that, this test I did, was switching off and on the WiFi on my phone . This might be different from leaving the area and getting out of WiFi range, but leaving the WiFi "on". Perhaps something to consider.

[Edit] No, it makes no difference. Also when leaving the area the phone transmits "offline", which is correct, but returning and entering the area, results in an "online" message and then switching back to "offline". So the behavior of leaving and returning the area and switching "Off"and "On" the WiFi.
I also noticed, that (after a restart of the phone in order to get it "online") the Autostart does not work as expected. I had to open the app first before I received the "online" message.

ostrya added a commit that referenced this issue Sep 7, 2024
The main issue is that wifi manager sometimes returns a disconnected
WifiInfo object rather than null, which was wrongly detected as being
connected to a new "<unknown ssid>" network. This is addressed by
additionally checking the supplicant state of the network for state
COMPLETED.

Also for SDK < 31 we cannot really rely on the WifiManager giving
data in sync to the Callback events, as we have no guarantees about
that from AOSP. The best we can do is (similar to the Broadcast
solution for SDK < 23), regardless of event type, always to check
the current SSID and assume connect when it's present and
disconnect when it's absent.

Since this causes duplicate events, the last known SSID is statically
persisted in the WifiEventConsumer, and the event is only propagated
if the SSID actually changes.
@ostrya
Copy link
Owner

ostrya commented Sep 7, 2024

I hope I got it now. There were several issues I had overlooked, but it should work now with the next release.

In any case, please keep an eye out for the restart issue, that should still work as before. If it persists, please create a new issue for that.

@FireWizard52
Copy link
Author

FireWizard52 commented Sep 27, 2024

Hi @ostrya,

I waited a couple of weeks, before to report the results of the latest release 2.6.3, as I was too quick the last time.

I can confirm that the app detects the "Home" network correctly and it reports [online].
I did not see any issues with that, so "online" is detected properly.

However this is not the case, if I leave my house, e.g. to do some shopping.
In this case it continues to report online and it also keeps the SSID.
If I enter an area, where the SSID is known (friends), it will automatically detect that network and report as connectedWifi the SSID and [offline] So far, so good.

After I leave that network, it will properly display as connectedWifi "N/A", until I arrive at home, after it will detect the "Home" network and will report [online].

So the detection of the connection to my Home Network is okay, but the detection of the disconnection is not working. This is the same, if connected to a foreign network. It gives [offline] and the SSID, which is correct, as it is not my home network, but it does not disconnect that foreign network and does not show N/A.

Regards

@FireWizard52 FireWizard52 changed the title Condition changed to "ofline" spontanously, after being online. Condition changed to "offline" spontaneously, after being online. Sep 29, 2024
@ostrya
Copy link
Owner

ostrya commented Oct 1, 2024

Sorry that it still does not work, and thanks for the update. So it looks like my changes are not working as intended. I guess I will need to go back to detecting the WiFi network in a time-based manner.

ostrya added a commit that referenced this issue Oct 2, 2024
Since the network callback solution does not work due to race conditions,
we additionally read the wifi during publishing again. Hopefully, this
should give us the best of both worlds.

Also, do not store the connected wifi into a preference, since we do not
want it to survive app restarts - who knows how long the app was not
running, most likely the wifi has changed in the meantime.

relates to #70
@ostrya
Copy link
Owner

ostrya commented Oct 21, 2024

Hi @FireWizard52, do you see any changes with the new version 2.6.4?

@FireWizard52
Copy link
Author

Hello Kai,

I wasn't aware that version 2.6.4 had been released. So I did not monitor it consequently, but now I saw that it was actually installed on the phone. I checked in the log al the times, that I was sure, that I was not connected to my own wifi.
I checked also the behavior, by switching the phone "offline" and after approx 2 minutes I switched it "online" again,

The result was, what I expected and my first impression is that the issue has been solved now.
Good job! Thanks for all your efforts to improve this app.

Before closing this issue, I suggest to keep it open for another couple of days. In the meantime, I will monitor its behavior.

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants