python - Issues+Clarification: Sending message from Raspberry Pi to Android Phone using Google cloud Messaging -
i new raspberry pi , google cloud messaging. want follows: raspberry pi reading sensor info , want send info android phone in real time, i.e. sensor reading received pushed phone. looked various ways this, , think using google cloud messaging suitable me. so, did following:
created gcm project online in project, generated server api key raspberry pi's ip address.then ran next programme rpi. api in code above api (taken 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} info = 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", "xxxxxx@gmail.com", "24", "10-09-2014", "val") my issues , questions:
when running above code rpi getting 'authorization error 401'. why? have completed steps properly? can run above code rpi without installing gcm server anywhere? i don't know kind of code need write in gcm project site receive/send/use message. after part works, write client programme receive rpi info in android phone.i have checked next pages help:
sending notifications google cloud messaging php gives me unauthorized error 401 http://fryerblog.com/post/30057483199/implementing-push-notifications-with-gcmany help appreciated! thanks!
i not solve above error. send force notification android phone using amazon sns gcm!
from iot device sent sensor info web service hosted on amazon ec2. ec2 pushed info android phone using sns , gcm. worked without trouble.
i used web services send info ec2 instance. amazon kinesis more efficient way stream info amazon cloud in real time.
aws gives free membership seek out many of cloud utilities. kinesis not free, hence didn't seek out. know people using it.
you can download entire android project source code amazon sns official tutorial site , utilize after little bit of personalization.
android python raspberry-pi urllib2 google-cloud-messaging
No comments:
Post a Comment