rstrouse / ESPSomfy-RTS

A controller for Somfy RTS shades and blinds
The Unlicense
428 stars 32 forks source link

Auto-reconnect to wifi in case it is down for some time. #407

Open hajar97 opened 1 week ago

hajar97 commented 1 week ago

Describe you new feature you'd like

Was restarting my router today and noticed that after restarting it ESPSomfyRTS stayed offline even after router fully rebooted and started to accept wifi connections again.

Question: Is there some periodic wifi re-connect retry logic that ensures that it will eventually come online again without having to manually restart it even if internet is down for some prolonged time, but eventually comes back online again? This is particularly important when admin is away from physical access to the device and cannot come to it to reboot after internet connection has been restored by someone else.

rstrouse commented 1 week ago

If you do not connect to the AP it will close it as soon as it can connect to the said you defined.

hajar97 commented 1 week ago

Seems if I turn off router and some time later turn on it remains disconnected. On 21 Jun 2024, at 01:01, rstrouse @.***> wrote: If you do not connect to the AP it will close it as soon as it can connect to the said you defined.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rstrouse commented 1 week ago

I just did tried this again and did not experience your issue. The one thing that can cause this to happen is to have the auto-connect settings turned on for the ESPSomfyRTS SSID. In this case, as soon as the ESPSomfyRTS SSID becomes available then whichever device is set that way will connect to it. While a client is connected to the AP, ESPSomfy RTS will not drop out of AP mode. If it did then you would lose connection while you are trying to configure the device.

Are you sure you don't have any devices that you need to forget the ESPSomfyRTS network on?

hajar97 commented 1 week ago

Just tested it again:

  1. Made sure I “forgot” ESPSomfy RTS SSID on all my devices
  2. Turned off Wifi Access Point (part of my wifi Mesh) that is closest to ESPSomfy device
  3. Checked HA to ensure it became unavailable. And that ESPSomfy RTS SSID indeed appears in the list of SSIDs but I do not connect to it. Also checked and confirmed my other ESPHome devices also went off radar.
  4. Waited to see if it would pick up signal from another access point. It should be possible, though signal would be much weaker. Anyway, it didn’t in 5 mins.
  5. Turned on the access point again. Waited until its up and other ESPHome devices would come back online. They did successfully as expected.
  6. Waited 15 mins pinging ESPSomfy RTS device. It didn’t re-connect to wifi in 15 mins. And ESPSomfy RTS SSID continued to be visible and accessible all that time…

After 15 mins I turned ESPSomfy RTS off and on again and it immediately connected to wifi and appeared in HA.

Enable roaming checkbox is ON in the settings of ESPSomfy RTS device.

Let me know what other info may help you find out why in my case it doesn’t reconnect until I reboot it?

On 25 Jun 2024, at 17:03, rstrouse @.***> wrote:

I just did tried this again and did not experience your issue. The one thing that can cause this to happen is to have the auto-connect settings turned on for the ESPSomfyRTS SSID. In this case, as soon as the ESPSomfyRTS SSID becomes available then whichever device is set that way will connect to it. While a client is connected to the AP, ESPSomfy RTS will not drop out of AP mode. If it did then you would lose connection while you are trying to configure the device.

Are you sure you don't have any devices that you need to forget the ESPSomfyRTS network on?

— Reply to this email directly, view it on GitHub https://github.com/rstrouse/ESPSomfy-RTS/issues/407#issuecomment-2189202685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2QG7V6UQGHE3I7O4KVWDTZJGBEJAVCNFSM6AAAAABJUVQYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBZGIYDENRYGU. You are receiving this because you authored the thread.

rstrouse commented 6 days ago

The pre-release of v2.4.6 has some changes that performs a scan whenever the AP mode is active and not connected. I think my test case was previously finding the SSID on my mesh but the wireless on the main router was disabled. In essence it was still finding the AP on startup even though it could not connect.

These changes should make the device pick up the SSID as soon as it is detected.

hajar97 commented 6 days ago

Tested. Sadly same result. It doesn’t reconnect. Waited for 30 mins. No luck. On 26 Jun 2024, at 18:45, rstrouse @.***> wrote: The pre-release of v2.4.6 has some changes that performs a scan whenever the AP mode is active and not connected. I think my test case was previously finding the SSID on my mesh but the wireless on the main router was disabled. In essence it was still finding the AP on startup even though it could not connect. These changes should make the device pick up the SSID as soon as it is detected.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

alka79 commented 6 days ago

same for me: no change. The new code added in network::loop after if(this->softAPOpened) { to scan again is never executed.

rstrouse commented 2 days ago

Install the current pre-release v2.4.6 as I have made changes that should rectify this. Please test this since my network comes back online very quickly. I stopped relying on timing to perform a new scan when the SSID cannot be found.

hajar97 commented 1 day ago

Just tested again. Switched off access point that was closest to ESPSomfy RTS device and voila it has picked up signal from another access point that is further away. Previously it didn’t do that.

Then I reconnected local access point, waited 15 mins and it reconnected to it again. I could judge it by vastly changing wifi dbms.

All seems to be working as expected now. Thanks a lot for looking into it and fixing it promptly. Every day of using ESPSomfy RTS is a joy!

On 30 Jun 2024, at 20:31, rstrouse @.***> wrote:

Install the current pre-release v2.4.6 as I have made changes that should rectify this. Please test this since my network comes back online very quickly. I stopped relying on timing to perform a new scan when the SSID cannot be found.

— Reply to this email directly, view it on GitHub https://github.com/rstrouse/ESPSomfy-RTS/issues/407#issuecomment-2198644668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2QG7XMCW62GQNI22YLZI3ZKBFHHAVCNFSM6AAAAABJUVQYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGY2DINRWHA. You are receiving this because you authored the thread.

hajar97 commented 1 day ago

Hm, now a different problem started to occur which I didn’t have before. ESPSomfy started to loose wifi connection and become unavailable every so often. Sometimes every 7 minutes, sometimes hours go by without loosing connection and then it happens.There was definitely nothing affecting my wifi during this time. On 30 Jun 2024, at 22:24, E Hajar @.> wrote:Just tested again. Switched off access point that was closest to ESPSomfy RTS device and voila it has picked up signal from another access point that is further away. Previously it didn’t do that.Then I reconnected local access point, waited 15 mins and it reconnected to it again. I could judge it by vastly changing wifi dbms. All seems to be working as expected now. Thanks a lot for looking into it and fixing it promptly. Every day of using ESPSomfy RTS is a joy!On 30 Jun 2024, at 20:31, rstrouse @.> wrote:Install the current pre-release v2.4.6 as I have made changes that should rectify this. Please test this since my network comes back online very quickly. I stopped relying on timing to perform a new scan when the SSID cannot be found.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

hajar97 commented 1 day ago
image

Here is a screenshot to give you an idea. Just keeps connecting and disconnecting now. The issue with it is that often automations fire when it happens to be disconnected and then automation fails to perform correctly.

Never mind that entity I took is the Backup one. It is obviously the same with all ESPSomfy entities as it gets disconnected and then reconnects again.

hajar97 commented 1 day ago

The issue may be on my side actually. I am investigating. I have connected 2 ESP32 devices to that single 5V USB power source and it could be interfering. I have now disconnected the second device and will observe how ESPSomfy RTS is behaving. I’ll report back tomorrow once I had it running like this for 24 hours.

On 1 Jul 2024, at 08:43, Elnar Hajiyev @.***> wrote:

Hm, now a different problem started to occur which I didn’t have before. ESPSomfy started to loose wifi connection and become unavailable every so often. Sometimes every 7 minutes, sometimes hours go by without loosing connection and then it happens.

There was definitely nothing affecting my wifi during this time.

On 30 Jun 2024, at 22:24, E Hajar @.***> wrote:

Just tested again. Switched off access point that was closest to ESPSomfy RTS device and voila it has picked up signal from another access point that is further away. Previously it didn’t do that.

Then I reconnected local access point, waited 15 mins and it reconnected to it again. I could judge it by vastly changing wifi dbms.

All seems to be working as expected now. Thanks a lot for looking into it and fixing it promptly. Every day of using ESPSomfy RTS is a joy!

On 30 Jun 2024, at 20:31, rstrouse @.***> wrote:

Install the current pre-release v2.4.6 as I have made changes that should rectify this. Please test this since my network comes back online very quickly. I stopped relying on timing to perform a new scan when the SSID cannot be found.

— Reply to this email directly, view it on GitHub https://github.com/rstrouse/ESPSomfy-RTS/issues/407#issuecomment-2198644668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2QG7XMCW62GQNI22YLZI3ZKBFHHAVCNFSM6AAAAABJUVQYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGY2DINRWHA. You are receiving this because you authored the thread.

hajar97 commented 21 hours ago

Nope, that wasn’t the reason. It keeps loosing connection and then reconnecting every so often. Time between each connection loss is different. Sometimes there can be hours without loosing connection, sometimes it keeps loosing it and reconnecting every fee mins. I don’t seem to see any pattern to it or understand the reason. The only other test I can think of trying is to revert back to previous firmware and see if problem goes away. If it does then it must be something in the latest pre-released firmware version. Can I roll back to previous firmware version without loosing my configuration?On 1 Jul 2024, at 17:47, E Hajar @.> wrote:The issue may be on my side actually. I am investigating. I have connected 2 ESP32 devices to that single 5V USB power source and it could be interfering. I have now disconnected the second device and will observe how ESPSomfy RTS is behaving. I’ll report back tomorrow once I had it running like this for 24 hours.On 1 Jul 2024, at 08:43, Elnar Hajiyev @.> wrote:Hm, now a different problem started to occur which I didn’t have before. ESPSomfy started to loose wifi connection and become unavailable every so often. Sometimes every 7 minutes, sometimes hours go by without loosing connection and then it happens.There was definitely nothing affecting my wifi during this time. On 30 Jun 2024, at 22:24, E Hajar @.> wrote:Just tested again. Switched off access point that was closest to ESPSomfy RTS device and voila it has picked up signal from another access point that is further away. Previously it didn’t do that.Then I reconnected local access point, waited 15 mins and it reconnected to it again. I could judge it by vastly changing wifi dbms. All seems to be working as expected now. Thanks a lot for looking into it and fixing it promptly. Every day of using ESPSomfy RTS is a joy!On 30 Jun 2024, at 20:31, rstrouse @.> wrote:Install the current pre-release v2.4.6 as I have made changes that should rectify this. Please test this since my network comes back online very quickly. I stopped relying on timing to perform a new scan when the SSID cannot be found.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rstrouse commented 21 hours ago

Can I roll back to previous firmware version without loosing my configuration

You can but don't do that. This message may be simply that the active state is changing on the entity. What does the WiFi entity look like?

hajar97 commented 21 hours ago

Which wifi entity? Wifi SSID? It changes to “unknown” and then to my SSID then to “unknown” then to my SSID. This change to unknown and back to my wifi network happens every time when every other entity becomes unknown.

What do you recommend I try?

On 1 Jul 2024, at 23:45, rstrouse @.***> wrote:

Can I roll back to previous firmware version without loosing my configuration

You can but don't do that. This message may be simply that the active state is changing on the entity. What does the WiFi entity look like?

— Reply to this email directly, view it on GitHub https://github.com/rstrouse/ESPSomfy-RTS/issues/407#issuecomment-2201130457, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2QG7SIRRY7Z57T5DWXSVTZKHEXBAVCNFSM6AAAAABJUVQYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBRGEZTANBVG4. You are receiving this because you authored the thread.

rstrouse commented 20 hours ago

The strength entity.

schirm22 commented 3 hours ago

Hi there, it appears I have the same or a very similar issue. After upgrading to version 2.4.6 (due to Wifi disconnection issue), the device connects to the Wifi (WPA3). As soon as I try to access the web interface, it disconnects from the Wifi and then reconnects some seconds later. It doesn't open its own AP anymore. The device is currently placed right next to the Wifi router. MQTT is enabled. After 2-3 connection / disconnection cycles, the device does not connect anymore, nor does it open its own AP.

hajar97 commented 3 hours ago
image

When checking Wifi Signal entity I do seem to have reading around -20dbm all the time (it is right next to the router). But those readings are taken every 5 mins. When checking Connection entity (see attached screenshot), it is clear that between disconnects and reconnects sometimes a min long gap. So if automation fires in that minute then it will fail and that's exactly what was happening to me.

I restarted the router and the erratic behaviour seems to have stopped, at least last in the last 2 hours. To have more certainty I really need to wait 24 hours for conclusive results.

In any case, it cannot be just my router, as I have other ESP32 dev platforms and they all reconnect without a problem and keep connection without those strange dropouts every so often.

Sorry I wish I had more scientific and reproducible results. For now it is somewhat all over the place.

rstrouse commented 2 hours ago

Actually if it had disconnected, that wifi signal would have also dropped. This tells me there is something with the switch entity that I need to take care of. All of the entities on the device will go unavailable if device is disconnected.

schirm22 commented 2 hours ago

Could it be related to WiFi router channel switching?

rstrouse commented 2 hours ago

Yes if your router is switching channels the ESP32 will need to disconnect from the old channel to the new one. But it shouldn't be switching channels all the time. ESP32 has only one WiFi radio and does not support seamless channel changes. Is the channel entity changing in HA?

hajar97 commented 4 minutes ago

Checked for the last 3 days and it changed channel only once. So that cannot be a reason for such frequent reconnects. Started doing it again… so router reboot didn’t help either. On 2 Jul 2024, at 19:27, rstrouse @.***> wrote: Yes if your router is switching channels the ESP32 will need to disconnect from the old channel to the new one. But it shouldn't be switching channels all the time. ESP32 has only one WiFi radio and does not support seamless channel changes. Is the channel entity changing in HA?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>