bluetooth setup?

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
sanandak
Posts: 6
Joined: Sun Sep 01, 2019 3:34 pm

bluetooth setup?

Post by sanandak » Thu Nov 07, 2019 4:18 pm

I flashed
PYBD-SF2-20191106-v1.11-563-g4be316fb0.dfu
to a pyboard D (SF2)

import bluetooth
and
bt = bluetooth.BLE()

both work without error
but
bt.active(1)
simply hangs. The REPL never returns. I have to interrupt with ctrl-C

bt.active() returns False.

Any suggestions on how to trouble shoot? Or a different working micropython image?

Thanks,
Sridhar

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: bluetooth setup?

Post by jimmo » Thu Nov 07, 2019 8:53 pm

Could you please show us the output of flashing the Pyboard? (e.g. the output of dfu-util). Thanks

sanandak
Posts: 6
Joined: Sun Sep 01, 2019 3:34 pm

Re: bluetooth setup?

Post by sanandak » Sun Nov 10, 2019 4:40 pm

Hi, here is the output of flashing the pyboard (using pydfu.py)

Code: Select all

(usb) sakbook:tools sak$ ./pydfu.py -l
Bus 20 Device 050: ID 0483:df11
Memory Layout
    0x8000000  4 pages of  16K bytes
    0x8010000  1 pages of  64K bytes
    0x8020000  7 pages of 128K bytes
    0x80000000 64 pages of  32K bytes
    0x90000000 64 pages of  32K bytes
(usb) sakbook:tools sak$ ls ~/Downloads/*dfu
/Users/sak/Downloads/PYBD-SF2-20191106-v1.11-563-g4be316fb0.dfu
(usb) sakbook:tools sak$ ./pydfu.py -u /Users/sak/Downloads/PYBD-SF2-20191106-v1.11-563-g4be316fb0.dfu
File: /Users/sak/Downloads/PYBD-SF2-20191106-v1.11-563-g4be316fb0.dfu
    b'DfuSe' v1, image size: 968333, targets: 1
    b'Target' 0, alt setting: 0, name: "ST...", size: 968048, elements: 2
      0, address: 0x08008000, size: 423152
      1, address: 0x90000000, size: 544880
    usb: 0483:df11, device: 0x0000, dfu: 0x011a, b'UFD', 16, 0x9671606b
Writing memory...
0x08008000  423152 [=========================] 100% 
0x90000000  544880 [=========================] 100% 
Exiting DFU...
And the output of trying to run bluetooth

Code: Select all

MicroPython v1.11-563-g4be316fb0 on 2019-11-06; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> import bluetooth
>>> bt = bluetooth.BLE()
>>> bt.active()
False
>>> bt.active(True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt: 
>>> 

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: bluetooth setup?

Post by jimmo » Mon Nov 11, 2019 1:47 am

Hi,

Thanks for that.

I'm going to send you a firmware build with some extra debugging, but in the meantime, can you do a simple test just to rule out some other things.

- Install urequests.py (copy the file directly from https://github.com/micropython/micropyt ... equests.py )

- Connect to WiFi

- Run this at the REPL:

Code: Select all

>>> import urequests
>>> urequests.get('https://micropython.org/ks/test.html').text
(Basically just need to know that both wifi and SSL is working)

Thanks!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: bluetooth setup?

Post by jimmo » Mon Nov 11, 2019 2:06 am

Could you please try flashing this firmware and trying the following things:

https://drive.google.com/file/d/16nVtXe ... sp=sharing

Code: Select all

>>> import bluetooth
>>> ble = bluetooth.BLE()
>>> ble.active(True)
This should print out a reasonable amount. If you can paste it into a https://gist.github.com/ (or equivalent) that would be great.

Next can you please verify that the flash data is being read back from the external qspiflash correctly (either copy this into a file and import it, or use Ctrl-E to enter raw repl, paste, then Ctrl-D to run). Again, please post this to a gist or similar.

Code: Select all

import uctypes
import uhashlib

addr = 0x90000000
addr_end = addr + 0x200000
n = 0x10000
while addr < addr_end:
    h = uhashlib.sha256()
    h.update(uctypes.bytearray_at(addr, n))
    print(h.digest())
    addr += n
    
Thanks again!

sanandak
Posts: 6
Joined: Sun Sep 01, 2019 3:34 pm

Re: bluetooth setup?

Post by sanandak » Tue Nov 12, 2019 12:48 am

jimmo - thanks! but still have trouble:

output of bluetooth active() command:
https://gist.github.com/sanandak/17d4eb ... 52e853d778

it still doesn't return to the repl after the debug messages...

contents of the flash:
https://gist.github.com/sanandak/5d2d2e ... 8810e9ce52

Sincerely,
Sridhar

sanandak
Posts: 6
Joined: Sun Sep 01, 2019 3:34 pm

Re: bluetooth setup?

Post by sanandak » Tue Nov 12, 2019 12:59 am

jimmo - I built a dfu from the latest version on github and that seemed to work!
Thanks for all your time and effort - much appreciated!
Sincerely,
Sridhar

Code: Select all

Entering REPL. Use Control-X to exit.
>
MicroPython v1.11-571-g7e374d231 on 2019-11-10; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> 
>>> import bluetooth
>>> bt = bluetooth.BLE()
>>> bt.active(True)
True
>>> 
MPY: sync filesystems
MPY: soft reboot
MicroPython v1.11-571-g7e374d231 on 2019-11-10; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> 
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import bluetooth
=== from micropython import const
=== 
=== _IRQ_SCAN_RESULT = const(1<<4)
=== _IRQ_SCAN_COMPLETE = const(1<<5)
=== 
=== def bt_irq(event, data):
===     if event == _IRQ_SCAN_RESULT:
===         print("result", data)
===         addr_type, addr, connectable, rssi, adv_data = data
===     elif event == _IRQ_SCAN_COMPLETE:
===         print("complete", data)
=== 
=== bt = bluetooth.BLE()
=== print(bt.config('mac'))
=== bt.active(True)
=== 
=== bt.irq(bt_irq)
=== 
=== bt.gap_scan(10000)
b'HJ0\x01\x9b\xf2'
True
>>> result (1, b'D\x8d\xb7YC\xb3', True, -94, b'\x02\x01\x1a\n\xffL\x00\x10\x05\x03\x18\xb5\xa7\x1c')
result (1, b'm\x10.u\xa2\x02', True, -58, b'\x02\x01\x06\x13\xffL\x00\x0c\x0e\x08\xab\x1a08\xc1\xf0Q\x98w?=\xb4\xcd')
complete ()

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: bluetooth setup?

Post by jimmo » Tue Nov 12, 2019 1:46 am

OK, glad it's working, but please let me know if you see the issue again.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: bluetooth setup?

Post by jimmo » Tue Nov 12, 2019 1:57 am

If you did have a minute to investigate further, I'm curious as to why building from latest master was any different...

Is it possible you were using an older version of pydfu.py (like before mid last year), and then when you built from source you also updated your repo to the latest version?

Do you see the same issue if you use dfu-util on the pre-built firmware images?

sanandak
Posts: 6
Joined: Sun Sep 01, 2019 3:34 pm

Re: bluetooth setup?

Post by sanandak » Tue Nov 12, 2019 3:47 am

Hmm.. that might have been it. (though the pydfu was from earlier this year- I only purchased the pybd this summer...)

I re-flashed the image downloaded from micropython.org (the one that gave me trouble):
MicroPython v1.11-563-g4be316fb0 on 2019-11-06; PYBD-SF2W with STM32F722IEK

and this time bluetooth worked fine.

Thanks for your time - I have some paths for troubleshooting in the future!
Sincerely,
Sridhar

Code: Select all

MicroPython v1.11-563-g4be316fb0 on 2019-11-06; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> 
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import bluetooth
=== from micropython import const
=== 
=== _IRQ_SCAN_RESULT = const(1<<4)
=== _IRQ_SCAN_COMPLETE = const(1<<5)
=== 
=== def bt_irq(event, data):
===     if event == _IRQ_SCAN_RESULT:
===         print("result", data)
===         addr_type, addr, connectable, rssi, adv_data = data
===     elif event == _IRQ_SCAN_COMPLETE:
===         print("complete", data)
=== 
=== bt = bluetooth.BLE()
=== print(bt.config('mac'))
=== bt.active(True)
=== 
=== bt.irq(bt_irq)
=== 
=== bt.gap_scan(10000)
=== 
b'HJ0\x01\x9b\xf2'
True
>>> result (1, b'p\xe7\x8bw3;', True, -59, b'\x02\x01\x1a\n\xffL\x00\x10\x05\x13\x1c:\xa4\x06')
complete ()


Post Reply