Particle Device "Is It Up" Report Generator

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:

  1. You are using the excellent (and free) Hook.io service
  2. You are using Mailgun (also free) to send emails

To use follow these steps:

  1. 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).

  2. Go to Hook.io, sign in, and create a new service.

  3. Go down to the “Hook Source” section and paste the code from here)

  4. 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. The variable 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 accurate online status. Create a Particle.variable on your Electron and have it return something (doesn’t really matter what). You can omit expectedValue 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.
  1. 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
  2. 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.

  3. 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.

10 Likes

Hey @harrisonhjones! Just wanted to say THANK YOU for such an awesome and complete write-up, and a useful utility!

1 Like

Great instructions. For some reason when I run the test I get “Mailgun is not loving your login or password”. Can you provide more details on what exactly to put in the defined variables in hook.io? For domain name, I used the full domain name as it shows under the domain information page and for user name I used the SMTP login in that same page and password the "default password’ in the same page. ham I missing?

Thanks

Andre

1 Like

I just resolved my issue. I looked at the code and figured I need to remove the domain name from the username variable. It worked. I could have sworn I tried that before I posted the question. Oh well, it is working now, Thanks for a very useful guide.

1 Like