Monitoring Your Particle Devices With IFTTT
I build plenty of IoT demos here at SitePoint but there’s one thing I’d never considered – keeping track of whether or not my devices are online! It’s one of those downsides of the Internet of Things… without the Internet, they can become rather powerless things!
In this article, we’ll explore how to quickly and easily set up monitoring for Particle devices like the Core and Photon using IFTTT, Slack and Google Spreadsheets. We’ll get notifications on Slack about when our devices go online/offline and we’ll record that in a Google Spreadsheet for our records.
If you’re totally new to the Particle ecosystem, you can find out more on the Particle website. You may know them as “Spark Core”, as that was their previous name before they rebranded themselves. I put together a demo with the Particle Core and NeoPixels a few weeks back too. They’re basically cloud connected microcontrollers that are a lot of fun to work with!
What is IFTTT?
IFTTT is a wonderful online service that is short for “If This Then That”. It allows you to set up rules for various services that either provide an action that can be triggered remotely or provide the trigger for our actions. For example, about two months ago I built a demo on Connecting LIFX Light Bulbs to the IoT Using IFTTT. In that demo, smart lightbulbs would change color or turn on and off depending on various rules I’d set. If I set my Jawbone UP to sleep mode, my lights would know to turn off. If my favorite sporting team were playing, my lights could change color to the team colors to get some team spirit happening!
Connecting Particle to IFTTT
This article will assume you’ve already got an account on IFTTT set up and ready to go. If not, sign up on the IFTTT website to get started. If you need more info, we covered it in more detail in the previous IFTTT article mentioned above.
To get started, head over to the Particle IFTTT Channel page (or search for it on the IFTTT “Channels” page) and click “Connect”:
It will prompt you for your Particle username and password. Enter those in and click “Sign In”:
Then click “Okay” to give IFTTT access to your Particle data:
If all goes well, you should have a “Channel Connected!” success message appear for a little bit and a Particle channel page that looks like so:
Connecting Slack to IFTTT
Slack is pretty similar to connecting up the Particle channel, however it asks a few more questions. Start at the Slack IFTTT Channel page and click “Connect”:
It will ask you to sign into the Slack domain you’d like the messages to appear inside. I used a domain I’ve got for an upcoming website project, rather than driving people at the SitePoint channel insane with my Particle alerts!
Then click “Authorize” to allow Slack to post messages into that Slack domain.
Once your Slack domain and IFTTT are able to talk to each other, you should have a Slack Channel page that looks like so:
Creating Our Particle and Slack Recipes
Now we’ve got Particle and Slack connected up to IFTTT, lets create our recipes with them. Click on the dropdown with your name in the top right and choose “Create” to create a new IFTTT recipe:
Click “this” to get started choosing our trigger:
Type in Particle to find the Particle channel and select that as our trigger:
There are a range of triggers you can use with the Particle Channel. You could have it run when an event you’ve defined on your Particle fires, or when a variable changes. For our example, we’ll choose “Monitor your device status” which will give us access to when the device goes online or offline:
In the next screen, choose the Particle device you’d like to monitor. (Mine was called “IagoCore” for reasons I don’t fully remember. It was a Lion King reference that made sense at the time.) Then choose the status you’d like to respond to. For my first rule I’ve chosen “Offline”, which will tell me if the Particle Core goes offline. Once you’ve made those all important choices, click “Create Trigger”.
Then, we choose “that” to move into defining our response to the Particle trigger:
Then type in “Slack” to find the Slack channel:
At the time of writing, there’s only one action option here, so this bit should be simple. Choose “Post to channel”, as that’s exactly what we want to do!
Next, you can choose which channel you’d like IFTTT to post into. I chose the “general” Slack channel.
Turns out, you can also choose Direct Messages, so if I did set it up in SitePoint’s slack channel, I wouldn’t necessarily need to drive everyone insane after all! I could choose one person in particular!
You can also customize the message and title of the message to your heart’s content. Once you are happy with it, click “Create Action”.
You can customize the name of the recipe you’ve made, or just hit “Create Recipe” to save it and start it running. If you’d like extra alerts whenever your device goes down, you can also tick “Recieve notifications when this Recipe runs” so that it alerts you on your phone if you’ve got IFTTT installed.
When it is all done, you’ll see it waiting in your recipe list for the Particle device to go offline:
You can repeat this process to create a second recipe that runs when it comes back online too. I created one for both. This is what they look like when my Particle Core goes offline and online:
Google Spreadsheets and Particle
Another option for the action you can take, is to log the online and offline activity in a Google Spreadsheet via IFTTT. You can run both this one and the Slack one simultaneously, so you’ll get alerts and have a nice history of how often the Particle device is coming online/offline throughout the week.
Head back to the “Create Recipe” page and set up another Particle trigger for when your Particle device goes offline (just as we did earlier).
For the action, type in “Google” to find the “Google Drive” channel. Choose that one.
We’re doing things in a bit of a different order here. Chances are you don’t have the Google Drive channel connected yet. Luckily, IFTTT prompts you to connect it up before going further:
Once you’ve connected it up, you’ll get to the “Choose an Action” screen. We’ll want to choose the “Add row to spreadsheet” option.
Finally, we can set up the spreadsheet settings. Set up a name for the spreadsheet – make sure it is exactly the same for all recipes you want to go into the same spreadsheet otherwise you’ll have duplicates! It will create a new spreadsheet if it does not find one with that name.
Adjust the row contents if you’d like (I kept them the same), the columns are marked with
|||. You can also set which folder you’d like the spreadsheet to be saved to. When you are happy with that, click “Create Action”.
Feel free to create a similar recipe for when it comes online too. Then take a look at your Google Spreadsheets and you should have a new spreadsheet:
Within that spreadsheet, once your Particle device has come online/offline a few times, you should have a good set of data waiting for you:
As you can see, setting up logging and alerts for your Particle Cores that are out in the wild is really simple to do thanks to the power of IFTTT! Do you have any IFTTT channels you’ve found that help you manage your Particle devices? Leave a note in the comments or get in touch with me on Twitter (@thatpatrickguy)!