Best practices for controlling pybd wirelessly?

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
kesterlester
Posts: 21
Joined: Sat Nov 17, 2018 10:04 pm

Best practices for controlling pybd wirelessly?

Post by kesterlester » Sat Feb 06, 2021 1:15 am

I have a pybd (D series) which I have embedded in a home-build project that manages certain home automation tasks.

It was no trouble to connect it to the house wifi, and when my device senses that certain events have happened, it cheerfully uses urequests to send data to web servers which can log those reports etc. Getting data wirelessly off the pybd therefore seems trivial.

However it is not clear to me what the best way of sending to the pybd is.

I know I could write a polling routine on the pybd that pings a web-server somewhere every 10 seconds to ask if there are waiting commands which it should process, but this seems HUGELY wasteful to me. I am sure there must be 100 proper ways of avoiding polling .... but I don't really know what they are.

If my pybd had a publicly reachable IP address I might look into seeing how I would write something that listened on some socket or other for a connection .... but on a home system behind multiple layers of NAT and not having the patience to work out how to push things through the NAT I presume that I don't want to go there -- and I don't have much experience of sockets anyway.

Is there some kind of off-the-shelf pyhon library for pushing notifications to a pybd whose details I won't have to fully understand, save for knowing that I can register some kind of callback that will fire when a message comes in ?

User avatar
jimmo
Posts: 2244
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Best practices for controlling pybd wirelessly?

Post by jimmo » Sat Feb 06, 2021 5:14 am

kesterlester wrote:
Sat Feb 06, 2021 1:15 am
Is there some kind of off-the-shelf pyhon library for pushing notifications to a pybd whose details I won't have to fully understand, save for knowing that I can register some kind of callback that will fire when a message comes in ?
I think the two best resources are

https://github.com/peterhinch/micropython-iot
https://github.com/peterhinch/micropython-mqtt

I think the idea here is that if you need to be able to send from outside your home network then you could run the server somewhere with a public address (and the pybd would connect to that from inside your network).

If you don't want to run anything on public addresses but you still want to be able to get through your NAT layers easily, something that I had an excellent experience recently with was Tailscale. Basically I have a (Linux) device on my internal network that acts as a coordinator for multiple other devices on my network (some running MicroPython). I installed the Tailscale client on both that Linux device and my phone, and now no matter what network I'm on, I can always access the Linux device by its hostname.

kesterlester
Posts: 21
Joined: Sat Nov 17, 2018 10:04 pm

Re: Best practices for controlling pybd wirelessly?

Post by kesterlester » Sat Feb 06, 2021 9:20 pm

Thank you for these tips. I will investigate them all.

Post Reply