Page 1 of 1

ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Posted: Mon Feb 01, 2016 5:33 pm
by beegee1962
I was looking into a solution to send push notifications from an ESP8266 module to an Android application. I know that this is possible with the Google Cloud Messaging service.

But what I found on the internet is using an external webserver, able to run PHP (or Python) scripts and using a MySQL server to store registration IDs.
ImageImage
So far so good, but why do I need to setup an external server with MySQL and PHP just to send messages to the Android devices. The ESP8266 has server capabilities build-in and has enough storage to save registration IDs in the Flash memory.
What I wanted is:
ImageImage

As I could not find any tutorial or example on the Internet how to achieve this, I started to write the code by myself.
And here is the result:
ESP8266 - Google Cloud Messaging without external server
Of course the code is open source and stored in my Github repository

Hope it helps someone.

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Posted: Tue Feb 02, 2016 5:17 pm
by wuyunzhou
good job.
yes, if the device can get the gcm api_key, and the android registration id, the device can notify without server.

so the first is to pass the android registration id from app to device,
then make a http request to Gcm server, like this:

POST /gcm/send HTTP/1.1
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Host: gcm-http.googleapis.com
Accept: */*
Authorization: key=${api_key}
Content-Type: application/json
Content-Length: xx

{"registration_ids":%s,"priority":"%s","time_to_live":%s,"data":%s}

registration_ids is a array with android registration ids.

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Posted: Tue Feb 02, 2016 8:26 pm
by beegee1962
wuyunzhou,
Correct, that is how it works. However I didn't use the "priority" and "time_to_live' keys.

ESP8266 GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Posted: Mon May 22, 2017 4:09 pm
by JamesRit
Hi. copying the form of the sample in my test project, allways get the error google is not defined. I can run the sample avobe with no problem, but with my test project, allways the same error. I dont konw why. Thanks.

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Posted: Tue May 04, 2021 6:43 pm
by milesstone
beegee1962 wrote:I was looking into a solution to send push notifications from an ESP8266 module to an Android application. I know that this is possible with the yowhatsapp apk Google Cloud Messaging service.

But what I found on the internet is using an external webserver, able to run PHP (or Python) scripts and using a MySQL server to store registration IDs.

So far so good, but why do I need to setup an external server with MySQL and PHP just to send messages to the Android devices. The ESP8266 has server capabilities build-in and has enough storage to save registration IDs in the Flash memory.
What I wanted is:

As I could not find any tutorial or example on the Internet how to achieve this, I started to write the code by myself.
And here is the result:
ESP8266 - Google Cloud Messaging without external server
Of course the code is open source and stored in my Github repository[/url]

Hope it helps someone.

You can get your ESPs to be publicly accessible by configuring port forwarding or DMZ properly on your router. You're pretty much out of luck if you're behind an ISP controlled NAT (basically a CGNAT). You can get a static IP from most ISPs for a small fee, which will enable you to do the same.

I'm afraid there is no simple way of doing "push" notifications without a service in the middle, unless you have a static IP on one of the devices, but there are some very convenient and easy to use services.

Visit dweet.io, its a cool service where you can store and retrieve data by using simple HTTP GET requests. I usually use it by making my ESPs send data there and making a simple android app or widget to get the JSON formatted data, and parsing it.