I have just found out about an application for Android called “Notify My Android” (NMA) this is a freemium (free for very limited use – with paid unlimited usage), that will allow you to send all sorts of notifications from your PC, Mac, If This Then That (IFTTT.com) or your Raspberry Pi.
What you will need
You will need to have the following to get my examples working
- Raspberry Pi running Raspbian (others may work but I have not tested them) connected to the internet
- Notify My Android Account + API Key (https://www.notifymyandroid.com/register.jsp)
- Android device with Notify My Android installed Price: Free+
Putting it together
I have found python, perl and Shell code for NMA that will run on the Raspberry Pi and all of them work very well. I am only going to cover the Perl version, but most work in the same way once you have them on your Raspberry Pi
Getting it working
Ok, lets look at the perl code first. This comes straight from NMA’s developer pages (https://www.notifymyandroid.com/dev.jsp)
On your Pi (local or remote SSH) enter the following command
This will create a directory, download the NMA perl script from the internet and then open a file for editing in the nano editor. This file will contain your API key from NMA that will tell them where to deliver the notifications too.
You can get this API key here – https://www.notifymyandroid.com/account.jsp, once you have an API key, copy it into the file and save the file by pressing
ctrl + o
ctrl + x
Then you can try sending a test notification to the device that has the Android application installed
perl nma.pl -apikeyfile=apikey -application=RaspberryPi -event="AN Event" -notification="Your Pi Says Hi!" -priority=-2
So what does all this mean?
- -apikeyfile=apikey – this is the file we created previously that contains your API key
- -application=RaspberryPi – this can be anything you wish and shows what send the notification
- -event=”An Event” – This is like a sub-title, again it can be anything you wish – so “Raspberry Pi rebooted” for example – if you want space be sure to use quotes “”
- -notification=”Your Pi Says Hi!” – The main body of the message – you could feed in variables like time & date the Pi rebooted for example
- -priority=-2 – What is the seriousness of this notification? A Number from Minus 2 (-2) to 2 (2) with 2 being emergency!
One of my example uses works with my guest post over on Class Think (http://www.classthink.com/2014/01/12/raspberry-pi-vocal-intruder-warning-system-project/)
# Detect movement using a PIR module
# Original Author : Matt Hawkins
# Date : 21/01/2013
# Speech output Added : Vincent Willcox
# Date : 12/01/2014
# Import required Python libraries
import RPi.GPIO as GPIO
# We need this next line so we can run the text to speech script later
# Use BCM GPIO references
# instead of physical pin numbers
# Define GPIO to use on Pi
GPIO_PIR = 4
print "PIR Module Test (CTRL-C to exit)"
# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN) # Echo
Current_State = 0
Previous_State = 0
print "Waiting for PIR to settle ..."
# Loop until PIR output is 0
Current_State = 0
print " Ready"
# Loop until users quits with CTRL-C
while True :
# Read PIR state
Current_State = GPIO.input(GPIO_PIR)
if Current_State==1 and Previous_State==0:
# PIR is triggered
print " Motion detected!"
# Tell the Pi to run our speech script and speak the words
# motion dtected! - anything after the .sh will be read out.
cmd_string = './speech.sh motion detected!'
# now run the command on the Pi.
cmd_string = 'perl ./nma.pl -apikeyfile=apikey -application=RaspberryPi -event=Motion -notification="Motion Detected in Study www.talktech.info" -priority=2'
# Record previous state
elif Current_State==0 and Previous_State==1:
# PIR has returned to ready state
print " Ready"
# Wait for 10 milliseconds
print " Quit"
# Reset GPIO settings
For this to work, you will need the nma.pl and apikey files in the same directory as this script.