/ble

Bluetooth LE related programs

Primary LanguagePythonOtherNOASSERTION

ble

Bluetooth LE related programs for Raspberry Pi/Linux.

  • bledevice.py : basic class module for BLE devices
  • blecomm.py : test program for communicating with an HM-10 BLE module
  • blebulb.py : control program for Zengge BLE bulb
  • yeelight.py : control program for Yeelight bedside lamp
  • beacon : iBeacon and Google Eddystone related programs

To use these programs, you have to install bluez and python pexpect module.

The bluez (Bluetooth stack for linux) package can be installed by executing the following command:

sudo apt-get install bluetooth blueman bluez python-gobject python-gobject-2

The pexpect module can be installed as follows:

sudo pip install pexpect

BLE bulb Protocols

##Zengge Bluetooth LED Originally Zengge BLE bulb can be controlled by the Magic Light app. To execute our control program, use the following command.

python blebulb.py
FunctionCommandCharacteristic (Handle)Data
PowerWrite0xffe9 (0x43) STX(cc) : 0x24 : ETX(33)
Ex) Turn On : 0xcc2333, Turn Off: 0xcc2433
RGB LightWrite0xffe9 (0x43) STX(56) : R : G : B : 00 : f0 : ETX(aa)
Ex) Red : 0x56ff000000f0aa
Yellow : 0x56ffff0000f0aa, Blue: 0x560000ff00f0aa
Warm LightWrite0xffe9 (0x43) STX(56) : 00 00 00 : Lightness : 0f : ETX(aa)
Ex) 0x56000000ff0faa
Set ModeWrite0xffe9 (0x43) STX(bb) : Mode(25-38) : Speed(01-FF) : ETX(44)
Ex) 7 lights conversion(mode=0x25) : 0xbb250344
Get StateWrite and Read0xffe9 (0x43)
0xffe4 (0x50)
STX(ef) : 01 : ETX(77) = 0xef0177
Return: STX(66) 15 Power Mode 20 Speed R G B Lightness 06 ETX(99)
66 15 23 41 20 00 ff ff ff 00 06 99
66 15 23 25 20 05 ff ff ff 00 06 99 Mode(=0x25)
66 15 23 41 20 00 00 00 00 ff 06 99 Warm

##Yeelight Bedside Lamp Of course, Xiaomi's Yeelight Bedside Lamp can be controlled by the Yeelight Lamp app. To execute our control program, use the following command.

python yeelight.py
FunctionCommandCharacteristic (Handle)Data
CertificationWrite and Read0xaa7d3f34 (0x12) STX(43) : CMD(0x67) : ON(0x02) : ETX(00)\*15 - Total 18B
Return: STX(43) : CMD(0x63) : ON(0x02) : ETX(00)
PowerWrite0xaa7d3f34 (0x12) STX(43) : CMD(0x40) : ON(0x01)|OFF(0x02) : ETX(00)\*15 - Total 18B
Ex) Turn On : 0x434001000000000000000000000000000000
Turn Off: 0x434002000000000000000000000000000000
RGB LightWrite0xaa7d3f34 (0x12) STX(43) : CMD(0x41) : R : G : B : 00 : 65 : ETX(00)\*11
Ex) Red : 0x4341ff000000650000000000000000000000
Warm LightWrite0xaa7d3f34 (0x12) STX(43) : CMD(0x43) ; Color(2B, 1700~6500) : 65 : ETX(00)\*13
Ex) 0x43430400650000000000000000000000
LightnessWrite0xaa7d3f34 (0x12) STX(43) : CMD(0x42) : Lightness : ETX(00)*15
The range of Lightness is 1 ~ 100
Ex) 0x434263000000000000000000000000000000