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. Solution providers are looking forward and adopting this technology in the numerous applications such as Lighting, HVAC and in the 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:
- Amazon Echo and Alexa devices
- AVS integrated into the embedded device
- Smartphone Alexa App
The article talks about the integration of STMicroelectronics BlueNRG-Mesh solution with Amazon Echo device.
How it works
The solution uses Raspberry Pi as Gateway device that can be interfaced with the mesh node in following ways:
- 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.
- 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 the 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. The figure 2 below gives the overview of its working.
- 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).
- Raspberry PI 3 as a Gateway
- 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)
- ssh into the RPI3 and do sudo raspi-config to configure the SSID and password of the Wi-Fi network
- Install Flask ASK API :
>>sudo pip install Flask flask-ask2.
- Amazon Skill ,RPI FLASK or Flask ASK Python script and https endpoint configuration
- Login to the Amazon developer Console and create a new Skill to interact with the Gateway to Lighten the Bulb.
- Set the invocation to “Bluetooth Mesh”. “Alexa, tell Bluetooth Mesh to Turn the lights to ON/OFF” is the invocation command in this example
- Copy paste the below python script in one terminal and run it. This will listen 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
print “Mesh Skill”
print(ser.name + ‘is open..’)
app = Flask(__name__)
ask = Ask(app,’/’)
//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])
port = 5000
4. Download ngrok : Visit https://ngrok.com/download and get the latest Linux ARM release as a zip and unzip inside the home directory:
#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.
Once Above steps are completed, the user needs to give the voice command – “Alexa, tell Bluetooth 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.