Always wanted to send push notifications from an embedded device into my phone and I wanted it to be easy and free. Google have the API with no quota for free and then a friend recommended me a web hosting site that offers free small apps hosting. So with all pieces in place finally decided to put words into code. Just released an app into the play store to do just that, the app has a web component written in python and hosted in a free account at heroku.com. App has not be tested carefully but then again, nothing is in the hacking community. Better to have something that nothing, bugs and enhancements can be latter added.
The concept is.
Create a message on the embedded device triggered by a simple action event. It may be a sensor read or other condition. Then post a message to the server with the desired text. That message is then pushed into the phone, For this there is a web API I created using python and Flask and from there the message is forwarded to the google cloud messaging site to get pushed into your phone.
The FUN PART, How to use it:
1. Install RemoteAlert on your phone (available for free from Google play store) (https://play.google.com/store/apps/details?id=com.soy.remotealert)
2. In the app you are prompted with your device UniqueId. That id is arbitrary created within the app, so it means nothing outside of RemoteAlert.
3. Using the UniqueId from the app just issue a post with a json containing the message you want to show on the device.
Sample Code:
After installing the app in your phone will see an screen similar to this:
Using the orange id from the above image you may issue a simple post to send a message.
Example using a curl command from the shell (you can just run this on the shell of any computer that has curl)
curl -X POST -H "Content-Type: application/json" http://remote-alert.herokuapp.com/post/a32b831c-7623-4c43-99cf-b614ff54e902 -d '{"message":"Hellow Push Message World"}'
A python sample will look like this:
import json
import urllib2
class RemoteAlert:
def send(self, device_id, message ):
data = { 'message' : message }
url = 'http://remote-alert.herokuapp.com/post/' + device_id
req = urllib2.Request( url )
req.add_header('Content-Type', 'application/json')
urllib2.urlopen(req, json.dumps(data))
return 'OK'
ra = RemoteAlert()
dev_id = 'a32b831c-7623-4c43-99cf-b614ff54e902'
print ra.send(dev_id, 'Hellow Push Message World')
This is how the received message looks like:
A simple POST with a JSon body with the mesaage is all it is needed. You may use https if you prefer is the same
http://remote-alert.herokuapp.com/post/<device_id>
{ "message" : "There you go" }
You may use the language of preference for this, C#, ruby, C++, perl, etc etc etc. And this can be used from anywhere not just an embedded computer. For example you may have an script on your PC start up to send you a message if somebody logged into your computer. Or a script on your raspberry pi that sends you your public IP when it changes...
This is a work in progress and software projects are never finished but just wanted to put it out there so anybody can use if wanted. All code will be posted open source to freely use. You may print it all into a shirt or a bed cover it will be public. There is nothing special in the code and that's the idea. We all should have basic features for free at least to hack away and learn.
More sample codes to come. Planning on adding some sample to push notifications directly from an arduino, if the web API needs to be changed for that it will be change. Adding the notifications straight from the arduino will make this even more fun.
The app is free, no personal info, no registration/login required. As long as there is free web hosting this will be online.
No message are stored on the server and no personal info. The android app has no sign in, there is no special permissions except the network access because without internet this will not work.
Said that, I would not recommend nobody to share confidential data using this. This app has no error correction, it just sends a message to the google cloud messaging to get push into your phone as soon as you post it. However the Google Cloud Service do not push the message to the phone instantly, from testing I have seen that messages may take close to a minute to get to the phone. Normally I get the messages in 20 secs more or less (haven't time it carefully).
If anybody use it, add a comment bellow so others in the community can benefit, be gentle but if it does not work please post it as well. Save time to others if you do not like it, or vice-versa.
Sample video just to have an idea of how much time it takes for the message to be sent and received. Un-edited just to show a real world sample of the time it took.
Code from the video: https://github.com/soynerdito/RaspberryPiTalk/blob/master/in_out_sample/push_no_block_event_led.py
library https://github.com/soynerdito/RaspberryPiTalk/blob/master/in_out_sample/remotealert.py
Hope this can help others, this is just a simple project put together to help me do other projects faster. I will blog again in progress and features, take care to all!