🛠 Balise BLE : diffuser un beacon avec le CYW43438

Raspberry Pi Zero W (2017) — Board Sheet · intermediaire · Schéma : IMG-zero-w-intermediaire-3-balise-bluetooth-low-energy.svg — Zero W émettant des paquets d'advertising BLE captés par un smartphone affichant le nom ZeroW-01 et une charge utile personnalisée.

Objectives

Turn the Zero W into a BLE presence beacon: the Cypress CYW43438 chip (the one in the Pi 3 B) supports Bluetooth 4.0 + BLE under Linux, without a dongle.

Hardware

Steps

  1. Install the stack: sudo apt install bluez bluepy then bring up the radio: sudo hciconfig hci0 up.
  2. Broadcast name + manufacturer payload (iBeacon-like schema):
#!/usr/bin/env python3
from bluepy.btle import ADType, Peripheral
import struct, time

p = Peripheral
p.setAdvertiseData(ADType.COMPLETE_LOCAL_NAME, b"ZeroW-01")
payload = struct.pack("<BHBHH", 0xFF, 0x004C, 0x0215, 0xBEEF, 0x0001)
p.setAdvertiseData(ADType.MANUFACTURER_DATA, payload)
p.setAdvertiseEnable(True)
while True:
    time.sleep(1)
  1. Scan from the phone: ZeroW-01 should appear with the payload 0xBEEF.

Verification

hciconfig hci0 shows the interface UP RUNNING; the scanner sees the beacon.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials