Linux Side Bluetooth Debugging __linux

Source: Internet
Author: User
Tags git clone
Linux side Bluetooth debugging

@ (embedded) [BLE, BLE]

Graduated for most of the year has been engaged in BLE peripherals development, found that Linux can use BlueZ bluetooth development, more convenient is, there is a Python module on the BlueZ interface encapsulation, called BLUEPY, to develop testing to bring more convenience. Get & Install

Development platform Ubunt 14.04

$ sudo apt-get install git build-essential libglib2.0-dev
$ git clone https://github.com/IanHarvey/bluepy.git
$ CD bluepy
$ python setup.py build
$ python setup.py install

Personal test Script Library mybluepy, not how to write Python, for reference. using Hcitool & Gatttool

The tools provided after the BlueZ protocol stack have been installed, and the simple operation is as follows. Viewing devices for a Bluetooth PC

Hcitool Dev
Scan ble
Hcitool Lescan
Set Gatttool
Gatttool-  b 76:66:44:33:22:72-i

-I: Enter interactive mode

Under the Gatttool,
Start connecting devices: Connect
Input: Help View other directives

Enter characteristics to view eigenvalue information, and the result is probably as follows

handle:0x0022, char properties:0x1a, char value handle:0x0023, UUID:0000A802-0000-1000-8000-00805F9B34FB

As above, handle 0x0023 write data, write 0x0100 to 0x0023+1, set up listening, write 0 to cancel listening bluepy script

Module documentation
Provide a simple example:

#!/usr/bin/python from __future__ import print_function import sys import BINASCII import btle import os ble_conn = None Class MyDelegate (Btle. Defaultdelegate): Def __init__ (self, conn): Btle. Defaultdelegate.__init__ (self) self.conn = conn def handlenotification (self, CHandle, data): data = b Inascii.b2a_hex (data) print ("Notification:", str (chandle), "data", data) def handlediscovery (self, dev, IsN  Ewdev, Isnewdata): If Isnewdev:pass elif isnewdata:print ("\ndiscovery:", "MAC:", DEV.ADDR, "Rssi", str (DEV.RSSI)) def ble_connect (DEVADDR): Global ble_conn if not devaddr are None and Ble_con N is none:ble_conn = Btle. Peripheral (devaddr, Btle.
    Addr_type_public) ble_conn.setdelegate (MyDelegate (ble_conn)) print ("Connected") def ble_disconnect (): Global Ble_conn Ble_conn = None print ("Disconnected") if __name__ = = ' __main__ ': Ble_mac = ' 66:55:44:33:22:11 "# Scan scanner = Btle.
        Scanner (). Withdelegate (MyDelegate (None)) Timeout = 10.0 devices = Scanner.scan (timeout) for Dev in devices:  if dev.addr = = Ble_mac:print ("\ndiscovery:", "Mac:", Dev.addr, "Rssi", str (DEV.RSSI)) for
            (Adtype, desc, value) in Dev.getscandata (): Print ("%s (0x%x) =%s"% (desc, int (adtype), value) Break # Connect Ble_connect (BLE_MAC) # Write, set Listen Snd_content_str = "" "\x01\x00" "" BL

    E_conn.writecharacteristic (handle, SND_CONTENT_STR) # Wait Notification ble_conn.waitfornotifications (2.0)
 # Disconnect Ble_disconnect ()
ReferenceGet-Start with BlueZ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.