DE

EgiGeoZone

EgiGeoZone Forum

Download

 

EgiGeoZone and GCM

General

EgiGeoZone can now receive GCM (Google Cloud Messaging) messages .

Google Cloud Messaging for Android (GCM) is a free service that allows you to send data from a server to your Android-powered device, and also to receive messages from devices on the same connection. Mostly these are simple short messages, which indicate for example the status of equipment.
This type of notifications are also called push messages.

Below is the configuration using the FHEM servers and describes the gcmsend module.
 

Register GCM with Google

To use GCM, you need to subscribe to the service from Google.
Go to https://console.developers.google.com/project and register there.

If this is the first time you have used Google Developer Console, you need to create a new project. For this, click on "Create Project".

In the next step you will be prompted for a project name. Here you can enter any name. For example EgiGeoZone.

Then, a Project ID is assigned and you accept "Terms of Service" and create the project by clicking on "Create".



Projekt number

After the project is created, you can see at top centre a Project Number. This project number is required later when configuring GCM in the app. So please make a note of it. You can see the number when visiting this page again later.

Example: Project Number: 1234567890

 

Enable interface GCM for Android: APIs & auth

Find the menu item APIs and then select auth APIs. Here you can see a couple of unlocked APIs. In addition, we need Google Cloud Messaging for Android. For this click on the button OFF to activate the API. Accept the Terms of Use and the interface then moves to the beginning of the list.



API Key: Generate server key

Under the menu item Credentials, select 'Create new key'. Then click on 'Server key'.

Then click on Create. "Accept requests from these server IP addresses " can be left blank.

On the next page, the API KEY now appears. We need this key for later configuration on the server.



This key can be regenerated if necessary, or deleted.

Configuration of the app EgiGeoZone for GCM

Unter Verwaltung kann man nun die vorhin erhaltene GCM-Projekt-Number angeben.

Then activate GCM receive messages. The registration with the GCM service is now running in the background. This requires an active Internet connection. After a few seconds a dialogue box appears and displays the generated API Client Key. This should be immediately copied for further use in the clipboard. This key is needed later in the server configuration.




Server configuration (FHEM)

This is where you can configure the gcmsend module from FHEM. Other servers can be configured in a similar way.

Copy the gcmsend module 98_gcmsend.pm  from the contrib directory of FHEM and give them proper rights to do so. The FHEM-user under which the server runs, must be able to read the script.


The following modules have also to be installed.

LWP :: Protocol :: https (download here )
Mozilla :: CA (download here )

Now create FHEM in a GCM device:
define <gcm_device_name> gcmsend

For FHEM to talk to GCM, the server needs the API Key, which we received when acreating the GCM project, so you need to enter:

attr <gcm_device_name> apikey <apikey>

And finally, you still need the API Client Key, which was generated for the EgiGeoZone app, specifically. Thus FHEM now know to whom the messages should be sent. Here you can also add more client keys separated by "|" symbol.
Note: andFHEM sends these key themselves to the configuration. We will need to enter them manually here, because EgiGeoZone performs no changes to FHEM!

attr <gcm_device_name> regIds <apiClientKeys>

The remaining optional attributes are:

gcmsend_stateFilter
    Sends a GCM message only if the attribute of the RegExp filter corresponds.

gcmsend_vibrate
    Indicates whether the receiving device (smartphone) should vibrate or not. Values: true or false
    Example: attr <gcm_device_name> vibrate true

gcmsend_deviceFilter
    Sends a GCM message only when the RegExp of the filter corresponds.

gcmsend_playSound
        Indicates whether the receiving device (smartphone) should play an notification sound or not. Values: true or false:
        Example: attr <gcm_device_name> playSound true

See also:
http://andfhem.klass.li/installation.html#gcm
http://forum.fhem.de/index.php/topic,14064.0.html

The gcmsend module has two main methods.

One method automatically sends status modifications via push according to the filter settings on the devices.
Notifications can be sent to the unit via the second method.

Example:
define dummy_standby_notify notify tv:standby set gcm send StandbyMessage|Television|Television is in standby

To test: you can enter the following command in FHEM :
set gcm send Attention|Unicorn alarm|The unicorn is eating your popcorn again!

EgiGeoZone shows the device name and its changes.

Example:


 

Other servers

Messages from other servers are displayed without formatting.