├── test_discover_devices.py ├── test_ble_scan.py └── README.md /test_discover_devices.py: -------------------------------------------------------------------------------- 1 | # simple inquiry example 2 | import bluetooth 3 | 4 | nearby_devices = bluetooth.discover_devices(lookup_names=True) 5 | print("found %d devices" % len(nearby_devices)) 6 | 7 | for addr, name in nearby_devices: 8 | print(" %s - %s" % (addr, name)) 9 | -------------------------------------------------------------------------------- /test_ble_scan.py: -------------------------------------------------------------------------------- 1 | import bluetooth 2 | 3 | # bluetooth low energy scan 4 | from bluetooth.ble import DiscoveryService 5 | 6 | service = DiscoveryService() 7 | devices = service.discover(2) 8 | 9 | for address, name in devices.items(): 10 | print("name: {}, address: {}".format(name, address)) 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # BLE 5 | 6 | ## MacOS 7 | 8 | ``` 9 | pip uninstall pyobjc 10 | pip install pyobjc 11 | pip install git+https://github.com/0-1-0/lightblue-0.4.git 12 | pip install git+https://github.com/karulis/pybluez.git 13 | ``` 14 | 15 | ## Linux 16 | 17 | pybluez for bluetooth2 and BLE, and [bluepy](https://github.com/IanHarvey/bluepy) for BLE only 18 | 19 | ``` 20 | sudo apt-get install libbluetooth-dev 21 | pip install pybluez (I download it and python setup.py install) 22 | ``` 23 | 24 | Install pygattlib 25 | 26 | ``` 27 | Todo 28 | https://raspberrypi.stackexchange.com/questions/55530/pybluez-and-gattlib-error/57520 29 | https://bitbucket.org/OscarAcena/pygattlib/issues/41/ld-cannot-find-lboost_python-py34 30 | 31 | sudo aptitude install libboost-thread-dev 32 | sudo aptitude install libboost-all-dev 33 | 34 | git clone https://github.com/labapart/gattlib.git 35 | mkdir build && cd build 36 | cmake -DGATTLIB_FORCE_DBUS=TRUE .. 37 | make 38 | pip install gattlib 39 | ``` 40 | 41 | Other useful notes 42 | 43 | ``` 44 | $ sudo apt-get --purge remove nodejs node npm 45 | $ sudo apt-get clean 46 | $ sudo apt-get autoclean 47 | $ sudo apt-get -f install 48 | $ sudo apt-get autoremove 49 | ``` 50 | 51 | ## Notes 52 | 53 | - BLE only support Linux, for Windows, use pygatt? 54 | 55 | ------ 56 | # Com port via PL2303 57 | 58 | 59 | ## Linux 60 | 61 | minicom 62 | ``` 63 | http://blog.csdn.net/liang890319/article/details/8246156 64 | ``` 65 | 66 | BLE透传 67 | ``` 68 | https://wenku.baidu.com/view/de1721d86c85ec3a87c2c5f9.html 69 | http://pmt2a3f7b.pic31.websiteonline.cn/upload/gs9a.pdf 70 | http://www.gteray.com/upload/file/20170807/20170807105243824382.pdf 71 | ``` 72 | 73 | --------------------------------------------------------------------------------