Monday, July 20, 2015

Push notifications from Raspberry Pi

Often it's useful to just receive information from a Raspberry Pi. Surely Yowsup could be nice, but you need a phone card and also it's not a simple system to use.

Setting and using Whatsapp with Yowsup can be a nightmare and sometimes it seems a bit unreliable. I do not know if it's a Yousup issue or maybe from how I use the libraries (but I found other Yowsup users with similar problems).

If you just need to receive information from the RPi, without sending them, the solution could be using push notifications. These are messages sent to your smart device. The device can be configured to inform you of the incoming message as soon as this is received.

I searched a lot for different ways to get info from my RPi. One of the best systems I found seems to be Pushover.

First of all I have to say that this service is NOT free (I'm not affiliated with them). Anyway it's quite reliable and it doesn't cost too much as for less than $5/os (but first week is free to try) you have a lifetime service!

I specified cost for os as this service has an os based fee. You pay to use it on an operating system (eg.IOs or Android) and you can receive notifications on all of your device with that os installed.
Refer to their faq for more info about this.

What I like from Pushover.net is the ability to configure several different applications, each one with its own icon and that can send push notifications to the device(s) you like.

For example, you can have Pushover app installed on both the smartphone and the tablet, but you can choose to send the notification to just one of them or both.

Of course, using push notifications means that you just need an internet connection on the RPi and no phone card at all.

When you sign in at Pushover site, you get a user code that will be used on all of your applications. For every application that you create, you will receive an additional code.
Both these codes must be specified to make you application work.

Let's see an example:

import httplib, urllib
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
  urllib.urlencode({
    "token": "this_is_the_application_code",
    "user": "this_is_the_user_code",
    "message": "3D printing is ended",
  }), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()

This is the script I'm using to notify that a 3D printing has ended correctly (without my codes of course). As you can see it's extremely simple! To use it, I specified in the OctoPrint configuration to call this script in the PrintDone event.

This is what happens on my iPhone:


As you can see, when you open the Pushover app, the app icon is shown beside the notification.

You can also specify a link inside the message that can be opened from the receiving device, if you need it.

The script above has been made with Python, but it can be used with almost every language you can think of. Just take a look at the Pushover.net site for a full list and examples.

As this service is managed from a remote server, you can just forget your script after finished typing and testing them. No updates needed, so much less hassle for us.

This is just a small overview of this nice notification system. I've been quite satisfied of it and I think it really worths the price.

2 comments:

  1. Instead of pushover, you also can use https://www.pushsafer.com > they have apps for Android, iOS, Windows 10 (Desktop, Phone) and also support Webpush for Chrome and Firefox. With pushsafer you have the ability to set up your notification and change title, text, icon, sound, vibration > and you also can send image. It works great i use it by my self!

    ReplyDelete

Note: Only a member of this blog may post a comment.