blob: b6a7664126ad64dfa2fedd643d4d63ef09352d8f [file] [log] [blame] [view]
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -07001# libweave daemon examples
Vitaly Bukab0ee6702016-01-12 12:08:42 -08002
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -07003This directory contains examples implementation of `libweave` device daemons.
ggfand9921422015-09-25 13:34:09 -07004
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -07005## Build
ggfand9921422015-09-25 13:34:09 -07006
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -07007- build all examples
Jacob Marblee785ec92016-01-13 13:49:44 -08008
Vitaly Bukab0ee6702016-01-12 12:08:42 -08009```
Jacob Marblee785ec92016-01-13 13:49:44 -080010make all-examples
Vitaly Bukab0ee6702016-01-12 12:08:42 -080011```
ggfand9921422015-09-25 13:34:09 -070012
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070013- build only the light daemon
Jacob Marblee785ec92016-01-13 13:49:44 -080014
Vitaly Bukab0ee6702016-01-12 12:08:42 -080015```
Jacob Marblee785ec92016-01-13 13:49:44 -080016make out/Debug/weave_daemon_light
Vitaly Bukab0ee6702016-01-12 12:08:42 -080017```
Vitaly Bukab0ee6702016-01-12 12:08:42 -080018
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070019## Pre-requisites
Vitaly Bukab0ee6702016-01-12 12:08:42 -080020
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070021- enable user-service-publishing in avahi daemon
Vitaly Bukab0ee6702016-01-12 12:08:42 -080022
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070023set `disable-user-service-publishing=no` in `/etc/avahi/avahi-daemon.conf`
24
25- restart avahi daemon
26
Vitaly Bukab0ee6702016-01-12 12:08:42 -080027```
28sudo service avahi-daemon restart
29```
30
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070031## Provisioning
Vitaly Bukab0ee6702016-01-12 12:08:42 -080032
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070033### 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 Bukab0ee6702016-01-12 12:08:42 -080043
44```
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070045{
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 Bukab0ee6702016-01-12 12:08:42 -080053```
ggfand9921422015-09-25 13:34:09 -070054
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070055- Note: the ticket expires after a few minutes
56
57### Provision the device
58
59- start the daemon with the `registrationTicket` id.
ggfand9921422015-09-25 13:34:09 -070060
Vitaly Bukab0ee6702016-01-12 12:08:42 -080061```
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070062sudo out/Debug/weave_daemon_sample --registration_ticket=93019287-6b26-04a0-22ee-d55ad23a4226
Vitaly Bukab0ee6702016-01-12 12:08:42 -080063```
ggfand9921422015-09-25 13:34:09 -070064
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070065- the daemon outputs the path to its configuration file and its deviceId
ggfand9921422015-09-25 13:34:09 -070066
Vitaly Bukab0ee6702016-01-12 12:08:42 -080067```
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070068Saving settings to /var/lib/weave/weave_settings_XXXXX_config.json
69Device registered: 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d
Vitaly Bukab0ee6702016-01-12 12:08:42 -080070```
ggfand9921422015-09-25 13:34:09 -070071
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070072- the device id matches the `cloud_id` in the configuration
ggfand9921422015-09-25 13:34:09 -070073
Vitaly Bukab0ee6702016-01-12 12:08:42 -080074```
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070075$ sudo grep "cloud_id" /var/lib/weave/weave_settings_[XXXXX]_config.json
76 "cloud_id": 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d
Vitaly Bukab0ee6702016-01-12 12:08:42 -080077```
78
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070079- 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 Bukab0ee6702016-01-12 12:08:42 -080084
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070085### Send Commands
Vitaly Bukab0ee6702016-01-12 12:08:42 -080086
Johan Euphrosine5fe0ac02016-03-18 23:58:17 -070087- 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.