EMILY KELLER: In this video, I'll
introduce our Google Home sample app
for Matter, which showcases the Google Home Mobile
SDK, available from Google Play Services.
Hi there.
I'm Emily, part of the Nest Partner Engineering
team at Google.
At Google, we understand that mobile apps play a big role
in managing smart home devices.
If you'd like to build your own Android
apps to support Matter devices, we
can help you get started fast.
Our Mobile APIs for Matter can easily
be added to your Android studio projects,
allowing you to commission and share devices right
from your app.
You can also use our sample app as a learning tool
to better understand key Matter concepts, as well
as a tool to debug and troubleshoot interactions
with Matter devices.
To demonstrate the core features of our Google Home Mobile APIs,
we'll use an Android 12 device, along with an ESP32 development
board.
Our sample app only supports devices
that have the on/off server attribute, for example, lights,
smart plugs, and fans.
For this video, we'll use the All Clusters Example
from the Matter GitHub repository,
linked in the comments below.
I'll get started by opening the project in Android Studio.
While Gradle syncs, I'll make sure
that my ESP32 is plugged into a power source
and ready to start advertising.
Next, I'll go ahead and run the sample app on my Android phone.
Before you can control devices and allow them to communicate
with each other within the same fabric,
they need to be commissioned by a commissioner, which
in this case is our sample application.
To commission our ESP32, we'll need
to use the CommissioningClient API.
We can do this by tapping the Add Device button in our sample
app.
Now let's watch my teammate Pierre commission
a Matter device using the sample app on an Android phone.
First, he'll open up the sample app on his Android phone.
When he taps the Add button from the home screen,
control is transferred to Google Play Services.
When his app makes a call to the commissioning client API,
all of the commissioning work and associated screens
are handled by Google Play services and not the sample
app.
This functionality provides a consistent user experience
and removes the need to handle sensitive permissions
like Wi-Fi and thread credentials.
When the discovery process is complete,
he can enter a custom name for the device.
Now that commissioning is completed,
control is transferred back to our sample app.
During the commissioning process,
Pierre's ESP32 device was added to the Google fabric
using the commissionDevice API.
This means that he can now control it
through the Google Home app, Android power controls, voice,
and Nest touchscreen devices.
So how does the CommissioningClient API work?
Let's head back over to Android Studio and find out.
In our Commission to Google function,
first a commissioning request object is defined.
Matter is the entry point for the Google Home Mobile SDK.
In the next call, the getCommissioningClient function
gets a commissioning client by the fragment activity.
The commissionDevice method accepts
the CommissioningRequest request.
The success callback of the commissionDevice method
provides an IntentSender to launch
the commissionDevice activity in Google Play Services.
Here we use live data objects to report
the results of our API call.
That was the minimum code required to commission
a device to Google's fabric.
But what if you'd like to commission devices
to another fabric?
To manage and control devices directly within our sample app,
we'll need to create a local fabric
and obtain the operational credentials needed
to commission devices.
Let's see how that's done.
We can inform the Google Home Mobile SDK
that we'd like to commission devices to a local fabric
by passing a custom service to the commissioning request
object.
In this example, we pass AppCommissioningService.
With this modified flow, the CommissioningClient API
commissions devices to the Google fabric
first, then returns a callback to the service that we passed.
Let's take a look at the app commissioning service next.
To commission devices to a development fabric,
first we override the onCommissioningRequested
function, which returns a CommissioningRequestMetadata
object.
This metadata gives our sample app access
to the device information that Google Play Services
received when it connected to the ESP32 device.
In this example, we log the members,
including the device type, vendor ID,
and network information.
In addition to the Google Home Mobile SDK
from Google Play Services, our sample app
also includes commissioning and cluster libraries
from the Matter GitHub repository, Connected Home IP,
which again is linked below.
Remember, this local fabric will only exist on the instance
that it's created on.
If you install the sample app on a different Android device,
your Matter devices will need to be recommissioned.
Before we go on, it's important to remember
that local fabrics are for development only
and shouldn't be used in production.
Let's go see how to use these libraries to create
our development local fabric.
To perform local commissioning, we
can pass the device information returned
in the CommissioningRequestMetadata
object.
The chipClient uses this metadata
to create a secure channel between the Google Home sample
app for Matter and your device.
Then we use the awaitCommissionDevice function
to start the commissioning process.
Now that you better understand how
to use the CommissioningClient API,
let's look again at the home screen of our sample app.
Earlier, when Pierre commissioned his ESP32 device,
his instance of the sample app was using our custom app
commissioning service.
This means that the Matter-enabled lighting device
now participates in two fabrics--
Google Home and a local fabric.
Each fabric has its own set of credentials
and a unique 64-bit fabric ID.
Commissioning to a development fabric
allows you to use the libraries from the Matter GitHub
repository to control devices from the sample app.
Here's an example of how we can use Matter's chipClient
to get a pointer to commission devices,
then toggle them on and off.
To demonstrate this functionality,
Pierre can toggle his ESP32 on and off
right from the home screen of the sample app.
In the previous examples, we learned that the Google Home
Mobile SDK makes it possible to commission devices
to the Google fabric and also to a local fabric,
an example of multi-admin flow.
All of that was possible using the commissionDevice method.
Next let's talk about the shareDevice method,
which allows you to open a temporary commissioning
window for devices, change the state of your devices,
enabling them to be commissioned to another fabric,
and control your devices from other apps and ecosystems.
To demonstrate this functionality,
Pierre has installed two separate instances
of the sample app on his phone.
The first instance represents his primary ecosystem
where he's already commissioned the device.
The second app represents a sharing recipient, which
is the target commissioner.
First, he'll open the primary app instance,
then select the commissioned device.
From the Details screen, he taps Share.
The sample app makes a call to the shareDevice API,
and once again, control is transferred
to Google Play Services.
A share sheet displays where he can select other apps
to share the ESP32 device with.
Here he selects the second instance of the sample app.
Acting as the target commissioner,
the second instance of the app completes the commissioning
of the device into its own fabric.
He can name the device anything he
wants in the second app, the same or different.
Both apps now have control over the ESP32 device.
Let's go back to Android studio and see how Pierre did this.
We can still use the commissioning client
to share devices, but this time we'll
declare a ShareDeviceRequest.
The device descriptor provides specific information
about the device, such as its vendor ID, product ID,
and device type.
We'll also set the device name.
Next we set the commissioning window
and pass the device discriminator and passcode.
Now that our shareDevice request is set up,
we get a commissioning client, then
call the shareDevice function.
Once again, we'll use live data objects
to report the results of our API call.
Our Google Home sample app for Matter
also includes a Settings screen and developer utilities
to help you test and debug your own apps.
You can print Datastore repositories
to Logcat and create fake devices to simplify
your development process.
That's all for our simple app demo.
Be sure to check back soon for Google Play Services
updates, codelabs, and sample app downloads,
and don't forget to follow the links in the comments below.
Thanks for watching.