Skip to content

Instantly share code, notes, and snippets.

@psolyca
Last active September 20, 2021 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psolyca/2b3fb42f67668f59c8ba1ba729e526a3 to your computer and use it in GitHub Desktop.
Save psolyca/2b3fb42f67668f59c8ba1ba729e526a3 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 - ArchLinuxARM - BluetoothLE - Huawei LPv2

How-to to install bluetooth and run huawei-lpv2 on the Rapsberry Pi 3B (v1.2).
Read the whole guide before proceeding.

ArchLinux ARM

Installation

Follow this guide to install Arch on a SDCard.

To install it on a USB stick, you need to :

  1. install ArchLinux ARM on a SDCard
  2. install ArchLinux ARM on the stick the same way
  3. boot with the SDCard but do not follow step #10 of the guide
  4. enable USB boot mode ; write program_usb_boot_mode=1 in /boot/config.txt
  5. reboot the Pi with the SDCard
  6. check the USB boot mode ; type vcgencmd otp_dump | grep 17: result should be 17:3020000a
  7. remove program_usb_boot_mode=1 in /boot/config.txt
  8. reboot without the SDCard
  9. follow step #10 of the guide

Update

pacman -Syu to update the system.

Bluetooth

Since firmware 5.4.50, bluetooth is integrated in the system. We do not need extra packages.

Add dtparam=krnbt=on to /boot/config.txt and ensure enable_uart=0 in /boot/config.txt.
Also ensure that /dev/ttyAMA0 is not used in /boot/cmdline.txt.

Install bluez and bluez-utils.
Automatic start and launch of the service :

systemctl enable bluetooth.service
systemctl start bluetooth.service

Reboot the Pi and bluetooth is started.

Python and modules

Install python.

Install bleak and cryptography modules the way you want, pacman or pip.

For the pacman version, bleak package is in AUR so one may install yay, then python-bleak and python-cryptography.

huawei-lpv2

Installation

Get huawei-lpv2 from official git : https://github.com/zyv/huawei-lpv2
or more advanced git (feature/parse_log branch ) : https://github.com/psolyca/huawei-lpv2.git

Running

One need to enable bluetooth on the Pi and have a first pairing with the band/watch with bluez utils cause huawei-lpv2 is implemented around bluez framework.

bluetoothctl
power on
scan.transport le
scan on
pair MAC_BT_Band
disconnect MAC_BT_Band
exit

Then it is possible to connect to the band/watch.
On first launch python band_lpv2.py a file band.ini is created.
Fill this file with the MAC of :

  • the Pi (client_mac) obtained with bluetoothctl
  • the band (device_mac) obtained on the band

Relaunch python band_lpv2.py and voilà.

It is just a test script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment