Implementing a Bluetooth gateway on the Raspberry Pi(Built-In Bluetooth Adapter)。

 

Bluetooth Lighting Control Solution

mijia home hub-2.PNG

 

Prerequisites

The prerequisites of this project are:

A Raspberry Pi 3 Model B

An Internet connection

 

 Installing BlueZ Bluetooth Stack on the Raspberry Pi

 

 

树莓派的芯片类型及支持的蓝牙版本号列表

Raspberry Pi 3 Model A+  Broadcom BCM43438  4.1
Raspberry Pi 3 Model B  Broadcom BCM43438  4.1
Raspberry Pi Model 3B+  Cypress CYW43455  4.2
Raspberry Pi 4 Model B  Cypress CYW43455  5.0

detail:https://www.msly.cn/boards/topic/1135/1/page/2#15392

 

BlueZ is the official Linux Bluetooth protocol stack. It can be deployed on a Linux platform and provides support for the core Bluetooth layers and protocols.

BlueZ for Bluetooth Mesh

BlueZ started to support Bluetooth® Mesh in its BlueZ v5.47 release and has seen some improvements in subsequent releases, BlueZ v5.48 and BlueZ v5.49. These releases come with Bluetooth Mesh support in the form of a new meshctl tool.

How to install latest bluez 5.66(Compile/install latest bluez) on Raspberry step by step

https://www.msly.cn/boards/topic/14427/how-to-install-latest-bluez-566compileinstall-latest-bluez-on-raspberry-step-by-step

 

 

 

Many people know that the Mijia multi-function gateway connects some sensors and other devices to the network through the ZigBee protocol. Similarly, the Bluetooth gateway can connect all Bluetooth sub-devices that support the Mijia standard Bluetooth protocol to the network. In this way, you can remotely view the status from the mobile terminal and set up intelligent automatic linkage.

 

I need to build a bluetooth gateway using a raspberry pi 3 model b.Specifically, I have some BLE sensors and I need to read data from them, assemble and structure that data in a proper format, and then send that data to home assistant.

In this article, we will dive deep into using the Raspberry Pi as a Bluetooth gateway. Imagine a device that is constantly monitoring the Bluetooth IoT devices in your home and reporting to you. The Raspberry Pi 3 can act as a gateway that monitors Bluetooth devices and informs you about them. Imagine a scenario where you have an Estimote Bluetooth beacon with motion sensors and you put it on your front door. If someone breaks in, the beacon will sense it, and the Raspberry Pi will broadcast a notification using the Internet. 

In that situation, the raspberry would have a double role:

- act as a "server" (from the Android Application perspective), receiving commands from the app

- act as a "client" (from the sensors perspective), by receiving sensor readings, structure them and then forward those to the Smartphone app

 

 

The goal of this project is to convert your Raspberry Pi into a Bluetooth gateway so that it can scan and inform you about the surrounding Bluetooth devices (including their services and characteristics).

 

 

Quick start

OS on rpi - debian 11 on rpi 

Step 1 - Update and upgrade the Pi

The first step before starting development on your Raspberry is to make sure that it is up to date.

bluetooth on Rpi 3

step 1:Enable onboard bluetooth on Rpi 3

step 2:Xiaomi Mi Motion Sensor 2 are connected to HomeAssitant with the BLe Discovery proxy.

step 3:use this integration BLE monitor

step 4: Launching the gateway

ble Bluetooth sub devices 

At first you just need to connect to your BLE sub devices via BLE.

1.Xiaomi Mi Motion Sensor 2 isn’t needed to pair it to BLE monitor (BLE monitor will only listen).

2.But it is needed to to add it to MiHome app before it actually sends useful data.

You only need the MiHome app. Xiaomi Mi Motion Sensor 2 need to be added to the MiHome app first, before they are starting to send actual readable data.

3.Make sure you set the region to China mainland in MiHome, as this region has support for more sensors.

4.Xiaomi Mi Motion Sensor 2 needs an encryption key. This isn’t mentioned in the docs, but you can see it at the firmware, which says that it is encrypted

 

 

 

Make Raspberry acting as Bluetooth gateway

https://www.msly.cn/boards/topic/14420/make-raspberry-acting-as-bluetooth-gateway#18921

 

 

 

Step1:Bluetooth on Raspberry is runing

https://www.msly.cn/boards/topic/14420/make-raspberry-acting-as-bluetooth-gateway#18950

 

 

Bluetooth  packets decryption

Some devices use AES encryption to protect the sensor values they are broadcasting.

 

MiBeacon v2/v3 use unauthenticated AES with a 24 character hexadecimal (12 byte) key

MiBeacon v4/v5 use authenticated AES with a 32 character hexadecimal (16 byte) key

This key is called the bindkey or beaconkey.

How to get the MiBeacon V4/V5 encryption key

 

 

Bluetooth Mesh packets decryption

 

The RPi3 will run Rasperry Pi OS (previously called Raspbian) with the BlueZ Bluetooth stack in order to communicate with the Bluetooth Mesh network.

 

The communication will occur between the RPi3 and a node of the Bluetooth Mesh network implementing the Bluetooth Mesh Proxy functionality.

 

Finally, the RPi3 will communicate with the dashboard using MQTT, in order to send and receive data (i.e. it will act both as publisher and subscriber).

 

Useful links

https://www.bluetooth.com/wp-content/uploads/2020/04/Developer-Study-Guide-How-to-Deploy-BlueZ-on-a-Raspberry-Pi-Board-as-a-Bluetooth-Mesh-Provisioner.pdf

https://www.mokoblue.com/bluetooth-mesh-gateway/

Comments


Comments are closed