Skip to content

Python advertisement data #15

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

Merged
merged 19 commits into from
Jul 19, 2019

Conversation

dhalbert
Copy link
Collaborator

These adafruit_ble library updates are necessary for adafruit/circuitpython#1993 (bleio revamp and addition of central).

  • Server advertisement data now construction in adafruit_ble.advertising instead of in C in bleio.
  • Peripheral now subsumes Broadcaster, so code in adafruit_ble.beacon has changed.
  • Add adafruit_ble.scanner.Scanner and ScanEntry, which wrap bleio.Scanner and bleio.ScanEntry, and add additional functionality.
  • Move adafruit_ble.uart.UARTServer to adafruit_ble.uart_server.UARTServer.
  • Add adafruit_ble.uart_client.UARTClient to provide UART functionality as a BLE central.

dhalbert added 12 commits May 31, 2019 17:54
   Rename Advertisement to AdvertisingPacket.
   Make adding advertising flags is now done explicitly by callers.

2. ServerAdvertisement creates a scan response packet to send the
the full name, if it doesn't fit in the initial advertising data packet.

3. Allow UARTServer to specify peripheral name.
@jerryneedell
Copy link
Contributor

Started testing -- with CP PR 1993 installed. -- all of the demos seem to be working. Tried uart, eddystone and both peripheral and central demos.Used 2 nrf52840 express for central<-> peripheral demo.
also I was able to get my previously working "ble_rover" demo working with just the minor change of importing adafruit_ble.uart to adafruit__ble.uart_server.

@jerryneedell
Copy link
Contributor

jerryneedell commented Jul 13, 2019

Just for fun. Also tried central demo on a maker diary nrf52840 usb dongle, only change was to use AINx for Ax for the inputs. works fine.

also tested on a pca10059 (dongle) -- works as well using pins P0_02,P0_29,P0_31 as the analog inputs.

@jerryneedell
Copy link
Contributor

FYI this scanner is a modification of an older version from early ble testing -- it prints out lots of stuff in my house!

from bleio import Scanner

def display_scan_results(scan_entries):
    for e in scan_entries:
        print("ADDR:  ", e.address)
        print("RSSI:  ", e.rssi)
        print("DATA:  ")
        print(''.join('{0:02x}'.format(x) for x in e.advertisement_bytes))

        # Line break between record sets
        print("")

# Scan 1s for advertising devices in range
s = Scanner()
scan_res = s.scan(1)

# Display the scan results
display_scan_results(scan_res)

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like having more logic in Python and less in C.

However, I'm worried about what happens to BLE APIs when we have a couple long lived Services that are managed by the supervisor rather than user code.

@dhalbert
Copy link
Collaborator Author

@tannewt This is ready for re-review. There were a few more global changes after thinking about your feedback and working on the code:

  • Field lookup in advertising packets was moved from ScanEntry to AdvertisingPacket. This makes more sense. Both a __getitem__() and a get() are provided, per your feedback.
  • Scanner.scan() does de-duplication. Scanner.raw_scan() does not: it just returns all the scan entries.
  • Scanner.match() was renamed to Scanner.same_device().

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank!

@tannewt tannewt merged commit f38c77c into adafruit:master Jul 19, 2019
@dhalbert dhalbert deleted the python-advertisement-data branch July 27, 2019 18:46
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 20, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1305 to 1.0.3 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1305#5 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.6.0 from 3.5.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#51 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#47 from Johennes/feature/numpy

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 3.0.0 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#34 from dhalbert/check-cpy-version
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#32 from dhalbert/doc-and-cleanup
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#31 from dhalbert/char-fixes-and-float
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#30 from tannewt/api_rework
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#29 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#25 from kattni/plotter-code
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#23 from kattni/update-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#22 from kattni/update-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#21 from kattni/cpb-color-picker
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#18 from dhalbert/bleio-api-revamp
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#17 from dhalbert/demo-central
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#16 from dhalbert/pairing
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#15 from dhalbert/python-advertisement-data
tannewt pushed a commit to tannewt/Adafruit_CircuitPython_BLE that referenced this pull request Mar 22, 2021
Restructured match_prefixes to correctly match sequence number field
Added insurance that sequence number comes first to do so
Also caught the (macOS) case where adapter has no address (WIP)
Fixes adafruit#15
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