🛠 Balise BLE : diffuser un beacon avec le CYW43438
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
- 1 Zero W running Raspberry Pi OS Lite
- A smartphone with a BLE scanner (nRF Connect, LightBlue)
Steps
- Install the stack:
sudo apt install bluez bluepythen bring up the radio:sudo hciconfig hci0 up. - 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)
- Scan from the phone:
ZeroW-01should appear with the payload 0xBEEF.
Verification
hciconfig hci0 shows the interface UP RUNNING; the scanner sees the beacon.
Common Errors
- Radio off (
hciconfig hci0 downby default at boot on some images): the scan sees nothing. - bluepy is no longer maintained: test thoroughly before any production use.
Other tutorials for this board
- Premier démarrage headless de la Zero W (Wi-Fi + SSH)
- Suder le header 40 broches et faire clignoter une LED
- Se connecter au Wi-Fi en ligne de commande (nmcli)
- Pi-hole : bloqueur de pub DNS sur Zero W
- Gadget USB : Ethernet sur le port OTG + relais Wi-Fi
- Nœud capteur autonome sur batterie : énergie et fiabilité
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash