wiki:wireless/bluetooth/ledcandlegatt

Version 8 (modified by Ryan Erbstoesser, 6 years ago) ( diff )

add more info about led command

Remotely Controlling LED Bluetooth Candle with the Gateworks GW16126 CATM1/BLE Mini-PCIe Adapter

Bluetooth Low Engery (BLE) is the latest communication standard in the Internet of Things (IoT) and M2M markets. Sensors that report small amounts of data periodically can last for several years using BLE. The Generic Attribute Profile (GATT) is one of the most common profiles used over BLE. Gateworks setup a LED candle that changes colors and brightness using BLE commands sent from a Gateworks SBC and GW16126 BLE radio. The GW16126 Mini-PCIe card features a u-blox NINA-B301 BLE module with custom Zephyr firmware to use HCI. It also has a u-blox SARA-R4 LTE Cat M-1 modem for pushing data up to the cloud. More can be read on the GW16126 wiki page

Hardware Requirements

  1. Gateworks SBC, preferably Ventana or Newport
  2. Gateworks GW16126 Mini-PCIe BLE & Modem Card
  3. LED Candle
  4. Android Smartphone
  5. Linux Host PC

Sniffing Bluetooth Packets

  1. Install Magic Hue app for the candle onto Android Phone
  2. Use Bluetooth settings on Android Phone to find and connect to the Magic Candle (LEDBlue-081051FE)
  3. Open Magic Hue and connect to Candle device and verify ability to change colors
  4. Connect Android phone to Linux computer (desktop or laptop)
  5. Allow USB Debugging on Android phone
  6. Under Developer Options in Settings on the phone, Enable Bluetooth HCI snoop log
  7. Go back to Magic Hue app and change the colors in a known sequence, such as Blue, Green, Red which will then be recorded in the log.
  8. On the Linux computer, use the following command to retrieve the Bluetooth Log immediately after changing the colors using the Android app:
    adb pull /sdcard/btsnoop_hci.log
    
  9. Open btsnoop_hci.log using WireShark on the host PC
  10. Typically scroll to the bottom and find some events with protocol ATT.
    1. Note the Handle, value 0x002e
    2. Note the Value, 56:ff:00:00:00:f0:aa

Sending BLE Packets over GATT

Now that the packet structure and values are established, the candle can be controlled by the Gateworks SBC & GW16126 BLE card.

The following was done with a Gateworks Ventana SBC using Ubuntu Bionic software.

  1. Load the following modules
    modprobe algif_hash; modprobe algif_skcipher; modprobe algif_rng; modprobe algif_aead; modprobe af_alg; modprobe hci_uart;
    
  2. Start the bluetooth daemon
    bluetoothd -E &
    
  3. Find the device the bluetooth is connected to
    dev=$(basename $(ls -d /sys/bus/usb/drivers/ftdi_sio/*/ttyUSB*))
    
  4. Attach bluetooth to inferface dev
    btattach -B /dev/$dev -S 1000000 -P h4 &
    
  5. Now scan for BLE devices and confirm we have found the candle
    hcitool -i hci0 lescan
    
  6. Change the color of the candle to red, where hci0 is the interface, 3C:A3:08:10:51:FE is the address, 0x002e is the handle and 56ff000000f0aa is a hex representation of the value.
    gatttool -i hci0 -b 3C:A3:08:10:51:FE --char-write-req -a 0x002e  -n 56ff000000f0aa
    
  7. Change the color to green:
    gatttool -i hci0 -b 3C:A3:08:10:51:FE --char-write-req -a 0x002e  -n 5600ff0000f0aa
    

IoT and Beyond

The LED Candle is only an example. In reality, BLE is used for many industrial sensors, such as tags for location information or sensor data. Many Real-time location systems (RTLS) use BLE. Tools can be tracked via BLE tags. BLE beacons can be used for proximity marketing and directions.

BLE is for low bandwidth data applications unlike many consumer uses of regular Bluetooth.

BLE has some big advantages over RFID, some of those being power and cost. BLE tags have a low enough power draw that some can last 5-10 years on a battery.

The BLE chip on the GW16126 allows the Gateworks solution to act as a BLE reader / gateway, collecting all the sensor data and furthermore passing it up to the cloud via WiFi, Ethernet, or Cellular.

The CAT M1 modem on the GW16126 can then further enable internet connectivity, allowing sensor data to be pushed to the cloud. Modem information can be found GW16126 wiki page

More general Bluetooth information can be found on our wiki here

Attachments (6)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.