Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build/error handling improvements, and pair/unpair support #311

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

agordon
Copy link
Contributor

@agordon agordon commented Sep 28, 2018

Hello @IanHarvey ,

Thanks for writing this awesome python module.
I've been using it to communicate with a Mcirobit Board ( https://microbit.org ) with excellent results.

One thing that did present some problems is pairing/unpairing. The microbit turned out to be a bit finicky,
and bluepy did not have a 'pair' method that worked for me.

As I was debugging and exploring the bluepy-helper module, I've encountered some minor things that could be improved - they are included in this pull-request. There shouldn't be any major changes here, and no changes at all for the default behaviour.

I hope this is useful and will be accepted. If so, I will follow up with my Microbit Module ( agordon@3f2b0c7 ) that adds a new Microbit module+command line program (modelled after the 'thingy52' module) - including pairing support.

Comments very welcomed,
-gordon

Convert the field delimiter to a variable, in preparation
to making it user-configurable.
The current value (ASCII \x1E, RECORD SEPARATOR) stays the same.
Makes rebuilding the 'bluepy-helper' binary quicker during development.
Support minimal command-line processing:
  -h = help screen
  -v = version
  -s = use SPACE as field delimiters
Extract version string from the python package's setup.py
and git revision when rebuilding the executable.
In function 'parse_line', the function 'g_shell_parse_argv' can fail if
the input is invalid (according to its limited parsing features).
In such cases, argvp would be NULL and argvp[0] would segfault.

Example of unparsable input: any string starting with '#'.
When building with debug information (make DEBUGGING=1),
use -O0 for easier debugging. Without debugging, use the default -Os.
Both commands (in bluepy-helper) do not take an address parameter,
but reuse the device address from the previous 'connect' command.
In previus commit c1d8c3e
bluepy-helper binary gained ability to report detailed error codes
and messages in the 'emsg' and 'estat' response fields.

Propagate these optional fields to the BTLEException class,
and display them (when the exception is converted to a string).

The updated exception string looks like:

   bluepy.btle.BTLEException: Disconnect Error: Failed to execute mgmt cmd \
          'unpair' (estat: 6 emsg: Not Paired)
IanHarvey pushed a commit that referenced this pull request Nov 12, 2018
-----

btle: report error details from bluepy-helper

In previus commit c1d8c3e
bluepy-helper binary gained ability to report detailed error codes
and messages in the 'emsg' and 'estat' response fields.

Propagate these optional fields to the BTLEException class,
and display them (when the exception is converted to a string).

The updated exception string looks like:

   bluepy.btle.BTLEException: Disconnect Error: Failed to execute mgmt cmd \
          'unpair' (estat: 6 emsg: Not Paired)
@IanHarvey
Copy link
Owner

Thanks for all the patches. This PR didn't merge cleanly because of conflicts with #302, which I had merged earlier. I'll need to do a bit of cherry-picking to get it all fixed up.

IanHarvey pushed a commit that referenced this pull request Nov 19, 2018
@mdevel1
Copy link

mdevel1 commented Feb 2, 2020

Hi @agordon, do you plan to rebase your branch to resolve the conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants