Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 1 | # Overview |
| 2 | |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 3 | The wrapper implements OS dependent services for libweave |
| 4 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 5 | # Building |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 6 | |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 7 | ### Build daemon examples |
| 8 | |
| 9 | The example binaries land in the out/Debug/ directory build all of them at once: |
| 10 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 11 | ``` |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 12 | make all-examples |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 13 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 14 | |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 15 | ...or one at a time. |
| 16 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 17 | ``` |
Jacob Marble | e785ec9 | 2016-01-13 13:49:44 -0800 | [diff] [blame] | 18 | make out/Debug/weave_daemon_light |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 19 | ``` |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 20 | |
| 21 | # Prepare Host OS |
| 22 | |
| 23 | ### Enable user-service-publishing in avahi daemon |
| 24 | Set disable-user-service-publishing=no in /etc/avahi/avahi-daemon.conf |
| 25 | |
| 26 | #### restart avahi |
| 27 | ``` |
| 28 | sudo service avahi-daemon restart |
| 29 | ``` |
| 30 | |
| 31 | # Control device with the cloud |
| 32 | |
| 33 | ### Generate registration ticket |
| 34 | - Go to [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) |
| 35 | - "Step 1": Paste https://www.googleapis.com/auth/clouddevices and click to "Authorize APIs" |
| 36 | - "Step 2": Click "Exchange authorization code for tokens" |
| 37 | - "Step 3": Fill the form: |
| 38 | * HTTP Method: POST |
| 39 | * Request URI: https://www.googleapis.com/weave/v1/registrationTickets |
| 40 | * Enter request body: ```{"userEmail": "me"}``` |
| 41 | * Click "Send the request", a ticket id will be returned in |
| 42 | |
| 43 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 44 | { |
| 45 | "userEmail": "user@google.com", |
Vitaly Buka | 9f78ca3 | 2015-11-17 17:04:01 -0800 | [diff] [blame] | 46 | "kind": "weave#registrationTicket", |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 47 | "expirationTimeMs": "1443204934855", |
| 48 | "deviceId": "0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d", |
| 49 | "creationTimeMs": "1443204694855", |
| 50 | "id": "93019287-6b26-04a0-22ee-d55ad23a4226" |
| 51 | } |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 52 | ``` |
| 53 | - Note: the ticket "id" is not used within 240 sec, it will be expired. |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 54 | |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 55 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 56 | ### Register device to cloud |
| 57 | |
| 58 | - Copy the ticket "id" generated above: ```93019287-6b26-04a0-22ee-d55ad23a4226``` |
| 59 | - Go to terminal, register and start the daemon with |
| 60 | |
| 61 | ``` |
Paul Westbrook | e61717c | 2015-11-13 00:27:21 -0800 | [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 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 65 | - See something like: |
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 | ``` |
| 68 | Publishing service |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 69 | Saving settings to /var/lib/weave/weave_settings_[XXXXX]_config.json |
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 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 72 | - Note: in second and future runs, --registration_ticket options is not necessary anymore |
| 73 | - Get your device id with |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 74 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 75 | ``` |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 76 | sudo grep "cloud_id" /var/lib/weave/weave_settings_[XXXXX]_config.json |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 77 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 78 | |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 79 | - See a field called cloud_id like: |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 80 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 81 | ``` |
| 82 | ... |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 83 | "cloud_id": 0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 84 | ... |
| 85 | ``` |
| 86 | |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 87 | - Use this cloud_id for future communication with your device as its deviceId. |
| 88 | It does not expire. |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 89 | - Verify device is up with Weave Device Managers on |
| 90 | [Android](https://play.google.com/apps/testing/com.google.android.apps.weave.management), |
| 91 | [Chrome](https://chrome.google.com/webstore/detail/weave-device-manager/pcdgflbjckpjmlofgopidgdfonmnodfm) |
Shawn S | 86e8f63 | 2016-03-02 17:57:14 -0800 | [diff] [blame] | 92 | or [Weave Developpers Console](https://weave.google.com/console/), where you |
| 93 | see this id listed right below the device name in device details section. |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 94 | |
| 95 | ### Send Command to the Daemon |
| 96 | |
| 97 | - Go to [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) |
| 98 | - "Step 1": Paste https://www.googleapis.com/auth/clouddevices and click to "Authorize APIs" |
| 99 | - "Step 2": Click "Exchange authorization code for tokens" |
| 100 | - "Step 3": Fill the form: |
| 101 | * HTTP Method: POST |
| 102 | * Request URI: https://www.googleapis.com/weave/v1/commands |
| 103 | * Enter request body: |
| 104 | |
| 105 | ``` |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 106 | { |
| 107 | "deviceId": "0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d", |
Vitaly Buka | e6b17ed | 2016-01-04 12:43:53 -0800 | [diff] [blame] | 108 | "name": "_sample.hello", |
| 109 | "component": "sample", |
| 110 | "parameters": { "name": "cloud user" } |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 111 | } |
ggfan | d992142 | 2015-09-25 13:34:09 -0700 | [diff] [blame] | 112 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 113 | ``` |
Vitaly Buka | e6b17ed | 2016-01-04 12:43:53 -0800 | [diff] [blame] | 114 | |
Vitaly Buka | b0ee670 | 2016-01-12 12:08:42 -0800 | [diff] [blame] | 115 | - "Send the request", you command will be "queued" as its "state" |
| 116 | - Verify the command execution observing daemon console logs |
| 117 | - Verify the command usign [Weave Developpers Console](https://weave.google.com/console/) |
| 118 | - Verify the command history with [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) |
| 119 | - "Step 1": Paste https://www.googleapis.com/auth/clouddevices and click to "Authorize APIs" |
| 120 | - "Step 2": Click "Exchange authorization code for tokens" |
| 121 | - "Step 3": Fill the form: |
| 122 | * HTTP Method: GET |
| 123 | * Request URI: https://www.googleapis.com/weave/v1/commands?deviceId=0f8a5ff5-1ef0-ec39-f9d8-66d1caeb9e3d |
| 124 | * Click "Send the request", you get all of the commands executed on your device. |