Reputation: 1309
I am new to Raspberry Pi and Google Cloud Messaging. What I want to do is as follows: Raspberry Pi is reading some sensor data and I want to send the data to my Android Phone in real time, i.e. as soon as a sensor reading is received it will be pushed to the phone. I looked into various ways to do this, and think using Google Cloud Messaging will be most suitable for me. So, I did the following:
Then ran the following program from RPi. The API in the code is the above API (taken from Google Cloud Messaging HTTP Error 400: Bad Request)
import json
import urllib
import urllib2
class RemoteAlert:
def sendGCM(self, regid, email, entry_id, date_modified, kind):
url = "https://android.googleapis.com/gcm/send'
apiKey = MY_API
myKey = "key=" + apiKey
json_data = { "registration_id": regid, "data" : {
"entry_id" : entry_id,
"email": email,
"date_modified": date_modified,
"kind": kind,
"reg_id": regid,
},
}
headers = {'Content-Type': 'application/json', 'Authorization': myKey}
data = urllib.urlencode(json_data)
req = urllib2.Request(url, data)
req.add_header("Authorization", myKey)
f = urllib2.urlopen(req)
response = f.read()
f.close()
print "DONE"
obj = RemoteAlert()
print obj.sendGCM("1234", "[email protected]", "24", "10-09-2014", "VAL")
My issues and questions:
I have already checked the following pages for help:
Any help is appreciated! Thanks!
Upvotes: 3
Views: 1480
Reputation: 1309
I could not solve the above error. But I could successfully send push notification to Android phone using Amazon SNS with GCM!
From my IoT device I sent sensor data to my web service hosted on Amazon EC2. From EC2 I pushed the data to Android phone using SNS and GCM. It worked without any trouble.
I used web services to send data to EC2 instance. But Amazon Kinesis is a more efficient way to stream data to Amazon cloud in real time.
AWS gives free membership to try out many of their cloud utilities. Kinesis is not free, hence I didn't try it out. But I know people using it.
You can download entire Android project source code from Amazon SNS official tutorial site and use it after a little bit of personalization.
Upvotes: 0