GCM

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:

  1. Open this link and sign in with your google email account: https://console.developers.google.com/project
    1. You do NOT need to sign up for the free trial account, the GCM service already included at no charge.
  2. Click on "Create Project" (blue button upper left). Give it a memorable name. The ID doesn't matter.
  3. When it completes, note the Project Number (from beside the ID).
  4. You'll configure that in AutomationManager under preferences, AutomationServer (when you do, use the link to open the console on your phone's browser to copy/paste it).
  5. Enable the Google Cloud Messaging API:
    1. Click on "Enable and manage APIs" in the "Use Google APIs" panel.
    2. Type "Google Cloud Messaging" in the search bar.
    3. Click on "Google Cloud Messaging for Android"
    4. Click on "Enable API" at the top.
    5. Create a credential for use in the AutomationServer.
    6. Click on "Credentials" on the left hand side menu.
    7. Click on the "New Credentials" drop down and choose API Key.
    8. You must add a key restriction: choose "IP Addresses" and authorize to 0.0.0.0/24 unless you know your routers external IP and it won't change.
    9. You'll need both the GCM Project # and the API key to configure your server for GCM,
    10. and you'll need the GCM Project # to configure your client.
  6. If you're using the AutomationServer on an android device, go to the next step.
    1. If you're using the JAVA AutomationServer on PC, copy/paste the GCM project number and the key into the appropriate section of the AutomationServer "Configure>GCM" menu, and continue on with AutomationRemote setup below.
  7. If you're using the AutomationServer for android, find and add the AutomationServer widget (not the app shortcut!) to one of your home screens. On older android systems you find widgets by long touching an empty part of your home screen, and picking it from the list. On new android systems you open the "all apps" view and you'll find a folder at the top to select widgets - scroll to find the right one - they're in alphabetical order.
    1. Touch the server widget to open the configuration, and the menu to get to the server settings. Copy/paste the GCM project number and the key into the appropriate section of the preferences. If it's all correct the AutomationServer widget should be on one of your home screens and the GCM indicator should be green, like this:

For reference or more information: http://developer.android.com/google/gcm/gs.html

Great, now how do I get to it from AutomationRemote?

  1. There's no point continuing here until you have the correct widget above running and showing green in the GCM indicator - if not there's nothing for your phone to talk to.
  2. On your PHONE open AutomationRemote and add a GCM Server using that same GCM Project Number. You can customize the server and client names but be sure to use different names for each client.
  3. Register the AutomationRemote with the AutomationServer (the "register" menu item) as with any AutomationRemote client. Check the AutomationServer system for the incoming registration request and accept it. If the request did not show up on the AutomationServer confirm the project number and ensure registrations have been allowed in the preferences/configuration. You can control or remove client access from the AutomationManager/AutomationServer preferences menu.

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.