Help to make 'intelligent' WiFi buttons to control Raspberry Pi

Hello all,

I have built a dog treat machine using a Raspberry Pi & Python.
At the moment I’m using Telegram to send instructions to put the machine into auto mode, dispense a treat, take a photo of the hound etc. etc. The next step is to create a wireless push button that lights up via internal LEDs and plays tones via a piezo. The Pi would tell the button when to flash/play tone and then the dog needs to push the button so that it sends a command back to the raspberry pi to dispense the treat on a successful push. Would really appreciate some help in how to achieve this (please note I’m a beginner but keen to learn). Eventually I want to create three or four buttons (each with different “come press me” sounds located around the house for the hound to search out the right one and press the button in order to get his treat. I have bought a photon as thought they might be a good way of starting to build the first WiFi button… but I’m a bit lost at the moment.

Thanks
Clive.

You can use the publish/subscribe approach:

https://docs.particle.io/guide/getting-started/examples/photon/#the-buddy-system-publish-and-subscribe

Kenneth, I’ve just had a read through this, must admit… I’m a little confused. Am I right in saying that the publish is pushing to the particle cloud? I’m actually after a solution that lets the Photo talk directly to the Raspberry PI as the signal from the push button needs to work without any delays.

Thanks
Clive.

If that’s the case… You will need to write up your own TCP server/client code to do so…

1 Like

Would I be going down the right route with these as a starting point…
PHOTON > https://docs.particle.io/reference/firmware/photon/#tcpclient
RPi > http://www.binarytides.com/python-socket-programming-tutorial/
Apologies for my beggineritus.
Cheers
Clive.

While a direct connection is the fastest, I don’t think the cloud is as slow as you are imagining. I have several buttons and infrared remote control receivers and I haven’t measured the latency, but it’s well under a half second. For all practical purposes it seems instantaneous. You use Particle.publish on the Photon. The key to making it fast is that the event receiver (the Pi in your case) uses HTTP Server-Sent Events (SSE) to receive the events. In SSE, the client (Pi) has a constant connection to the server (particle.io), so the events are pushed out immediately. It’s not polling, it’s pushing. You can implement SSE in pretty much any language. I used Java, but you can use Node, Python, whatever you prefer.

OK great. That might simplify things for me.

If possible, would you be able to give me a ‘dummies guide’ quick bullet point rundown as to what I need to do.

I haven’t programmed since my A level in Computer Science… many years ago!
It took me about two weeks just to write the python code for treat machine… but I’m learning lots.

Thank you
Clive.