LUNATICOASTRO.COM

PushOver messages from a Windows script (.bat) file

CloudWatcher, Dragonfly…

It is often very useful to be able to receive instant notifications upon certain events happening in your observatory … or just at your computer.

Nowadays we’re recommending the PushOver tool for this purpose – as it supports a wide range of devices, works great, and, while not totally free, the price is really reasonable (at the time of writing, just $5 for a lifetime license: https://pushover.net/pricing )

With this post we’re trying to cover most Windows versions and computers active now – including 32 bits systems.

Note: our network-enabled products already have this capability built in (the Solo, Dragonfly…); we’re writing this post for added flexibility and offering more options.

So, first step, create a PushOver account if you don’t already have one. There is a trial period, so no need to pay yet.

You are going to need two “keys” or “tokens”; one is attached to your user (clearly visible from PushOver homepage, once you register), and other one attached to an application.

In the very same homepage, you can create an application:

… it is a really simple process, and you can even add a PNG image to personalize your messages.

Ok, with this set, we have to arrange things in the Windows side. To make this as universal as possible, we’ll be using a 32 bit version of the curl tool. I downloaded it from the curl project page, windows section. 

To make things easier, I have made a smaller distribution, with just the files strictly needed for our purpose (including the copyright notice). You can download it from: https://lunaticoastro.com/aagcw/Min-Curl32b.zip

You have to find or decide on a suitable folder to extract the contents; I’d personally use my “user” folder, creating a “scripts” sub-folder inside. That would be, for me, C:\Users\Jaime\scripts

… wherever you choose, open the zip file, select all files, copy, browse to this folder, paste. Or extract. Whatever method you prefer.

There is a sample script inside – “sample-message.bat”. Please edit it now; notepad will do.

rem You will probably need to “cd” (change directory) to the folder where the curl program is installed
cd \Users\MyUser\scripts
curl -s –cacert curl-ca-bundle.crt –form-string “token=APPLICATION_TOKEN_HERE” –form-string “user=YOUR_PUSHOVER_USER_TOKEN_HERE” –form-string “message=Hello there!” https://api.pushover.net/1/messages.json

You have to modify four things inside the script:

1: the path (folder) for the cd (change directory) at the second line

2 and 3: the tokens, application token, and user token

4: the message you want to send! (otherwise it will be Kenobi’s “Hello there”)

A functional script will look like this one:

cd \Users\Jaime\scripts
curl -s –cacert curl-ca-bundle.crt –form-string “token=laksdfasdfasdfasdfasdfasdf” –form-string “user=ththsethsethsqrwt” –form-string “message=Hello there!” https://api.pushover.net/1/messages.json

Once you’re done, please run the script – you’ll receive a message in your phone in a few seconds, all going well.

Applying all this to the CloudWatcher.

The CloudWatcher Windows software can be set to run two scripts, one when the weather turns safe, another one when unsafe. It is set from setup->script.

So please, using the script above as a template, create one or two new scripts with the message you want to receive on change of conditions. For the example, I have named them “weatherSafe.bat” and “weatherUnsafe.bat

script selecting in CloudWatcher

… the interface is a bit awkward to be compatible with all existing Windows versions around – we astronomers tend to be quite reluctant to update a perfectly working Windows version… – we’ll remove XP compatibility (and make it more friendly) in the future …

Click “Path” to select the folder you chose above, then type the name of the script. If you want a script run for both conditions, you have to repeat for each one.

… that’s it!

You can set “don’t disturb” hours in PushOver if you don’t want to receive annoying messages during the day… or the night.

On the other hand… if you can’t afford to miss the message, you’ll want to add:

–form-string ‘priority=2’ –form-string ‘retry=30’ –form-string ‘expire=600’ 

to the script to receive a high priority message, retried every 30 seconds – that will keep annoying you until acknowledged or the 600 seconds timeout expires.

To avoid any doubt, the curl line would look like this:

curl -s –cacert curl-ca-bundle.crt –form-string “token=laksdfasdfasdfasdfasdfasdf” –form-string “user=ththsethsethsqrwt” –form-string ‘priority=2’ –form-string ‘retry=30’ –form-string ‘expire=600’ –form-string “message=Hello there!” https://api.pushover.net/1/messages.json

… not as bulletproof as the Good Night System, but may come handy at times.

And of course you can add this functionality to your Dragonfly scripts, for example.

For future posts… curl is really a handy tool to have around. Do you know you can it to access the Dragonfly relays and sensors? As in close a relay from a simple script? Or to download a JSON data file from the Solo?