In the last video we talked about linking our particle cloud account with our gmail account by using IFTTT and this was great for some really interesting projects that can get quite complicated and integrate lots of different services but IFTTT is a little bit slow sometimes it can take several minutes for the trigger to be processed because it is a free service. So if you're using your Raspberry Pi in an application where timing is quite important and you want it to respond very quickly to an event you can keep your entire project within the particle cloud only and publish between say Raspberry Pi's or other particle devices so on the bench I have my trusty Raspberry Pi 3 B with the same LED circuit as in the last video and on the left here I have a Raspberry Pi Zero W if you don't know what that is it's just a small footprint Raspberry Pi that has Wi-Fi and bluetooth on board so it's really really good for small power efficient and enclosed projects that are going to be installed somewhere like a remote sensor so here is the here is the project that I want to build.
I want to flash this LED for the number of times but a button is pressed so on the first press I want the LED flash, on the second press I want it to flash twice, and so on and so forth and then the second button is just a reset button to reset that total count. So even though they're both sitting on the same table these PI's are connected by nothing other than the particle cloud so all of all of this data is going to be going through the particle cloud only there's no physical connection. So we can grab the demo code for this section and the first the first piece of code is for the publisher that's the PI 0 so I'm going to go and scroll to the top of that application this publishing script would work equally as well on another PI 3 but they'll both be compatible I'll just draw it here as a PI 0 but the GPIO is the same. So after copying that example code I can go over to particle build there's our application from last time I'm going to create a new application that I'm going to call it pub for publish and just paste in that code and save that. Now I can go over to what we can do is flash this now so you can see our target is currently set to the pi3 B so if you go over to the Left menu for this crosshair symbol you can see the devices that are registered to your account, I've already registered the PI 0 to my account so I'm going to select that, and now I can hit flash, and while that's flashing I'll go grab the subscriber code, that's down here. So there is the subscriber code demo, copy that and any minute now the Pi will reset okay so the PI 0 W has been flashed with its code I'll now go and create a new app and call this sub for subscribe and paste it here and now I need to set my target to the PI 3 B need to save my project and flash that device, while that's flashing let's take a look at what this is doing you can see that the subscriber is subscribed to a pretty-pretty non unique event name but impressed is it's short it's pretty it's pretty general purpose but you can see that we've got this extra argument now for the SUBSCRIBE option what we're doing here is restricting the instances of this event to only come from my devices, these are devices that are only registered to your own account that way you can use much simpler, neater event names because you're making it a private event only within your account.
Okay, that's finished flashing so we should be ready to go let's have a look at how this works. This is my publish button I think so I'll press that and yes so you can see immediately the LEDs flash the ones if I press it again we get two flashes and of course three times you get three flashes could do this all day but will reset so I've hit the reset button nothing appears to happen but if I press the publish button once more we only get a single flash so just as a bit of a helper here we can have a look at what's going on behind the scenes by opening up the particle console so if we click on this icon down the bottom key a second from the bottom this graphing icon we can take a look at what particle is doing behind the scenes so here we are in the particle console and it's currently waiting for some events now that it's opened so if I press my button we get a button pressed event and because I'd already pressed it once before the data that is sent through is two. We can see that it came from our PI 0w and we even have a timestamp now scrolling along the top you we have kind of like a timeline of events so if I press that button again we see that instantly we get the data three coming through from button pressed and of course it's coming from our PI zero W so what happens if you have events coming through really really quickly like if I mash this button lots of times okay so I definitely pressed it more than six or seven times but I only got up to nine, so this is like there has to be a little bit careful of in the particle environment if you're throwing too many published events in a short amount of time they'll be ignored there is a maximum rate at which you can send data.
So that wraps things up for this chapter we've had a look at some internet of things services and how we can integrate our Raspberry Pi into them I've had a look at IFFT and how it can link services and we've also looked into particle and how we can handle more time-sensitive events. If you want to dig a little deeper and we recommend checking out some of the example applications as well as going to the documents section which you can find with this document tab here this has a lot of example code that you can have a look at over on IFTTT just have a scroll through the demo applications that are available if you're looking for some inspiration these are really good templates to work off I'll see you later
Makers love reviews as much as you do, please follow this link to review the products you have purchased.