GCM/DscClient

NOTE: GCM is being deprecated by Google before 4/11/2019. Use the secure DscKeypad or Drive remote access type rather than GCM.

This section describes how to use the DscServer with the DscClient over Google Cloud Messaging (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 the DscServer 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 the DscServer to connect to your phone using a google cloud service instance that you own and control yourself. No danger of outside access.

Using GCM eliminates the need to configure your router and to use a DDNS service when using the DscClient. Your phone and the DscServer will find each other using your GCM service project number.

GCM is bi-directional, meaning the DscServer can update your phone the DSC status and alarms, and allow you to access your service 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 DSC connection indicator and the GCM indicator on the server widget is green. If it's yellow or gray the server is not connected to the DSC or the GCM service.

You should find the error in the server logs.

For the DSC panel use the troubleshooting instructions on the HowTo page.

For GCM its typically 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 do 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 DscServer under preferences (when you do, use the link to open the console on your phone's browser to copy/paste it to avoid typos).
  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"
    4. Click on "Enable API" at the top.
  6. Create a credential for use in the DscServer.
    1. Click on "Credentials" on the left hand side menu.
    2. Click on the "New Credentials" drop down and choose API Key in the "Create a new key" window.
    3. 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 (in which case specify that IP).
  7. You'll need both the GCM Project # and the API key to configure your server for GCM,
  8. and you'll need the GCM Project # to configure your client.
  9. If you're using the DscServer for android, add the DscServer widget. 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.
  10. 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.
    1. The DscServer widget will look something like this when GCM is enabled and running properly.
      1. For the GCM indicator:
        1. RED means google can't be contacted or your project number is incorrect.
        2. YELLOW means the DscServer can't authenticate with GCM. Double check your authentication key.
        3. GREEN means your good to continue.

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

How do I connect to the DscServer using the DscClient?

  1. The GCM indicator must be green on your server before continuing here or nothing will connect.
  2. On your PHONE start up the DscClient app (it's like the keypad but allows multiple servers to be defined).
  3. Use the menu to "add server" with your GCM Project number.
  4. Register with your DscServer. Accept the client registration request on the server system.
  5. Once it connects you can add a DscClient widget to your home screen for a connection that stays active all of the time.

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.

On the DscServer java version the message at the bottom for the GCMServer will say “authenticated” or “reconnected”.

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 allow IP range 0.0.0.0/24 until you’ve got it running. You can change it later if you know your server IP/range 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.