I have received help elsewhere about this obstacle but unfortunately it’s going over my head at the moment. Not…way over, about an inch, but, still - it’s going over my head. I’m pretty good at “adapting” code, and adding to existing code, I’ve cooked up reasonably involved projects before on the Arduino platform, but I am not an experienced coder at all so would really welcome some help turning advice/help into actual code. I don’t want to pester ScruffR anymore - who has been helpful and patient. Hence this new thread.
Background (skip if you’re not interested!)
Basically I am trying to create something like the VoicePage checkout system for the small ‘mom and pop’ shop I work in. There are two checkouts, an office and a little workshop. It would be SO useful to send messages between these places with buttons and LEDs rather than picking up the internal telephone all the time. I had thought to do this with spark.subscribe/spark.publish and four particle cores. I got so excited when I saw the spark core (as was) being talked about online - it all sounded like it would be easy for someone who had been able to cobble arduino projects together by writing the odd bit of code but mainly patching in bits of code or adapting code examples. Especially as all I’m really doing is flicking LEDs/relays etc on and off in response to inputs. Things I’ve easily been able to do with the Arduino. It sounded like the Spark platform would enable me to do that but with a small family of devices due to its cloud based nature. However the more into the project I have got the more limitations/restrictions/bugs I have found which need to be overcome with programming nouse I don’t yet(?) have! Things like adding a heartbeat to a particle project to overcome the bug (now fixed, it seems!) whereby if the particle dropped its WiFi connection, which mine seem to do a lot, it didn’t automatically resubscribe. All concepts I can understand, and no problem for a real programmer, but an insurmountable hurdle for me so far. I’m also not complaining, merely explaining my difficulty.
So, my issue:-
I have code which is ‘adapted’ from Quantumly Entangled LEDs and it’s working. I can make two separate digital pins go high or low on a particle core based on inputs on another particle core being pressed using spark subscribe and spark publish. I’ve been given some advice about how to adapt/extend this code but it is just a bit too abstract for me. Does anyone have time to hold my hand?
This is the advice I have been given:-
If you wrap your sending device ID and any other useful info into your event name and data payload you can just get along with one handler.
There might me some doc reading to be done, but one hint is that the event name you are subscribing to is only a prefix filter (e.g. CoreToggle would fire for CoreToggle1 and CoreToggle2 and even CoreToggleAnyOtherSuffix).
Just check the contents of toggle along side onOff.
If you use your DeviceID rather than an arbitrary number you can even flash the same code to all of your Cores and each Core would know if it’s receiving own events or one of the others without the need to set that number in code for each individual Core. […]
when you subscribe to e.g. “myPrefix” your handler will be triggered for anything that starts with “myPrefix”, so you can use do e.g. Particle.publish(“myPrefixLED1”, “ON”) and Particle.publish(“myPrefixLED2”, “OFF”) and both wil trigger the same handler. To check which LED is meant, you look at the first parameter you called *toggle.
Or you send something like “LED1=OFF”/LED2=ON", split this up and use the seperated values.
So as I say, I can understand this in principle, I just can’t turn it into code. I would be happy to be pointed in the direction of a code example, and no doubt(!) I’ll be able to strip it for parts and make it work for my situation. But I can’t find one online and I can’t write one from where I am now. Which is my failing.
The other thing is, I am a bit at sea re: button debouncing. The button debouncing in my above code examples on pastebin work a treat, but they mean introducing lots of new variables each time I add a button. Is there a library that will handle debouncing for me? Any recommendation there?
THANKS for your help in advance, much appreciated.