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

Add a function to send ping packets #461

Closed
wants to merge 1 commit into from

Conversation

felipediel
Copy link
Collaborator

@felipediel felipediel commented Oct 25, 2020

Some Broadlink firmwares have a watchdog timer to ensure that the device remains connected to the cloud. The devices reboot when they don't receive heartbeat messages from the cloud for more than 3 minutes.

Lots of users want to block access to the internet for privacy reasons and this is causing their devices to reboot periodically. This PR comes to add a function to send heartbeat messages and keep the devices awake even without access to the cloud.

Credits to @marcan, who found the watchdog packet.

Fixes: #458

@felipediel felipediel marked this pull request as draft October 25, 2020 00:28
@felipediel
Copy link
Collaborator Author

felipediel commented Oct 25, 2020

@marcan Thanks for your dedication to this. Is this code working?

import broadlink as blk
import time

while True:
    blk.keep_alive("192.168.0.17", 80)  # Example device
    time.sleep(120)

@KTibow
Copy link
Contributor

KTibow commented Oct 27, 2020

Any way for me to test this? Just pull the branch and install?

@felipediel
Copy link
Collaborator Author

felipediel commented Oct 27, 2020

This test requires a specific environment:

  1. Enable UPnP on the router and connect a UPnP device to this router (I connected another router).
  2. Block outbound connections from the device on the firewall.
  3. Run Home Assistant and set up the Broadlink integration.
  4. Wait 10 minutes.
  5. Check the remote entity history. Messy.
  6. Install this branch on your computer and run this script.
  7. Wait 10 minutes.
  8. Check the remote entity history. It needs to be ok. 100% availability.

This test is dangerous. We don't know if blocking the device is healthy in the long run. I already have the technology to test, so you don't need to take the risk if you don't want to.

@KTibow
Copy link
Contributor

KTibow commented Oct 27, 2020

Okay. I was thinking about testing with the SP4, but I don't control the router I have and your SP4 support PR hasn't been merged yet. Thanks for letting me know.

@felipediel
Copy link
Collaborator Author

felipediel commented Oct 28, 2020

I tested. It's working! 🎉

I'm gonna make some fine adjustments and then I release for review...

@KTibow
Copy link
Contributor

KTibow commented Oct 28, 2020

Sad that this didn't make it into 0.117, but hopefully this makes it into 0.118!

@felipediel felipediel force-pushed the keep-alive branch 3 times, most recently from b0af1ef to 0f46280 Compare October 29, 2020 06:06
@felipediel felipediel marked this pull request as ready for review October 29, 2020 06:11
@marcan
Copy link

marcan commented Oct 30, 2020

Sorry for the late test. I tested this in lieu of my previous crontab hack:

import broadlink as blk
import time

while True:
    blk.keep_alive("192.168.7.255", 80)
    time.sleep(120)

(I had to change the parameters from a tuple to separate host/port)

It works fine, I can see the packets going out and no reassociations from my devices.

@felipediel felipediel changed the title Add a function to send heartbeat messages Add a function to send ping packets Jan 27, 2021
@felipediel
Copy link
Collaborator Author

Closing to merge with the dev branch. We no longer merge directly into master in order to keep things clean.

@felipediel felipediel closed this Jan 27, 2021
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

Successfully merging this pull request may close these issues.

Support sending cloud ping packets (packet type 0x01)
3 participants