Comments (16)
I think in my next experiment I'm going to Pythonise an example and supporting subset of the NodeJS BLE library BluetoothHCISocket by @sandeepmistry
from python-bluezero.
Good work @WayneKeenan!
There are two performance issues that are a concern with DBus
- continuously scanning for devices. E.g. if you want to constantly scan for nearby beacons. This was discussed on the Bluez mailing list
http://marc.info/?l=linux-bluetooth&m=148123125327634&w=2
There is no way to do this with the DBus API currently - Throughput with read/write/notify of GATT characteristics. This was the issue raised on the Adafruit BLE library that was linked to on the Bluezero retrospective.
New DBus API of AcquireNotify and AcquireWrite seems to be trying to address this.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt#n117
Does that help?
from python-bluezero.
added a noddy class in a gist that the test just simply bounces the hci0
interface.
Needs to be run with sudo.
from python-bluezero.
I have implemented the experiment and have LE Scanning working, please see https://github.com/TheBubbleworks/python-hcipy
from python-bluezero.
There is now a Connection and a PhysicalWeb Beacon example.
Scripts can also can run as a non-root user, please check out the README for more info.
I'm keen to understand the performance benefits of the approach, @ukBaz please could you outline the structure of a specific test scenario you had in mind? (it was beacon related I think)
from python-bluezero.
Thanks @kaidokert .
I've started a wiki to track these libraries and make it easier for people to update directly:
https://github.com/ukBaz/python-bluezero/wiki
from python-bluezero.
think the way to go is to use struct.pack and fcntl.ioctl, e.g.
buffer = struct.pack("I", dev_id)
fcntl.ioctl(sock.fileno(), HCIDEVUP, buffer)
My test case gets past the data format but is hitting now hitting complaint from the kernel:
IOError: [Errno 25] Inappropriate ioctl for device
My experiment is here
I think running as root might be required. To circumvent that requirement Noble/Bleno use an external binary which has a ACL applied to the binary, that is something not possible for a 'script', AFAIK.
aversion to running a python bluezero daemon as root?
from python-bluezero.
The reason for the failure is because the HCI commands passed to ioctl need to be converted from the 'bare' number to a Linux ioctl encoding, e.g. http://code.activestate.com/recipes/578225-linux-ioctl-numbers-in-python/
I've had a quick try, doesn't work as-is, needs a bit more massaging, will take a look later.
from python-bluezero.
This is the 'call stack' with links to the functions:
- Python enable_le_scan() (example from @colin-guyon)
- bt_hci_send_cmd() (the underlying C source for
import bluetooth._bluetooth as bluez
found in many Python BLE libs) - hci_send_cmd() (BlueZ userland C code)
- writev() (POSIX/GLIBC)
- The Magic Happens(tm)
So, all that's needs is to compress the bits in-between 1 and 5 into 1 :)
EDIT: I should caveat the above by saying this was a manual trawl thru the filesystem and online repositories, not from a runtime or IDE introspection, so please beware it maybe inaccurate.
from python-bluezero.
I meant to add that the prototype demonstrates 3 key aspects of using socket io for HCI:
- sending HCI Commands (e.g. HCIDEVUP)
- decoding HCI responses (e.g. HCIDEVINFO, EVT_LE_META_EVENT)
- handling unsolicited HCI events (e.g. EVT_LE_META_EVENT for LE Scanning)
I've also kept in mind the need to do automated testing so the core class has been written with future automated tests in mind, comments in the code.
from python-bluezero.
That's a great demonstration - I spent quite some time banging my head against a brick wall with a prototype similar to Barry's opener, without knowing about the IOCTL numbers (I was getting a "file descriptor in a bad state" type error from fcntl.ioctl
). I'm glad Barry asked the question and that there is a purely pythonic way to do HCI!
from python-bluezero.
I have just added the port of the LE advertisement test, https://github.com/TheBubbleworks/python-hcipy/blob/master/le_advertisement_test.py
from python-bluezero.
Just as a comment, here is yet another half finished pile of code that kind of speaks HCI ( written for TI BLE embedded configurations )
https://github.com/mzxu/pyble/tree/master/ble
Assumes a serial port, but i've verified it to somewhat work with plain character device too for basic functions. At least the constant tables might be useful for anyone trying direct HCI interface implementation
from python-bluezero.
Thanks @kaidokert .
We should add this to the list of libraries on #126
Maybe we should start a wiki with all these libraries listed.
from python-bluezero.
Not to flood, but i came across this too https://github.com/Jumperr-labs/hci-protocol . Built on top of https://en.wikipedia.org/wiki/Construct_(python_library) which provides nice self-documenting code.
Jumperr-labs also has python-gatt-server and jumper-ble-logger repos that use this implementation.
from python-bluezero.
Closing this and following the Python HCI sockets work happening elsewhere
from python-bluezero.
Related Issues (20)
- Feture request: Implement Agent for pairing support HOT 4
- how to return simple string from update value? HOT 8
- create 2 services from the same source? HOT 3
- Force disconnect clients from peripheral HOT 2
- How best to get extra information like RSSI and tx_power during scan HOT 2
- Disabling BlueZ request to pair with central on connect. HOT 5
- AttributeError: module 'bluezero.async_tools' has no attribute 'EventLoop' HOT 9
- Tests failing and blocking release HOT 1
- Can't install dbus-python to use bluezero HOT 3
- Error "dbus.exceptions.DBusException: org.bluez.Error.NotAvailable: Operation currently not available" on central HOT 8
- using class methods as callbacks fails for writes HOT 2
- Method to determinate current/negotiated MTU for connection HOT 7
- Documentation about PIN on pairing HOT 6
- Name a service and a characteristic HOT 1
- Method to retrieve remote device path in StartNotify and StopNotify HOT 9
- Advertisment of peripheral HOT 3
- Unable to set `DiscoverableTimeout` HOT 2
- What is srv_id 0 zero? HOT 1
- Enable services changed on Generic Attribute service HOT 1
- Wait notification functionality feature HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-bluezero.