Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 1 | # libweave daemon examples |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 2 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 3 | This directory contains examples implementation of `libweave` device daemons. |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 4 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 5 | ## Build |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 6 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 7 | - build all examples |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 8 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 9 | ``` |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 10 | make all-examples |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 11 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 12 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 13 | - build only the light daemon |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 14 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 15 | ``` |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 16 | make out/Debug/weave_daemon_light |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 17 | ``` |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 18 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 19 | ## Pre-requisites |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 20 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 21 | - enable user-service-publishing in avahi daemon |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 22 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 23 | set `disable-user-service-publishing=no` in `/etc/avahi/avahi-daemon.conf` |
| 24 | |
| 25 | - restart avahi daemon |
| 26 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 27 | ``` |
| 28 | sudo service avahi-daemon restart |
| 29 | ``` |
| 30 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 31 | ## Provisioning |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 32 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 33 | ### Generate registration tickets |
| 34 | - go to the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) |
| 35 | - `Step 1`: enter the Weave API scope `https://www.googleapis.com/auth/weave.app` and click to `Authorize APIs` |
| 36 | - `Step 2`: click `Exchange authorization code for tokens` |
| 37 | - `Step 3`: |
| 38 | - set `HTTP Method`: `POST` |
| 39 | - set `Request URI`: `https://www.googleapis.com/weave/v1/registrationTickets` |
| 40 | - click `Enter request body`: `{"userEmail": "me"}` |
| 41 | - click `Send the request` |
| 42 | - The `Response` contains a new `registrationTicket` resource. |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 43 | |
| 44 | ``` |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 45 | { |
| 46 | "userEmail": "user@google.com", |
| 47 | "kind": "weave#registrationTicket", |
| 48 | "expirationTimeMs": "1443204934855", |
| 49 | "deviceId": "0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d", |
| 50 | "creationTimeMs": "1443204694855", |
| 51 | "id": "93019287-6b26-04a0-22ee-d55ad23a4226" |
| 52 | } |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 53 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 54 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 55 | - Note: the ticket expires after a few minutes |
| 56 | |
| 57 | ### Provision the device |
| 58 | |
| 59 | - start the daemon with the `registrationTicket` id. |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 60 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 61 | ``` |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 62 | sudo out/Debug/weave_daemon_sample --registration_ticket=93019287-6b26-04a0-22ee-d55ad23a4226 |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 63 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 64 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 65 | - the daemon outputs the path to its configuration file and its deviceId |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 66 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 67 | ``` |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 68 | Saving settings to /var/lib/weave/weave_settings_XXXXX_config.json |
| 69 | Device registered: 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 70 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 71 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 72 | - the device id matches the `cloud_id` in the configuration |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 73 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 74 | ``` |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 75 | $ sudo grep "cloud_id" /var/lib/weave/weave_settings_[XXXXX]_config.json |
| 76 | "cloud_id": 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 77 | ``` |
| 78 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 79 | - verify that that the device is online in the |
| 80 | [Weave Developers Console](https://weave.google.com/console/), |
| 81 | the [Weave Android app](https://play.google.com/apps/testing/com.google.android.apps.weave.management) |
| 82 | or |
| 83 | the [Weave Chrome app](https://chrome.google.com/webstore/detail/weave-device-manager/pcdgflbjckpjmlofgopidgdfonmnodfm). |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 84 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 85 | ### Send Commands |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 86 | |
Johan Euphrosine | 5fe0ac0 | 2016-03-18 23:58:17 -0700 | [diff] [blame] | 87 | - go to the [Weave Developers Console](https://weave.google.com/console/), |
| 88 | - click `Your devices` |
| 89 | - select your device to show the `Device details` page. |
| 90 | - in the `Available commands` click `_sample.hello` |
| 91 | - set command parameters |
| 92 | - click `RUN COMMAND` |
| 93 | - verify the command is handled correctly by looking at the daemon logs. |