Wednesday, December 25, 2024

Integrating Amazon Alexa with the ST BlueNRG-Mesh Solution

- Advertisement -

 

Introduction

Bluetooth Mesh is the latest global standard for simple, secure wireless connectivity. It enables one to one and one to many device communications and is ideally suited for building automation, sensor networks and many other IoT solutions where a number (10s to 1000s) of devices need to reliably and securely communicate with each other.

- Advertisement -

Solution providers are looking forward and adopting this technology in numerous applications such as Lighting, HVAC and in industrial automation. In parallel Voice, Assistant Services are gaining popularity and acceptance in the market as they can be controlled using voice commands. Amazon (Alexa), Google (Google Assistant) and Microsoft (Cortana) are some of the big companies working in this domain.

This article describes how Bluetooth Mesh and Voice Assistant Services can be integrated together to control the Bluetooth mesh using a voice command. The solution is developed using STMicroelectronics Bluetooth Mesh (QDID(Qualified Design Id): 116029, BlueNRG-Mesh) SDK and Voice Assistant Software Development Kit from Amazon called Amazon Voice Service (AVS) here. There are three methods to interact with Amazon Voice Service:

1. Amazon Echo and Alexa devices

2. AVS integrated into the embedded device

3. Smartphone Alexa App

The article talks about the integration of STMicroelectronics BlueNRG-Mesh solution with the Amazon Echo device.

ST BLE Mesh App
Figure 1: ST BLE Mesh App

How it works

The solution uses Raspberry Pi as a Gateway device that can be interfaced with the mesh node in the following ways:

1. Connection between Gateway and Bluetooth® Mesh controller is over serial communication protocol such as SPI, I2C or UART. In the current example, communication happens over UART.

2. Standalone Gateway where the Gateway itself is a part of the Bluetooth mesh network. It should have capability to host both Bluetooth-Mesh stack and Internet connectivity.

The Gateway has internet capability and is running Flask-Ask API. Flask-ASK API is a new Python Framework for Rapid Alexa Skills Kit Development. Skills are the built-in capabilities of Amazon devices driven by the voice commands. It listens to the response request coming from the AVS in the Amazon Cloud. The embedded array of microphones inside the Alexa (Echo Dot) device captures the voice commands and sends it to the Cloud. AVS recognizes and interprets the voice commands and sends it back to the Gateway over https endpoint. Flask ASK API on successfully getting the response over https endpoint parses it and forwards it to the BlueNRG-Mesh node over a serial UART. This node then sends the command to the destination in the mesh network. Figure 2 below gives an overview of its working.

Voice Controlled BlueNRG Mesh message flow
Figure 2: Voice Controlled BlueNRG Mesh message flow

Hardware Setup

• Amazon Alexa Device – Amazon Echo or Echo dot, BlueNRG-1 and BlueNRG-2 boards as Mesh Nodes, Raspberry Pi 3 (any model) along with 16GB micro SD Card are required to create the setup.

• Flash the BlueNRG-2 board with the binary from the GitHub link : https://github.com/rawatsaurabh/MeshSkill.git

• Provision the Device with the ST BLE Mesh Smartphone App available on the App store (Refer Figure1)

• Once provisioned, connect the BlueNRG Mesh Node with Gateway as shown below in Figure 3. Power it ON with the micro USB cable (5V Source).

Gateway and BlueNRG-1/2 Hardware Connections
Fig 3 – Gateway and BlueNRG-1/2 Hardware Connections
Setup in Action
Figure 4: Setup in Action

Software Setup

1. Raspberry PI 3 as a Gateway

a. Jessie-lite image downloaded from https://www.raspberrypi.org/downloads/raspbian/ and flash it using Etcher – https://etcher.io/ tool(very easy 3 step process)

b. ssh into the RPI3 and do sudo raspi-config to configure the SSID and password of the Wi-Fi network

>>[email protected]
>>password: raspberry
c. Install Flask ASK API :
>>sudo pip install Flask flask-ask

2. Amazon Skill, RPI FLASK or Flask ASK Python script and https endpoint configuration

a. Log in to the Amazon Developer Console and create a new Skill to interact with the Gateway to Lighten the Bulb.

b. Set the invocation to “Bluetooth Mesh”. “Alexa, tell Bluetooth Mesh to Turn the lights to ON/OFF” is the invocation command in this example.

c. Copy-paste the below python script in one terminal and run it. This will listen to the response from the AVS and send the message to the Node on UART.

from flask import Flask
from flask_ask import Ask,statement,convert_errors
import logging
import serial
print “Mesh Skill”
ser=serial.Serial(“/dev/ttyS0”,baudrate=115200,timeout=5.0)
if ser.isOpen():
print(ser.name + ‘is open..’)
app = Flask(__name__)
ask = Ask(app,’/’)
logging.getLogger(“flask_ask”).setLevel(logging.DEBUG)
@ask.intent(‘LocationControlIntent’,mapping={‘status’:’status’,’location’:’location’})
def location_control(status,location):
locationDict={
‘lights’:21
}
//Custom Protocol to send data over Serial UART to ST’s BlueNRG Mesh Node
value = bytearray([116,101,115,116,32,83,69,84,45,48,51,113])
ser.write(value)
port = 5000
app.run(host=’0.0.0.0′,port=port)

d. Download ngrok:

Visit https://ngrok.com/download and get the latest Linux ARM release as a zip and unzip inside the home directory:

>>unzip /home/pi/ngrok-stable-linux-arm.zip
#Next, run it from the command line in another terminal:
>>sudo ./ngrok http 5000

On the Amazon developer Console go to the endpoint section and paste the https ngrok url obtained by running ngrok command in the terminal previously. Save the skill and build it.

Conclusion

Once the above steps are completed, the user needs to give the voice command – “Alexa, tell Bluetooth to mesh to turn the Lights to ON” to visualize the action happening (Refer Figure 4, where the LED Turns ON). This implementation can be done on any platform running Linux and can be easily portable to STM32 MPU, which is the latest offering by STMicroelectronics in the Embedded Linux World.
This implementation serves as an example to create an opportunity to new Eco-System for Cloud Companies to integrate with the ST BlueNRG-Mesh for the gateway controlled Bluetooth Mesh.


Saurabh Rawat – Staff Engineer, STMicroelectronics India

Kumar Rahul Tiwari – Senior Design Engineer, STMicroelectronics India

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics