ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

User avatar
beegee1962
Posts: 11
Joined: Fri Jan 08, 2016 11:11 am
Location: Manila, Philippines
Contact:

ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby beegee1962 » Mon Feb 01, 2016 5:33 pm

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.

wuyunzhou
Posts: 12
Joined: Fri Apr 10, 2015 3:46 pm

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby wuyunzhou » Tue Feb 02, 2016 5:17 pm

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.

User avatar
beegee1962
Posts: 11
Joined: Fri Jan 08, 2016 11:11 am
Location: Manila, Philippines
Contact:

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby beegee1962 » Tue Feb 02, 2016 8:26 pm

wuyunzhou,
Correct, that is how it works. However I didn't use the "priority" and "time_to_live' keys.

JamesRit
Posts: 2
Joined: Fri May 12, 2017 12:03 am
Location: Latvia
Contact:

ESP8266 GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby JamesRit » Mon May 22, 2017 4:09 pm

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.

milesstone
Posts: 24
Joined: Mon Apr 26, 2021 4:50 pm

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby milesstone » Tue May 04, 2021 6:43 pm

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.

Nielson
Posts: 21
Joined: Wed Dec 09, 2020 4:15 pm

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby Nielson » Sat Jun 12, 2021 10:09 pm

milesstone wrote:
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.

I don't know the answer to this unfortunately, but I'm actually curious about the answer as well

I'm currently using an echo dot - and for that there are a few 3rd party solutions for building a locally hosted API to respond to commands - which is really nice

I'd like to possibly switch to a google home in the future, but I'm concerned it might be harder to integrate into my custom-built system

schroedermcken
Posts: 1
Joined: Wed Jun 23, 2021 10:31 am

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby schroedermcken » Wed Jun 23, 2021 12:34 pm

I was very surprised to hear this!
word unscrambler

Lianza
Posts: 1
Joined: Wed Jul 07, 2021 2:49 pm

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby Lianza » Wed Jul 07, 2021 4:08 pm

If you require any kind of academic help. Then call to professional assignment writers. They will hear all your and resolve all your issues in a short time.

RalphKeil
Posts: 1
Joined: Mon Jul 26, 2021 5:46 pm

Re: ESP8266 - GOOGLE CLOUD MESSAGING WITHOUT EXTERNAL SERVER

Postby RalphKeil » Mon Jul 26, 2021 5:50 pm

I'm looking for a method to send notifications with Google Cloud Messaging using javascript from my pc, so without a middle server. As pointed in the Developer's web site, the format of the request should be like this:

Code: Select all

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}


First I've tryed to use the ajax method:

Code: Select all

var textNotification={
    "notification": {
        "title": "Portugal vs. Denmark",
        "text": "5 to 1"
    }
};
    $.ajax(
    {
        url : "https://gcm-http.googleapis.com/gcm/send",
        type : "POST",
        headers :
        {
            'Authorization' : 'AIzaSyZ-1u...',
            'Content-type': 'application/json'
        },
        data : textNotification
    }
    ).done(function (data)
    {
        console.log(data);
    }
    );


As aspected, due to the fact I'm trying to send an HTTPS request from my PC, it is blocked. Is there another way to follow?

source : https://wasaelgroup.com

Who is online

Users browsing this forum: No registered users and 3 guests