Skip to content

Commit eccd236

Browse files
author
Dave Smith
committed
Update README and license headers
Bug: 152413683 Signed-off-by: Dave Smith <[email protected]> Change-Id: Ia3bde9744f4984ae65cacd8f4db414931f7e982d
1 parent 67f0494 commit eccd236

File tree

12 files changed

+176
-160
lines changed

12 files changed

+176
-160
lines changed

README.md

Lines changed: 115 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# Local Home SDK Sample
22

3-
This sample shows how to integrate with the
3+
This sample demonstrates integrating a smart home Action with the
44
[Local Home SDK](https://developers.google.com/assistant/smarthome/concepts/local).
5-
The Local Home SDK allow developers to add a local path to execute smart home
5+
The Local Home SDK allow developers to add a local path to handle smart home
66
intents by running TypeScript (or JavaScript) directly on Google Home smart speakers
77
and Nest smart displays.
8-
The sample could be configured to use one of the following protocols for virtual
9-
device discovery: **UDP**, **MDNS** or **UPNP**. To control a discovered virtual
10-
device for a local execution, sample could be configured to use one of **TCP**,
11-
**HTTP** or **UDP** protocols.
8+
The sample supports the following protocols along with the companion
9+
[virtual device](device/README.md):
10+
- **Device Discovery:** UDP, mDNS or UPnP
11+
- **Control:** UDP, TCP, or HTTP
1212

1313
## Prerequisites
1414

1515
- [Node.js](https://nodejs.org/) LTS 10.16.0+
16+
- [Firebase CLI](https://firebase.google.com/docs/cli)
1617

17-
## Configure the smart home project
18+
## Configure the Actions project
1819

1920
- Create a new _Smart Home_ project in the [Actions console](https://console.actions.google.com/)
2021
- Deploy the placeholder smart home provider to _Cloud Functions for Firebase_
@@ -34,154 +35,136 @@ device for a local execution, sample could be configured to use one of **TCP**,
3435
- **Authorization URL**: `https://${REGION}-${PROJECT_ID}.cloudfunctions.net/authorize`
3536
- **Token URL**: `https://${REGION}-${PROJECT_ID}.cloudfunctions.net/token`
3637

37-
### Configure a discovery protocol
38-
39-
- Discovery protocol and its attributes are configured in _Build > Actions > Smart home > Actions_
40-
in the `Device Scan Configuration`.
41-
- To configure **UDP** as a discovery protocol, set only the following attributes
42-
in the `Device Scan Configuration` and remove other attributes if set:
43-
- **UDP discovery address**: `255.255.255.255`
44-
- **UDP discovery port in**: `3312`
45-
- **UDP discovery port out**: `3311`
46-
- **UDP discovery packet**: `A5A5A5A5`
47-
- To configure **MDNS** as a discovery protocol, set only the following attributes
48-
in the `Device Scan Configuration` and remove other attributes if set:
49-
- **MDNS service name**: `_sample._tcp.local`
50-
- **Name**: `.*\._sample\._tcp\.local`
51-
- To configure **UPNP** as a discovery protocol, set only the following attribute
52-
in the `Device Scan Configuration` and remove other attributes if set:
53-
- **UPNP service type**: `urn:sample:service:light:1`
38+
### Select a discovery protocol
5439

55-
## Set up the virtual device
40+
Choose one of the supported the discovery protocols that you would like to test,
41+
and enter its attributes in the Actions console at
42+
_Develop > Actions > Configure local home SDK_ under **Device Scan Configuration**.
43+
44+
> Note: These are the default values used by the [virtual device](device/README.md)
45+
> for discovery. If you choose to use different values, you will need to supply
46+
> those parameters when you [set up the virtual device](#set-up-the-virtual-device).
47+
48+
#### UDP
49+
- **UDP discovery address**: `255.255.255.255`
50+
- **UDP discovery port in**: `3312`
51+
- **UDP discovery port out**: `3311`
52+
- **UDP discovery packet**: `A5A5A5A5`
53+
54+
#### mDNS
55+
- **mDNS service name**: `_sample._tcp.local`
56+
- **Name**: `.*\._sample\._tcp\.local`
57+
58+
> Note: The **Name** attribute value is a regular expression.
59+
60+
#### UPnP
61+
- **UPNP service type**: `urn:sample:service:light:1`
62+
63+
### Select a control protocol
5664

57-
- Virtual device discovery settings should match settings in
58-
`Device Scan Configuration` in _Build > Actions > Smart home > Actions_
59-
- Virtual device should use the same discovery protocol as in
60-
`Device Scan Configuration`
61-
- Virtual device control protocol should match control_protocol used for
62-
`functions:config:set` in `npm run firebase` command.
65+
Choose one of the supported control protocols that you would like to test.
66+
You will use this value to configure both the cloud fulfillment and the virtual
67+
device.
68+
69+
- `UDP`: Send execution commands to the target device as a UDP payload.
70+
- `TCP`: Send execution commands to the target device as a TCP payload.
71+
- `HTTP`: Send execution commands to the target device as an HTTP request.
72+
73+
### Choose a device type
74+
75+
The local fulfillment sample supports running as a **single end device** or a
76+
**hub/proxy device**. This is determined by the number of channels you configure.
77+
A device with more than one channel will be treated as a hub by the local
78+
fulfillment sample code.
6379

64-
### Start as a single end device
80+
## Set up cloud fulfillment
6581

66-
- Configure the cloud service to report a single device (`strand1`) in the
67-
`SYNC` response:
82+
Configure the cloud service to report the correct device `SYNC` metadata based on your
83+
chosen device type and control protocol. Here are some examples for configuring the service for different use cases:
84+
85+
- Report a single device (`strand1`) controlled via UDP commands:
6886
```
6987
npm run firebase --prefix functions/ -- functions:config:set \
70-
strand1.leds=16 strand1.channel=1 strand1.control_protocol=UDP
88+
strand1.leds=16 strand1.channel=1 \
89+
strand1.control_protocol=UDP
7190
npm run deploy --prefix functions/
7291
```
73-
- Trigger a `SYNC` request by unlinking and re-adding the placeholder smarthome
74-
provider in the _Google Home app_.
75-
- Start the virtual light strip with a single strand of 16 pixels:
92+
93+
- Report three individual light strands connected through a proxy (`hub1`) and
94+
controlled via TCP commands:
7695
```
77-
npm install --prefix device/
78-
npm start --prefix device/ -- \
79-
--device_id strand1 \
80-
--discovery_protocol UDP \
81-
--udp_discovery_port 3311 \
82-
--udp_discovery_packet A5A5A5A5 \
83-
--control_protocol TCP \
84-
--channel 1
96+
npm run firebase --prefix functions/ -- functions:config:set \
97+
hub1.leds=16 hub1.channel=1,2,3 \
98+
hub1.control_protocol=TCP
99+
npm run deploy --prefix functions/
85100
```
86101

87-
This starts a local device server that:
102+
After you have deployed the cloud configuration, trigger a new `SYNC` request from
103+
Google Assistant by unlinking and re-adding the placeholder smart home provider in
104+
the _Google Home app_.
88105

89-
- replies to UDP discovery packets on port `3311` with device metadata
90-
- receives device controlling commands with TCP on port `7890`
91-
- handles OPC set 8-bit pixel packet on channel 0
92-
- displays OPC pixels to the terminal in a colorful way
106+
## Set up the virtual device
107+
108+
The companion [virtual device](device/README.md) is a Node.js app that emulates
109+
strands of RGB LEDs controllable using the
110+
[Open Pixel Control](http://openpixelcontrol.org/) protocol and displays the results
111+
to the terminal in a colorful way.
93112

94-
Note: The server needs to listen on the same local network as the Home device.
113+
- Virtual device discovery settings must match the attributes provided in
114+
**Device Scan Configuration** in _Develop > Actions > Configure local home SDK_.
115+
- If you modify the attributes in your **Device Scan Configuration**, you must
116+
configure the virtual device accordingly.
117+
See the [virtual device README](device/README.md) for more details on
118+
configuring the discovery attributes.
119+
- Virtual device control protocol should match `control_protocol` used with
120+
`functions:config:set` when setting up cloud fulfillment.
121+
- Configure the device type as **end device** or **hub/proxy** based on the number
122+
of `--channel` parameters provided. A device with more than one channel will be
123+
treated as a hub.
95124

96-
### Start as a hub device
125+
> Note: The virtual device needs to listen on the same local network as the Home device.
97126
98-
- Configure the cloud service to report 3 individual light strances connected
99-
through a proxy (`hub1`):
127+
Here are some examples for configuring the virtual device for different use cases:
128+
129+
- Start the virtual device as a single device (`strand1`) discovered via
130+
UDP broadcast and controlled with TCP commands:
100131
```
101-
npm run firebase --prefix functions/ -- functions:config:set \
102-
hub1.leds=16 hub1.channel=1,2,3 hub1.control_protocol=UDP
103-
npm run deploy --prefix functions/
132+
npm install --prefix device/
133+
npm start --prefix device/ -- \
134+
--device_id strand1 \
135+
--discovery_protocol UDP \
136+
--control_protocol TCP \
137+
--channel 1
104138
```
105-
- Trigger a `SYNC` request by unlinking and re-adding the placeholder smarthome
106-
provider in the _Google Home app_.
107-
- Start the virtual light hub with 3 individual strands:
139+
140+
- Start the virtual device as a hub (`hub1`) discovered via mDNS and controlling
141+
three individual strands with HTTP commands:
108142
```
109143
npm install --prefix device/
110144
npm start --prefix device/ -- \
111145
--device_id hub1 \
112-
--discovery_protocol UDP \
113-
--udp_discovery_port 3311 \
114-
--udp_discovery_packet A5A5A5A5 \
115-
--control_protocol TCP \
146+
--discovery_protocol MDNS \
147+
--control_protocol HTTP \
116148
--channel 1 \
117149
--channel 2 \
118150
--channel 3
119151
```
120152

121-
This starts a local device server that:
122-
123-
- replies to UDP discovery packets on port `3311` with proxy device metadata
124-
- receives device controlling commands with TCP on port `7890`
125-
- handles OPC set 8-bit pixel packet on channel 1 and 2 and 3
126-
- displays the 3 strands to the terminal in a colorful way
127-
128-
Note: The server needs to listen on the same local network as the Home device.
129-
130-
### View and adjust cloud service and virtual device configuration
131-
132-
Commands above use UDP discovery aand TCP control protocol. Other protocols
133-
are available. To select different discovery or control protocol, adjust
134-
configuration for the cloud service and change command line parameters for
135-
device.
136-
137-
- For cloud service, set control protocol in firebase configuration:
138-
- `strand1.control_protocol=UDP` for single device UDP control,
139-
- `strand1.control_protocol=TCP` for single device TCP control,
140-
- `strand1.control_protocol=HTTP` for single device HTTP control.
141-
- for hub, set `hub1.control_protocol` instead of `strand1.control_protocol`.
142-
- To view device configuration options and their default settings, use:
143-
```
144-
npm start --prefix device/ -- --help
153+
- Start the virtual device as a single device (`strand1`) discovered via
154+
UPnP with a custom advertisement and controlled with TCP commands:
145155
```
146-
- Set a discovery protocol and its options in `npm start --prefix device/`
147-
command. Use (and adjust if needed) the following options depending on discovery
148-
protocol settings in `Device Scan Configuration` in
149-
_Build > Actions > Smart home > Actions_:
150-
- For a single end device or a hub with UDP discovery:
151-
```
152-
--discovery_protocol UDP \
153-
--udp_discovery_port 3311 \
154-
--udp_discovery_packet A5A5A5A5 \
155-
```
156-
- For a single end device with MDNS discovery:
157-
```
158-
--discovery_protocol MDNS \
159-
--mdns_service_name _sample._tcp.local \
160-
--mdns_instance_name strand1._sample._tcp.local \
161-
```
162-
- For a hub with MDNS discovery:
163-
```
164-
--discovery_protocol MDNS \
165-
--mdns_service_name _sample._tcp.local \
166-
--mdns_instance_name hub1._sample._tcp.local \
167-
```
168-
- For a single end device or a hub with UPNP discovery:
169-
```
170-
--discovery_protocol UPNP \
171-
--upnp_service_type urn:sample:service:light:1 \
156+
npm install --prefix device/
157+
npm start --prefix device/ -- \
158+
--device_id strand1 \
159+
--discovery_protocol UPNP \
160+
--upnp_device_type urn:schemas-upnp-org:device:BinaryLight:1 \
161+
--upnp_service_type urn:schemas-upnp-org:service:SwitchPower:1 \
162+
--control_protocol TCP \
163+
--channel 1
172164
```
173-
- Set control protocol and control protocol port in `npm start --prefix device/`
174-
command.
175-
- Control protocol is one of `TCP`, `HTTP`, `UDP`. `
176-
- Use `--opc_port` option to change a control protocol port.
177-
- Examples:
178-
- Select UDP control and default control port `7890`:
179-
`--control_protocol UDP \`
180-
- Select HTTP with a custom control port value:
181-
```
182-
--control_protocol HTTP \
183-
--opc_port 7892 \
184-
```
165+
166+
> Note: See the [virtual device README](device/README.md) for more details on the
167+
> supported configuration options.
185168
186169
## Deploy the local execution app
187170

@@ -195,10 +178,11 @@ or deploy it to a publicly reacheable URL endpoint.
195178
npm install --prefix app/
196179
npm start --prefix app/ -- --host 0.0.0.0
197180
```
198-
Note: The local development server needs to listen on the same local network as
199-
the Home device in order to be able to load the Local Home SDK application.
181+
> Note: The local development server needs to listen on the same local network as
182+
> the Home device in order to be able to load the Local Home SDK application.
183+
200184
- Go to the smart home project in the [Actions console](https://console.actions.google.com/)
201-
- In _Test > On device testing_: set the development URL to
185+
- In _Develop > Actions > On device testing_ set the development URL to
202186
`http://local-dev-server-hostname-or-ip:8080/`
203187

204188
### Deploy to Firebase Hosting
@@ -210,7 +194,7 @@ npm run deploy --prefix app/ -- --project ${FIREBASE_PROJECT_ID}
210194
```
211195

212196
- Go to the smart home project in the [Actions console](https://console.actions.google.com/)
213-
- In _Test > On device testing_: set the development URL to
197+
- In _Develop > Actions > On device testing_ set the development URL to
214198
`http://${FIREBASE_PROJECT_ID}.firebaseapp.com/`
215199

216200
## Test the local execution app

app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Google, Inc.
2+
* Copyright 2019, Google LLC
33
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at

app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018, Google, Inc.
2+
* Copyright 2019, Google LLC
33
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at

app/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Google, Inc.
2+
* Copyright 2019, Google LLC
33
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at

app/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Google, Inc.
2+
* Copyright 2019, Google LLC
33
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at

app/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Google, Inc.
2+
* Copyright 2019, Google LLC
33
* Licensed under the Apache License, Version 2.0 (the 'License');
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at

common/discovery.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2020, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
export enum DiscoveryKind {
217
UDP = 'UDP',
318
UPNP = 'UPNP',

0 commit comments

Comments
 (0)