diff --git a/docs/reference.md b/docs/reference.md index aca07c1e..257425d3 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -29,21 +29,19 @@ control.inBackground(() => { }); ``` -## bluetooth and Eddystone +## Bluetooth ```namespaces devices.tellCameraTo(MesCameraEvent.TakePhoto); bluetooth.onBluetoothConnected(() => {}); -eddystone.advertiseUrl("https://pxt.io", 6); ``` ```package radio devices bluetooth -eddystone ``` ### See Also -[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth), [eddystone](/reference/eddystone) +[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth) diff --git a/docs/reference/bluetooth.md b/docs/reference/bluetooth.md index d2fa66b2..21e850bb 100644 --- a/docs/reference/bluetooth.md +++ b/docs/reference/bluetooth.md @@ -31,6 +31,13 @@ bluetooth.uartWriteNumber(0); bluetooth.uartWriteValue("", 0); ``` +## Eddystone + +```cards +bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); +bluetooth.stopAdvertising(); +``` + ```package bluetooth ``` @@ -47,4 +54,7 @@ For more advanced information on the @boardname@ Bluetooth UART service includin [uartWriteString](/reference/bluetooth/uart-write-string), [uartWriteNumber](/reference/bluetooth/uart-write-number), [uartWriteValue](/reference/bluetooth/uart-write-value), -[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected) +[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), +[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected), +[advertiseUrl](/reference/bluetooth/advertise-url), +[stopAdvertising](/reference/bluetooth/stop-advertising) diff --git a/docs/reference/bluetooth/advertise-url.md b/docs/reference/bluetooth/advertise-url.md new file mode 100644 index 00000000..e969d21c --- /dev/null +++ b/docs/reference/bluetooth/advertise-url.md @@ -0,0 +1,37 @@ +# Avertise Url + +Advertises a URL via the Eddystone protocol over Bluetooth. + +## ~hint + +### Eddystone + +Bluetooth beacons are used to indicate proximity to a place or object of interest. +Beacons use Bluetooth advertising to broadcast a small amount of data, +which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application. + +There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. +iBeacon is Apple's beacon message format. Eddystone comes from Google. + +Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ . + +## ~ + +```sig +bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); +``` + +### Parameters + +* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 18 characters long +* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range). + +### Example: Broadcast a secret code + +```blocks +bluetooth.advertiseUrl("https://pxt.io?secret=42") +``` + +## See Also + +[stop-advertising](/reference/bluetooth/stop-advertising) diff --git a/docs/reference/bluetooth/stop-advertising.md b/docs/reference/bluetooth/stop-advertising.md new file mode 100644 index 00000000..27a2ce29 --- /dev/null +++ b/docs/reference/bluetooth/stop-advertising.md @@ -0,0 +1,26 @@ +# Stop Advertising + +Stops advertising URL via the Eddystone protocol over Bluetooth. + +## ~hint + +### Eddystone + +Bluetooth beacons are used to indicate proximity to a place or object of interest. +Beacons use Bluetooth advertising to broadcast a small amount of data, +which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application. + +There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. +iBeacon is Apple's beacon message format. Eddystone comes from Google. + +Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ . + +## ~ + +```sig +bluetooth.stop-advertising(); +``` + +## See Also + +[advertise-url](/reference/bluetooth/advertise-url) diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 007f5518..fc2add8e 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -11,7 +11,6 @@ using namespace pxt; namespace bluetooth { MicroBitUARTService *uart = NULL; - /** * Starts the Bluetooth accelerometer service */ @@ -119,5 +118,30 @@ namespace bluetooth { //% parts="bluetooth" void onBluetoothDisconnected(Action body) { registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body); - } + } + + const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; + + /** + * Advertise an Eddystone URL + * @param url the url to transmit. Must be no longer than the supported eddystone url length + * @param power power level between 0 and 7, e.g.: 7 + */ + //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" + //% parts=bluetooth + //% help=bluetooth/advertise-url + void advertiseUrl(StringData* url, int power) { + int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; + uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level); + } + + /** + * Stops advertising Eddystone end points + */ + //% blockId=eddystone_stop_advertising block="eddystone stop advertising" + //% parts=bluetooth + //% help=bluetooth/stop-advertising + void stopAdvertising() { + uBit.bleManager.stopAdvertising(); + } } \ No newline at end of file diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index 3f480408..99af025c 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -46,4 +46,13 @@ namespace bluetooth { // dummy implementation for simulator return "???" } + + //% shim=bluetooth::advertiseUrl + export function advertiseUrl(url: string, powerLevel: number) { + } + + //% shim=bluetooth::stopAdvertising + export function stopAdvertising() { + } + } diff --git a/libs/bluetooth/pxt.json b/libs/bluetooth/pxt.json index 51f109d8..680fc305 100644 --- a/libs/bluetooth/pxt.json +++ b/libs/bluetooth/pxt.json @@ -25,7 +25,9 @@ "tx_power": 6, "dfu_service": 1, "event_service": 1, - "device_info_service": 1 + "device_info_service": 1, + "eddystone_url": 1, + "eddystone_uid": 0 }, "gatt_table_size": "0x700" } diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index 58c52fa9..1df83b16 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -80,6 +80,24 @@ declare namespace bluetooth { //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" //% parts="bluetooth" shim=bluetooth::onBluetoothDisconnected function onBluetoothDisconnected(body: () => void): void; + + /** + * Advertise an Eddystone URL + * @param url the url to transmit. Must be no longer than the supported eddystone url length + * @param power power level between 0 and 7, e.g.: 7 + */ + //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" + //% parts=bluetooth + //% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl + function advertiseUrl(url: string, power: number): void; + + /** + * Stops advertising Eddystone end points + */ + //% blockId=eddystone_stop_advertising block="eddystone stop advertising" + //% parts=bluetooth + //% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising + function stopAdvertising(): void; } // Auto-generated. Do not edit. Really. diff --git a/libs/core/dal.d.ts b/libs/core/dal.d.ts index 7e7f4134..6dae7e1f 100644 --- a/libs/core/dal.d.ts +++ b/libs/core/dal.d.ts @@ -80,13 +80,13 @@ declare const enum DAL { MICROBIT_BLE_POWER_LEVELS = 8, MICROBIT_BLE_MAXIMUM_BONDS = 4, MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL = 400, + MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER = 0xF0, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitButtonService.h // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitDFUService.h MICROBIT_DFU_OPCODE_START_DFU = 1, MICROBIT_DFU_HISTOGRAM_WIDTH = 5, MICROBIT_DFU_HISTOGRAM_HEIGHT = 5, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitEddystone.h - MICROBIT_BLE_EDDYSTONE_URL_ADV_INTERVAL = 400, // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitEventService.h // built/yt/yotta_modules/microbit-dal/inc/bluetooth/MicroBitIOPinService.h MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19, diff --git a/libs/eddystone/eddystone.cpp b/libs/eddystone/eddystone.cpp deleted file mode 100644 index c5ecf11a..00000000 --- a/libs/eddystone/eddystone.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "pxt.h" -#include "MicroBitEddystone.h" - -using namespace pxt; - -/** -* Support for Eddystone beacons -*/ -//% color=#0082FB weight=19 -namespace eddystone { - const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; - - /** - * Advertise an Eddystone URL - * @param url the url to transmit. Must be no longer than the supported eddystone url length - * @param power power level between 0 and 7, e.g.: 7 - * @param connectable true to keep bluetooth connectable for other services, false otherwise - */ - //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" - void advertiseUrl(StringData* url, int power, bool connectable) { - int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; - uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable); - } - - /** - * Stops advertising Eddystone end points - */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" - void stopAdvertising() { - uBit.bleManager.stopAdvertising(); - } -} diff --git a/libs/eddystone/eddystone.ts b/libs/eddystone/eddystone.ts deleted file mode 100644 index 12c902b1..00000000 --- a/libs/eddystone/eddystone.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** -* Support for Eddystone beacons -*/ -//% color=#0082FB weight=19 -namespace eddystone { - //% shim=eddystone::advertiseUrl - export function advertiseUrl(url: string, powerLevel: number, connectable: boolean) { - } - - //% shim=eddystone::stopAdvertising - export function stopAdvertising() { - } -} diff --git a/libs/eddystone/enums.d.ts b/libs/eddystone/enums.d.ts deleted file mode 100644 index 7c80d5f7..00000000 --- a/libs/eddystone/enums.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Auto-generated. Do not edit. -declare namespace eddystone { -} - -// Auto-generated. Do not edit. Really. diff --git a/libs/eddystone/pxt.json b/libs/eddystone/pxt.json deleted file mode 100644 index 76388b95..00000000 --- a/libs/eddystone/pxt.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "eddystone", - "description": "Eddystone beacon support", - "dependencies": { - "core": "file:../core" - }, - "files": [ - "eddystone.cpp", - "eddystone.ts", - "enums.d.ts", - "shims.d.ts" - ], - "yotta": { - "config": { - "microbit-dal": { - "bluetooth": { - "enabled": 1, - "eddystone_url": 1, - "eddystone_uid": 0 - } - } - }, - "optionalConfig": { - "microbit-dal": { - "bluetooth": { - "pairing_mode": 0, - "private_addressing": 0, - "whitelist": 0, - "advertising_timeout": 0, - "tx_power": 6, - "dfu_service": 0, - "event_service": 0, - "device_info_service": 0 - } - } - } - } -} \ No newline at end of file diff --git a/libs/eddystone/shims.d.ts b/libs/eddystone/shims.d.ts deleted file mode 100644 index 7db54b41..00000000 --- a/libs/eddystone/shims.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Auto-generated. Do not edit. - - - /** - * Support for Eddystone beacons - */ - //% color=#0082FB weight=19 -declare namespace eddystone { - - /** - * Advertise an Eddystone URL - * @param url the url to transmit. Must be no longer than the supported eddystone url length - * @param power power level between 0 and 7, e.g.: 7 - * @param connectable true to keep bluetooth connectable for other services, false otherwise - */ - //% blockId=eddystone_advertise_url block="eddystone advertise url %url|power %powerLevel" shim=eddystone::advertiseUrl - function advertiseUrl(url: string, power: number, connectable: boolean): void; - - /** - * Stops advertising Eddystone end points - */ - //% blockId=eddystone_stop_advertising block="eddystone stop advertising" shim=eddystone::stopAdvertising - function stopAdvertising(): void; -} - -// Auto-generated. Do not edit. Really. diff --git a/pxtarget.json b/pxtarget.json index e426ec06..cf55e6ca 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -9,8 +9,7 @@ "libs/core", "libs/radio", "libs/devices", - "libs/bluetooth", - "libs/eddystone" + "libs/bluetooth" ], "cloud": { "workspace": false, @@ -163,7 +162,7 @@ "yottaTarget": "bbc-microbit-classic-gcc", "yottaCorePackage": "microbit", "githubCorePackage": "lancaster-university/microbit", - "gittag": "v2.0.0-rc6", + "gittag": "v2.0.0-rc7", "serviceId": "microbit" }, "serial": {