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

Docs: Make scanner sample code work with python3 by using print() #497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/scanner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ Basic code to run a LE device scan for 10 seconds follows this example::
# when this python script discovers a BLE broadcast packet, print a message with the device's MAC address
def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
print "Discovered device", dev.addr
print("Discovered device", dev.addr)
elif isNewData:
print "Received new data from", dev.addr
print("Received new data from", dev.addr)

# create a scanner object that sends BLE broadcast packets to the ScanDelegate
scanner = Scanner().withDelegate(ScanDelegate())
Expand All @@ -96,15 +96,15 @@ Basic code to run a LE device scan for 10 seconds follows this example::
for dev in devices:
# print the device's MAC address, its address type,
# and Received Signal Strength Indication that shows how strong the signal was when the script received the broadcast.
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
print("Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi))

# For each of the device's advertising data items, print a description of the data type and value of the data itself
# getScanData returns a list of tupples: adtype, desc, value
# where AD Type means “advertising data type,” as defined by Bluetooth convention:
# https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
# desc is a human-readable description of the data type and value is the data itself
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)
print(" %s = %s" % (desc, value))


For continuous scanning, follow this example::
Expand All @@ -120,17 +120,17 @@ For continuous scanning, follow this example::
# when this python script discovers a BLE broadcast packet, print a message with the device's MAC address
def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
print "Discovered device", dev.addr
print("Discovered device", dev.addr)
elif isNewData:
print "Received new data from", dev.addr
print("Received new data from", dev.addr)

# create a scanner object that sends BLE broadcast packets to the ScanDelegate
scanner = Scanner().withDelegate(ScanDelegate())

# start the scanner and keep the process running
scanner.start()
while True:
print "Still running..."
print("Still running...")
scanner.process()


Expand Down