[nRF5x] How to connect using WebBluetooth REPL?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: How to connect with Bluetooth REPL using nRF UART app?

Post by WhiteHare » Mon Oct 15, 2018 10:19 pm

Nice to meet you Glenn. 8-)
c45713 wrote:
Mon Oct 15, 2018 9:13 pm
When you refer to nrf52832-dk, do you mean pca10040?
yes


c45713 wrote:
Mon Oct 15, 2018 9:13 pm
If so i can provide a hex file that works for me, just to rule out compilation issues.
Yes, please.

c45713
Posts: 33
Joined: Fri Dec 09, 2016 7:09 pm

Re: How to connect with Bluetooth REPL using nRF UART app?

Post by c45713 » Mon Oct 15, 2018 10:43 pm

Attached a hex file generated from yesterday's master (my last sync with mainline).
I have verified that this hex file works with my chromium-browser.
firmware.zip
pca10040 with MICROPY_PY_BLE_NUS (1)
(171.55 KiB) Downloaded 31 times
You can flash this application on top of your flashed SoftDevice ("make BOARD=pca10040 SD=s132 sd"). Issue the following command which will replace the micropython application only (equivalent to "make SD=s132 flash", but makes it easier to flash application outside the build folder):
nrfjprog --program firmware.hex --sectorerase -f nrf52
nrfjprog --reset -f nrf52
If the LED1 is turned on, you know that the application is running as expected on top of the SoftDevice.

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: How to connect with Bluetooth REPL using nRF UART app?

Post by WhiteHare » Tue Oct 16, 2018 1:02 am

Thank goodness you're here. :D :D :D As a result of your post, the WebBluetooth REPL is working now. Unlike before, it echos back whatever I type into it, and then the REPL does its thing, just as it should. :D I'm very glad to finally get un-stuck and start making progress again! 8-) :) :D

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by WhiteHare » Tue Oct 16, 2018 3:54 pm

Glenn,

How exactly is it that I make the sort of magic firmware that you posted? I want to do it for the pca10056 (i.e. nRF52840 development kit) as well.

What I've tried has been:

Code: Select all

make BOARD=pca10056 SD=s140 sd
make BOARD=pca10056 SD=s140 flash
and variations thereof, including your direct invocations of nrfjprog with the firmware that's created in build-pca10056-s140, but no joy. And yes, LED1 is lit. The DK does show up as "mcus" when scanned using bluetooth, but WebBluetooth REPL doesn't work like it does when using your magic firmware with the pca10040 (i.e. nRF52832 development kit).

Attached are my current config files, in case I did something wrong there. However, if not that, then I have no idea why I'm not getting the right results.

So far the only hint of anything wrong when is when you refer to "nrf52" instead of "NRF52" in your invocations of nrfjprog (well, at least according to the nrfjprog documentation), but I don't know that it matters, as I'm not seeing any errors returned.
Attachments
bluetooth_conf.h.tar.gz
(343 Bytes) Downloaded 27 times
mpconfigport.h.tar.gz
(3.15 KiB) Downloaded 31 times

c45713
Posts: 33
Joined: Fri Dec 09, 2016 7:09 pm

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by c45713 » Wed Oct 17, 2018 8:32 pm

I believe i see the problem here. If I run the configuration you attached, it turns out that the BLUETOOTH_WEBBLUETOOTH_REPL has to be set to 0. This flag is used to alternate the advertisment packet between normal advertisment ("micr") and Eddystone URL (https://goo.gl/F7fZ69 => https://aykevl.nl/apps/nus/) . The Eddystone mode is not needed for BLE REPL to work.

Ref:
https://github.com/micropython/micropyt ... art.c#L232

Could you try to disable the BLUETOOTH_WEBBLUETOOTH_REPL in bluetooth_conf.h and see if it helps?

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by WhiteHare » Wed Oct 17, 2018 11:58 pm

c45713 wrote:
Wed Oct 17, 2018 8:32 pm
I believe i see the problem here. If I run the configuration you attached, it turns out that the BLUETOOTH_WEBBLUETOOTH_REPL has to be set to 0. This flag is used to alternate the advertisment packet between normal advertisment ("micr") and Eddystone URL (https://goo.gl/F7fZ69 => https://aykevl.nl/apps/nus/) . The Eddystone mode is not needed for BLE REPL to work.

Ref:
https://github.com/micropython/micropyt ... art.c#L232

Could you try to disable the BLUETOOTH_WEBBLUETOOTH_REPL in bluetooth_conf.h and see if it helps?
You nailed it. After making that change, it works now, even on the pca10056. :D

kak
Posts: 22
Joined: Fri Oct 05, 2018 11:35 am

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by kak » Thu Oct 18, 2018 11:56 am

Great that it works for you now.
I remember having asked asked c45713 about BLUETOOTH_WEBBLUETOOTH_REPL, and he told me that it isn't needed, and therefore I left it at 0, but I didn't think that it'd cause a problem when enabled.

BTW: is there a possibility to have some sort of security on the Bluetooth REPL?

c45713
Posts: 33
Joined: Fri Dec 09, 2016 7:09 pm

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by c45713 » Thu Oct 18, 2018 3:52 pm

BTW: is there a possibility to have some sort of security on the Bluetooth REPL?
It should be possible. The only thing i have done on security so far is to add some pairing to the central in order to get a BLE keyboard connected to a central and print out the characters received from it.
https://github.com/micropython/micropython/pull/4083

However, it should not too different from what you would do for the peripheral role, and this code could be used as a rough base for inspiration.

User avatar
devnull
Posts: 353
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by devnull » Sat Oct 27, 2018 9:56 am

If executing the following, does this mean that the bluetooth stack is installed and working ??

Code: Select all

>>> import ble
>>> ble.enable()
SoftDevice enabled
>>> ble.address()
'fe:08:48:84:fe:28'
>>> 
As I don't see any discoverable bluetooth devices on my Imac, macbook or iphone :-(

User avatar
WhiteHare
Posts: 129
Joined: Thu Oct 04, 2018 4:00 am

Re: [nRF5x] How to connect using WebBluetooth REPL?

Post by WhiteHare » Sat Oct 27, 2018 12:59 pm

Try it again but with SD=140, as per your other thread (viewtopic.php?f=12&t=5348&start=20), since you are using an nRF52840. Sounds as though you are very close to getting it. Then you can join the club. ;)

Post Reply