NOTE: GCM is being deprecated by Google before 4/11/2019. Use the HTTP or Drive remote access type rather than GCM.
This section describes how to use the AutomationManager/AutomationServer with AutomationRemote over GCM.
What is GCM and why would I want it?
Google Cloud Messaging (or GCM) is a service google provides to allow servers to connect with client android devices. Normally this would be for application developers to connect with their apps running on your phone - send ads, alerts, (hack them!) etc.
If you're using AutomationServer you're already running your own server. You can sign up to GCM for free (you don't need to sign up for the free trial they offer, that's for servers hosted on the google cloud) and enable AutomationServer to connect to your phone using a google cloud service that you, and you alone, control.
Using GCM eliminates the need to configure your router and to use a DDNS service when using AutomationRemote. Your phone and the AutomationServer will always find each other using your GCM service project number.
GCM is bi-directional, meaning AutomationServer can update your phone with current device as well as allowing you to access your devices remotely.
Can I share GCM services with multiple servers?
No, only one server can use a GCM project at one time. They're free, so set up one per server you want to enable.
I'm having problems getting the client to connect, what should I do?
First, confirm that the GCM indicator on the server widget is green. If it's yellow or gray the server is not connected to the GCM service. You should find the error in the server logs, typically it's an authorization problem so double check that you've got the correct GCM project number and authorization code (try to use copy/paste rather than typing). Once that's sorted move onto the next steps below.
My GCM client seems to take a while to connect and frequently times out. What gives?
It seems that it may take Google a while to propagate your GCM project throughout it's cloud. if you're sure the server side is properly connected to GCM, double check the project number on your client. Keep trying to connect for a day or two once you get your client registered to see if the connection settles down. You may see some instability when you travel to new locations, but eventually you should find it reasonably fast and very reliable.
What happens when my GCM client loses it's connection?
If the connection is dropped the clients will keep trying to reconnect. When they get through they'll request the latest status from the server to catch up. Alarms and other important asynchronous events are sent to GCM directly by the server without waiting for or needing the clients to connect (if the client is registered and has connected at least once). The events will be delivered as soon as Google sees each client back online. If a client is unregistered it will be dropped from the server's asynchronous notification list.
Ok, how to I set it up?
You first create a Project using your Google account:
For reference or more information: http://developer.android.com/google/gcm/gs.html
Great, now how do I get to it from AutomationRemote?
I did all that and now I'm seeing "GCM Connect to <my project number (or not)> failed SASLError using PLAIN: not-authorized" on the server.
This is usually an authentication failure - double check that your GCM project number, server authorization code, and the allowed IP ranges are all correct. If you can login to the GCM developer console from your server device or email there it's easiest to copy/paste rather than trying to type them... I usually leave the IP range (in the developers console) blank unless I'm certain my external (routers) IP address won't change.
What does "GCM ack'd" mean?
It means that Google accepted the message from the client by acknowledging it. GCM will try to deliver it to the server, but the ack does not confirm delivery. if the message is not ack'd it means that the device is not properly connected to GCM - probably a communication issue.
I'm trying to register the client but there are a lot of retries and it doesn't seem to be working.
First confirm that the Server is properly connected to GCM.
On the android version, the indicator beside the GCM project should be green.
In the AutomationServer, use the "reconnect" server button and check the log for a GCM successful authentication.
If it didn't authenticate, double check the project numbers and the authorization key. The authorization key type has to be “Server”, and it’s usually best to leave the IP blank until you’ve got it running. You can change it if you know your IP will never change.
Once the server is connected to GCM, double check the project number used in the Client.
If you're sure everything is correct give it a try again every few hours, sometimes it takes a while before the project is properly running through google. Eventually it will succeed.