aboutsummaryrefslogtreecommitdiff
path: root/examples/daemon/README.md
blob: b6a7664126ad64dfa2fedd643d4d63ef09352d8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# libweave daemon examples

This directory contains examples implementation of `libweave` device daemons.

## Build

- build all examples

```
make all-examples
```

- build only the light daemon

```
make out/Debug/weave_daemon_light
```

## Pre-requisites

- enable user-service-publishing in avahi daemon

set `disable-user-service-publishing=no` in `/etc/avahi/avahi-daemon.conf`

- restart avahi daemon

```
sudo service avahi-daemon restart
```

## Provisioning

### Generate registration tickets
- go to the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/)
  - `Step 1`: enter the Weave API scope `https://www.googleapis.com/auth/weave.app` and click to `Authorize APIs`
  - `Step 2`: click `Exchange authorization code for tokens`
  - `Step 3`:
    - set `HTTP Method`: `POST`
    - set `Request URI`: `https://www.googleapis.com/weave/v1/registrationTickets`
    - click `Enter request body`: `{"userEmail": "me"}`
    - click `Send the request`
  - The `Response` contains a new `registrationTicket` resource.

```
{
  "userEmail": "user@google.com",
  "kind": "weave#registrationTicket",
  "expirationTimeMs": "1443204934855",
  "deviceId": "0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d",
  "creationTimeMs": "1443204694855",
   "id": "93019287-6b26-04a0-22ee-d55ad23a4226"
}
```

- Note: the ticket expires after a few minutes

### Provision the device

- start the daemon with the `registrationTicket` id.

```
sudo out/Debug/weave_daemon_sample --registration_ticket=93019287-6b26-04a0-22ee-d55ad23a4226
```

- the daemon outputs the path to its configuration file and its deviceId

```
Saving settings to /var/lib/weave/weave_settings_XXXXX_config.json
Device registered: 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d
```

- the device id matches the `cloud_id` in the configuration

```
$ sudo grep "cloud_id" /var/lib/weave/weave_settings_[XXXXX]_config.json
  "cloud_id": 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d
```

- verify that that the device is online in the
  [Weave Developers Console](https://weave.google.com/console/),
  the [Weave Android app](https://play.google.com/apps/testing/com.google.android.apps.weave.management)
  or
  the [Weave Chrome app](https://chrome.google.com/webstore/detail/weave-device-manager/pcdgflbjckpjmlofgopidgdfonmnodfm).

### Send Commands

- go to the [Weave Developers Console](https://weave.google.com/console/),
- click `Your devices`
- select your device to show the `Device details` page.
- in the `Available commands` click `_sample.hello`
- set command parameters
- click `RUN COMMAND`
- verify the command is handled correctly by looking at the daemon logs.