Hi everyone. In the middle of answering @benjiiiiuk’s question over in this thread I went a bit overboard and built a fairly featured Particle device “is it up?” health monitor service thing.
WHAT DOES IT DO?
The health monitor script I wrote (available here) checks an arbitrary number of Particle devices to determine if they are “up”. When done it generates a “Is It Up” report which gives you the statues of your devices (are they up or not). It then sends this report to an email of your choosing.
It generates a report email that looks like this:
THIS IS COOL. HOW DO I USE IT?
The script, as is, assumes two things:
- You are using the excellent (and free) Hook.io service
- You are using Mailgun (also free) to send emails
To use follow these steps:
-
Head over to Mailgun.com and create an account and a sandbox domain. Click your sandbox domain and make a note of the username, password, and domain (you’ll need it later).
-
Go to Hook.io, sign in, and create a new service.
-
Go down to the “Hook Source” section and paste the code from here)
-
Edit the code to suite your needs (you will want to change these two lines to match your devices):
devicesToCheck.push({deviceID: ‘39002a000547343432313031’, method: ‘info’});
devicesToCheck.push({deviceID: ‘350037000347343337373739’, method: ‘variable’, variableName: ‘fv’, expectedValue: ‘ninjas’});
- There are two methods. The
info
method just checks the cloud to see if the device is connected. This works best for Photons which maintain a constant connection to the cloud. Thevariable
method actually goes out and tries to query the device for a variable value. This is best for an Electron which doesn’t always have the most accurateonline
status. Create aParticle.variable
on your Electron and have it return something (doesn’t really matter what). You can omitexpectedValue
if you don’t want to use that feature. You can also use a pre-existing Particle.variable in your code. Note Every time you grab a variable value from an Electron you are using up data. These calls are not “free” but they should be fairly cheap. Just don’t run your script too often or setup two different services, one for Photons with more frequent calls and one of Electrons with more infrequent calls.
-
Save your service. Then head over to the Hook environmental variables page. You need to add the following variables:
- APP_PARTICLE_DEVICE_ISUP_TO_EMAIL - This is the email you want to send the report to
- MAILGUN_SMTP_DOMAIN - This is the domain of your mailgun account
- MAILGUN_SMTP_PASSWORD - This is the password for your mailgun email account
- MAILGUN_SMTP_USERNAME - This is the username for your mailgun email account
- PARTICLE_API_KEY - This is your Particle access token
-
Run your service and check your email. If it worked, awesome. You can set the Hook to automatically run every X minutes/hour/days. Just check the “Schedule Service on a Timer using Cron” checkbox and follow the instructions.
-
Let me know if you have any questions or issues.
HOLY **** THIS LOOKS COMPLICATED
It does look complicated but it isn’t, really. If you have any questions or problems let me know and I’ll be happy to help.