1
1
# Local Home SDK Sample
2
2
3
- This sample shows how to integrate with the
3
+ This sample demonstrates integrating a smart home Action with the
4
4
[ 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
6
6
intents by running TypeScript (or JavaScript) directly on Google Home smart speakers
7
7
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
12
12
13
13
## Prerequisites
14
14
15
15
- [ Node.js] ( https://nodejs.org/ ) LTS 10.16.0+
16
+ - [ Firebase CLI] ( https://firebase.google.com/docs/cli )
16
17
17
- ## Configure the smart home project
18
+ ## Configure the Actions project
18
19
19
20
- Create a new _ Smart Home_ project in the [ Actions console] ( https://console.actions.google.com/ )
20
21
- 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**,
34
35
- ** Authorization URL** : ` https://${REGION}-${PROJECT_ID}.cloudfunctions.net/authorize `
35
36
- ** Token URL** : ` https://${REGION}-${PROJECT_ID}.cloudfunctions.net/token `
36
37
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
54
39
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
56
64
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.
63
79
64
- ### Start as a single end device
80
+ ## Set up cloud fulfillment
65
81
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:
68
86
```
69
87
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
71
90
npm run deploy --prefix functions/
72
91
```
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 :
76
95
```
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/
85
100
```
86
101
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_ .
88
105
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.
93
112
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.
95
124
96
- ### Start as a hub device
125
+ > Note: The virtual device needs to listen on the same local network as the Home device.
97
126
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:
100
131
```
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
104
138
```
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 :
108
142
```
109
143
npm install --prefix device/
110
144
npm start --prefix device/ -- \
111
145
--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 \
116
148
--channel 1 \
117
149
--channel 2 \
118
150
--channel 3
119
151
```
120
152
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:
145
155
```
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
172
164
```
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.
185
168
186
169
## Deploy the local execution app
187
170
@@ -195,10 +178,11 @@ or deploy it to a publicly reacheable URL endpoint.
195
178
npm install --prefix app/
196
179
npm start --prefix app/ -- --host 0.0.0.0
197
180
```
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
+
200
184
- 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
202
186
` http://local-dev-server-hostname-or-ip:8080/ `
203
187
204
188
### Deploy to Firebase Hosting
@@ -210,7 +194,7 @@ npm run deploy --prefix app/ -- --project ${FIREBASE_PROJECT_ID}
210
194
```
211
195
212
196
- 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
214
198
` http://${FIREBASE_PROJECT_ID}.firebaseapp.com/ `
215
199
216
200
## Test the local execution app
0 commit comments