Google Assistant on DragonBoard™ 410c

by alvaromfcunha in Circuits > Software

777 Views, 1 Favorites, 0 Comments

Google Assistant on DragonBoard™ 410c

DragonBoard-UpdatedImages-front.png

This Instructables will teach you to run Google Assistant in the DragonBoard and and setup an smarthome environment with some devices.

Required:

-DragonBoard™ 410c (w/ a fresh install of linaro-alip);

-12V/1A 5.5mm jack power supply;

-CC2531 zigbee module;

-HDMI monitor;

-USB mouse and keyboard;

-OSRAM LIGHTFY™ Tunable White 60 bulb;

-FLC BLE bulb;

-Yale Real Living deadbolt smart lock (w/ zigbee module);

-Host PC (w/ Windows)

Google Cloud Log In

1.png

In the host PC, go to the Google Cloud page and log in.

PubSub - Console

2.png

In the left menu hover the mouse over "PubSub" and click on "Topics".

PubSub - Create Google Cloud Project

3.png

Insert a project name and click on "CREATE".

PubSub - Enable API

4.png

Click on "Enable API".

PubSub - Create Topic:

5.png

Click on "Create a topic".

PubSub - Topic Name:

6.png

Insert a name for the topic and click on "CREATE".

PubSub - Create Subscription:

7.png

Click on "CREATE SUBSCRIPTION".

PubSub - Subscription Setup:

9.png

Insert a name to the subscription and fill the rest as the image above shows.

PubSub - Required Topics/Subcriptions:

Following the example, create these topics with these subscriptions:

  1. BluDevCtl
    1. DashBluDevSub
    2. BluDevSub
  2. ZigCtl
    1. DashZigSub
    2. ZigCtlSub

Actions on Google - Log In:

Go to Actions console page and log in with the same account used before.

Actions on Google - Import Project:

10.png

Click on "Add/import project".

Actions on Google - Select the Project:

11.png

Select the previously created project to import and click on "IMPORT PROJECT".

Actions on Google - Device Registration:

oi.png

On project's console click on "Device registration".

Actions on Google - Register Model:

13.png

Click on "REGISTER MODEL".

Actions on Google - Model Setup:

14.png

Insert a name for the device, manufacturer and the device type as Speaker and click on "REGISTER MODEL".

Actions on Google - Client Secret JSON:

15.png
15´.png

Click on "Download OAuth 2.0 credentials" to download the client secret JSON that will be used later and click on "Next".

Actions on Google - Specify Traits:

16.png

Only click on "SKIP".

Account Activity Control:

Go to the Google Activity control page, log in with the same account as before and ensure the following toggle switches are enabled (blue):

  • Web & App Activity. In addition, be sure to select the Include Chrome history and activity from sites, apps, and devices that use Google services checkbox;
  • Device Information;
  • Voice & Audio Activity.

Service Account Credentials - Create Credentials:

18.png

Go to Google Cloud Credentials console, log in with the same account as before and click on "Create credentials".

Service Account Credentials - Setup:

19.png

Choose "New service account" in "Service account", insert a name for it, select "Owner" as the "Role", select JSON as the "Key type" and click on "Create".

Service Account Credentials - Download the Credentials:

20.png

As will click on "Create", a JSON file will be download. Save as you will need this file ahead.

Google Cloud Storage - Create Bucket:

21.png

Go to the Google Cloud Storage page, log in and click on "CREATE BUCKET".

Google Cloud Storage - Free Trial:

22.png

The Storage is a paid service, but Google offers a free trial that has more than needed. To setup the free trial click on "Sign up for a free trial".

Google Cloud Storage - Free Trial - Step 1:

23.png

Select the country, accept the terms of service and click on “AGREE AND CONTINUE”.

Google Cloud Storage - Free Trial - Step 2:

From here you need to enter some institutional information (that vary country to country) and a credit card to be able to access the storage.

Google Cloud Storage - Create Bucket W/ Free Trial:

24.png

Click again on "CREATE BUCKET".

Google Cloud Storage - Bucket Setup:

25.png

Inset a name for the bucket and fill the rest as the image above shows.

Google Cloud Storage - Files:

26.png

Create 3 files with these names:

  • status.txt;
  • statusble.txt;
  • statuszgb.txt.

Google Cloud Storage - Upload Files:

27.png

Upload the files dragging then to the bucket.

Google Cloud Storage - Check the Upload:

28.png

Wait until all files be uploaded.

Google Cloud Functions - Create Function:

29.png

Go to the Google Cloud Functions page and log in. You MUST have followed the instructions for a free trial in Step 22 to be able to create a function.

Google Cloud Functions - Function Setup:

30.png

Fill the setup as the image above shows. The .zip file available to download below.

Downloads

Google Cloud Functions - Inline Editor:

31.png

In the Function Console click on the expand icon of the inline editor.

Google Cloud Functions - Edit Variable:

32.png
34´.png

Set the bucket variable to the name of the Bucket setted in Step 26 and click on "OK".

Google Cloud Functions - Save Changes:

35.png

Click on "Deploy" to save the variable change. Wait the funciton to be deployed, and if any error appears, repeat the process again.

Dialogflow - Console:

36.png

Go to the Dialogflow page and click on "Go to console".

Dialogflow - Log In:

37.png

Log in using the same Google account as before.

Dialogflow - Account Settings:

38.png

Choose a country, accept the terms of service and click on "ACCEPT".

Dialogflow - Agent Setup:

39.png

Select the language, timezone and the Cloud project (Step 3) and click o "CREATE".

Dialogflow - Configuration:

40.png

In the agent console click on the configuration icon.

Dialogflow - Import:

41.png

Click on "Export and import".

Dialogflow - Restore From ZIP:

42.png

Click on "RESTORE FROM ZIP".

Dialogflow - Select File:

43.png

Click on "SELECT FILE".

Dialogflow - Upload ZIP File:

44.png

Select the .zip file available to download below, type RESTORE where it says to and click in "RESTORE".

Dialogflow - Save Changes:

45.png

On the agent console click on "SAVE".

Dialogflow - Fulfillment:

46.png

Click in "Fulfillment" in the left menu.

Dialogflow - Cloud Function Console

47.png

In another tab go to the console of the previously created function and click on "Trigger".

Dialogflow - Cloud Function URL

48.png
49.png

Copy the URL and paste as the Webhook URL in the Dialogflow fulfillment setup.

Dragonboard Setup - Access the DB Terminal:

50.png

To perform these steps you need a form to access the terminal of the DragonBoard. In the example, PuTTY was used on Windows to access via serial UART. Do not run any command that the tutorial shows as ROOT! If accessing the terminal via serial UART switch to user linaro as the image shows.

Command:

$ su linaro

Dragonboard Setup - Download the Code:

Download the .zip in this step and extract.

Downloads

Dragonboard Setup - Connecting Via SFTP:

51.png
52.png

Now it's time to transfer the credentials generated in the Google Cloud to the Dragonboard. It can be done in various ways. This example will use FileZila on the host machine to send the files to the Dragonboard internal memory.

In "Host" insert the DB local network IP*, the default user and password is "linaro" and the "Port" is 22.

*Run ifconfig in the terminal to discover the local IP.

$ ifconfig

Dragonboard Setup - Transfer the Code to the DB:

Transfer the DB_GA folder to the Dragonboard in the /home/linaro/ folder.

Dragonboard Setup - Transfering the Credentials:

54.png
55.png

Now transfer the credentials to the root of the DB_GA folder and rename the "client_secret_XXX.json" to "client_secret.json" and the other to "service_account_key.json".

Dragonboard Setup - Installing Dependencies:

  • Run apt update;
$ sudo apt update
  • Install these packages via apt: python-pip, libglib2.0-dev, swig, portaudio19-dev, libpulse-dev;
$ sudo apt install python-pip libglib2.0-dev swig portaudio19-dev libpulse-dev<br>
  • Go to the “DB” folder in "DB_GA" and run this command to install pip packages;
$ sudo pip install –r requirements.txt
  • Install NodeJS 8.x;
$ sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo bash - 
$ sudo apt install -y nodejs=8.15.1-1nodesource1<br>
  • Go to the “DB_GA/DB/zbserver” folder and run npm install.
sudo npm install

Dragonboard Setup - Credentials Configuration:

56c.png

Now it's time to connect the HDMI monitor, keyboard and mouse to the DB.

In the DB Desktop enter Ctrl+Alt+T to open an terminal.

Go to the DB_GA folder:

$ cd /home/linaro/DB_GA/

Run this command:

$ sudo google-oauthlib-tool --client-secrets client_secret.json --credentials /root/.config/google-oauthlib-tool/credentials.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save

Dragonboard Setup - Credential Login:

57.png

Copy the URL that the last command outputs and paste into the DB browser and log in with the same Google account used in the entire tutorial.

Run the Google Assistant!

Go to the DB_GA/DB/syswatch_dev/ folder:

$ cd /home/linaro/DB_GA/DB/syswatch_dev/

Connect the Zigbee Module to the DB;

Run the watch.py file:

$ sudo python watch.py