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

add a microbit scrolling text example #42

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

danjenkins
Copy link

Let me know if you don't want this in this repo and rather it be a separate repo on the nimbleape org

Basic demo that allows you to write to a micro:bit's led service and have text scroll across the LED matrix on the micro:bit - its a standard service on the micro:bit runtime (microbit-dal)

It also adds support for disconnecting from the micro:bit which isn't in any of the other demos yet I think.

Let me know your thoughts - follows the same patterns as other demos - uses polymer but not the polymer web bluetooth components which hides things away....

I have submitted a CLA, waiting to hear back

@beaufortfrancois
Copy link
Member

beaufortfrancois commented Jun 9, 2016

Thank you @danjenkins! 447 files is too big for GitHub to review this patch. Could you split your PR into 2 commits? One without bower_components and another one with bower_components.

Here's one nit I've noticed:
You could use gattserverdisconnected (featured in https://googlechrome.github.io/samples/web-bluetooth/device-disconnect.html) to know when device is actually disconnected.

@danjenkins
Copy link
Author

Thanks @beaufortfrancois ! I'll do that! Sure, I forgot there was an event - why is a promise not returned from disconnect? Seems like it should be (talking spec now)

@beaufortfrancois
Copy link
Member

beaufortfrancois commented Jun 9, 2016

@jyasskin
Copy link
Member

jyasskin commented Jun 9, 2016

@danjenkins disconnect() doesn't return a promise because we can make it appear to happen instantaneously from the point of view of the page, and because a call to disconnect() from one page may not physically disconnect the device if other pages are still connected. If you want to be sure there's a physical disconnection, you have to ask the device to do it, which will then be reported by gattserverdisconnected. Does that cover what you wanted to use the Promise for?

@danjenkins
Copy link
Author

Yeah that makes sense; it's just that when I was writing the code; I wrote it expecting a promise to be there - as it made sense for it to be there - your explanation makes sense but from a developer point of view; Calling disconnect and then having to listen for an event too is a shame - it would be cool if the it did return a promise that got resolved when the event is fired in that specific scenario

@jyasskin
Copy link
Member

jyasskin commented Jun 9, 2016

I guess I don't follow what you want to use the gattserverdisconnected event for. Calling disconnect() and then listening for it doesn't give you any extra information because it's fired by the call.

@beaufortfrancois
Copy link
Member

@danjenkins Keep in mind that you would probably always want to use the gattserverdisconnected event because it would also be triggered if the device would go out of range / run out of battery / etc.
Moreover as soon as you call disconnect(), your BluetoothDevice is not connected anymore from a JS point of view and you can't do anything but reconnecting before interacting with services/characteristics.

@danjenkins
Copy link
Author

I guess up until now I never listened for disconnect because it didn't exist... all sample apps should now encourage listening for disconnect as part of server connect sequence

@beaufortfrancois
Copy link
Member

@danjenkins
Copy link
Author

SO MANY SITES!! @beaufortfrancois ! I'll try and tackle this PR in the coming days (currently away from home)

@beaufortfrancois
Copy link
Member

@beaufortfrancois
Copy link
Member

beaufortfrancois commented Jul 20, 2016

I've just received my BBC micro:bit device and it works smoothly on Android. Sadly, pairing process is not triggered on Chrome OS. I've filed a bug at https://bugs.chromium.org/p/chromium/issues/detail?id=629773 for this.

@danjenkins
Copy link
Author

Did you turn off bluetooth pairing? https://github.com/nimbleape/microbit-led-service ?

By default the microbit wants proper pairing but thats not very BLE (think bb8) so you can turn it off - the BBC wanted protection etc for kids.

https://github.com/nimbleape/microbit-led-service/blob/master/config.json#L5

@beaufortfrancois
Copy link
Member

I didn't notice the README file. Thanks!
My BBC micro:bit device hasn't been modified yet for this sample.

@danjenkins
Copy link
Author

Ah! :) Yes; still good to know about the pairing issue on ChromeOS

@beaufortfrancois
Copy link
Member

After changing my micro:bit device to more "opened" (not requiring pairing), I'm still having some issues. It looks like the LED service does contain only one characteristic - the led matrix state, not the led text one.

I can reproduce it with https://googlechrome.github.io/samples/web-bluetooth/discover-services-and-characteristics.html?optionalServices=e95dd91d-251d-470a-a062-fa1922dfa9a8,00001801-0000-1000-8000-00805f9b34fb,e95d93b0-251d-470a-a062-fa1922dfa9a8,0000180a-0000-1000-8000-00805f9b34fb,e95d93af-251d-470a-a062-fa1922dfa9a8

Requesting any Bluetooth Device...
> Name:             BBC micro:bit [vagap]
> Allowed Services: 00001801-0000-1000-8000-00805f9b34fb
                    0000180a-0000-1000-8000-00805f9b34fb
                    e95d93af-251d-470a-a062-fa1922dfa9a8
                    e95d93b0-251d-470a-a062-fa1922dfa9a8
                    e95dd91d-251d-470a-a062-fa1922dfa9a8
Connecting to GATT Server...
Getting Services...
Getting Characteristics...
> Service: e95dd91d-251d-470a-a062-fa1922dfa9a8
>> Characteristic: e95d7b77-251d-470a-a062-fa1922dfa9a8 [READ, WRITE]
> Service: e95d93af-251d-470a-a062-fa1922dfa9a8
>> Characteristic: e95d9775-251d-470a-a062-fa1922dfa9a8 [READ, NOTIFY]
>> Characteristic: e95d5404-251d-470a-a062-fa1922dfa9a8 [WRITE]
>> Characteristic: e95d23c4-251d-470a-a062-fa1922dfa9a8 [WRITE]
>> Characteristic: e95db84c-251d-470a-a062-fa1922dfa9a8 [READ, NOTIFY]
> Service: 0000180a-0000-1000-8000-00805f9b34fb
>> Characteristic: 00002a24-0000-1000-8000-00805f9b34fb [READ]
>> Characteristic: 00002a26-0000-1000-8000-00805f9b34fb [READ]
> Service: e95d93b0-251d-470a-a062-fa1922dfa9a8
>> Characteristic: e95d93b1-251d-470a-a062-fa1922dfa9a8 [READ, WRITE]
> Service: 00001801-0000-1000-8000-00805f9b34fb
>> Characteristic: 00002a05-0000-1000-8000-00805f9b34fb [INDICATE]

@danjenkins Is that something you've seen before?

@beaufortfrancois
Copy link
Member

beaufortfrancois commented Jul 21, 2016

Wooo... I'm not sure why but disabling DFU service, Event service & standard BLE device information service makes the trick. I can now see all LED service characteristics:

Requesting any Bluetooth Device...
> Name:             BBC micro:bit [vagap]
> Allowed Services: 00001801-0000-1000-8000-00805f9b34fb
                    e95dd91d-251d-470a-a062-fa1922dfa9a8
Connecting to GATT Server...
Getting Services...
Getting Characteristics...
> Service: e95dd91d-251d-470a-a062-fa1922dfa9a8
>> Characteristic: e95d7b77-251d-470a-a062-fa1922dfa9a8 [READ, WRITE]
>> Characteristic: e95d93ee-251d-470a-a062-fa1922dfa9a8 [WRITE]
>> Characteristic: e95d0d2d-251d-470a-a062-fa1922dfa9a8 [READ, WRITE]
> Service: 00001801-0000-1000-8000-00805f9b34fb
>> Characteristic: 00002a05-0000-1000-8000-00805f9b34fb [INDICATE]

@beaufortfrancois
Copy link
Member

Here's what I would recommend for this patch then:

  • Document memory issue in README
  • Emphasize your your micro:bit led service in README. Could it be part of this demo folder?
  • Error should be more helpful than just Could not connect to bluetooth device!. Add Web Bluetooth error message in dialog.

@beaufortfrancois
Copy link
Member

beaufortfrancois commented Jul 21, 2016

For info, here's my micro:bit program I've used to make it work: https://developer.mbed.org/users/fbeaufort/code/microbit-ble-open/

And specifically the diff for inc/core/MicroBitConfig.h

diff -r 2fc7d7c2fffc -r 04376b21995b inc/core/MicroBitConfig.h
--- a/inc/core/MicroBitConfig.h Wed Jul 13 12:18:46 2016 +0100
+++ b/inc/core/MicroBitConfig.h Thu Jul 21 07:19:19 2016 +0000
@@ -101,7 +101,7 @@
 // For standard S110 builds, this should be word aligned and in the range 0x300 - 0x700.
 // Any unused memory will be automatically reclaimed as HEAP memory if both MICROBIT_HEAP_REUSE_SD and MICROBIT_HEAP_ALLOCATOR are enabled.
 #ifndef MICROBIT_SD_GATT_TABLE_SIZE
-#define MICROBIT_SD_GATT_TABLE_SIZE             0x300
+#define MICROBIT_SD_GATT_TABLE_SIZE             0x700
 #endif

 //
@@ -173,7 +173,7 @@
 // Enable/Disable BLE pairing mode mode at power up.
 // Set '1' to enable.
 #ifndef MICROBIT_BLE_PAIRING_MODE
-#define MICROBIT_BLE_PAIRING_MODE               1
+#define MICROBIT_BLE_PAIRING_MODE               0
 #endif

 // Enable/Disable the use of private resolvable addresses.
@@ -187,7 +187,7 @@
 // Open BLE links are not secure, but commonly used during the development of BLE services
 // Set '1' to disable all secuity
 #ifndef MICROBIT_BLE_OPEN
-#define MICROBIT_BLE_OPEN                       0
+#define MICROBIT_BLE_OPEN                       1
 #endif

 // Configure for open BLE operation if so configured
@@ -234,21 +234,21 @@
 // This allows over the air programming during normal operation.
 // Set '1' to enable.
 #ifndef MICROBIT_BLE_DFU_SERVICE
-#define MICROBIT_BLE_DFU_SERVICE                1
+#define MICROBIT_BLE_DFU_SERVICE                0
 #endif

 // Enable/Disable BLE Service: MicroBitEventService
 // This allows routing of events from the micro:bit message bus over BLE.
 // Set '1' to enable.
 #ifndef MICROBIT_BLE_EVENT_SERVICE
-#define MICROBIT_BLE_EVENT_SERVICE              1
+#define MICROBIT_BLE_EVENT_SERVICE              0
 #endif

 // Enable/Disable BLE Service: MicroBitDeviceInformationService
 // This enables the standard BLE device information service.
 // Set '1' to enable.
 #ifndef MICROBIT_BLE_DEVICE_INFORMATION_SERVICE
-#define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 1
+#define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 0
 #endif

 //


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.

None yet

3 participants