commit
d1021a30ca
@ -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)
|
||||
|
41
docs/reference/bluetooth/advertise-url.md
Normal file
41
docs/reference/bluetooth/advertise-url.md
Normal file
@ -0,0 +1,41 @@
|
||||
# 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", 7);
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[stop-advertising](/reference/bluetooth/stop-advertising)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
38
docs/reference/bluetooth/stop-advertising.md
Normal file
38
docs/reference/bluetooth/stop-advertising.md
Normal file
@ -0,0 +1,38 @@
|
||||
# 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.stopAdvertising();
|
||||
```
|
||||
|
||||
### Example: stop advertising on button pressed
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
bluetooth.stopAdvertising();
|
||||
})
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[advertise-url](/reference/bluetooth/advertise-url)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
28
docs/reference/eddystone.md
Normal file
28
docs/reference/eddystone.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Eddystone
|
||||
|
||||
Support for Eddystone beacons.
|
||||
|
||||
```cards
|
||||
eddystone.advertiseUrl("https://pxt.io/", 6);
|
||||
eddystone.stopAdvertising();
|
||||
```
|
||||
|
||||
### Advanced
|
||||
|
||||
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.
|
||||
|
||||
More information at https://lancaster-university.github.io/microbit-docs/ble/eddystone/
|
||||
|
||||
### See Also
|
||||
|
||||
[eddystone.advertiseUrl](/reference/eddystone/advertise-url),
|
||||
[eddystone.stopAdvertising](/reference/eddystone/stop-advertising),
|
||||
|
||||
```package
|
||||
eddystone
|
||||
```
|
@ -1,5 +1,8 @@
|
||||
{
|
||||
"bluetooth": "Support for additional Bluetooth services.",
|
||||
"bluetooth.advertiseUrl": "Advertise an Eddystone URL",
|
||||
"bluetooth.advertiseUrl|param|power": "power level between 0 and 7, e.g.: 7",
|
||||
"bluetooth.advertiseUrl|param|url": "the url to transmit. Must be no longer than the supported eddystone url length",
|
||||
"bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth",
|
||||
"bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established",
|
||||
"bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost",
|
||||
@ -11,6 +14,7 @@
|
||||
"bluetooth.startMagnetometerService": "Starts the Bluetooth magnetometer service",
|
||||
"bluetooth.startTemperatureService": "Starts the Bluetooth temperature service",
|
||||
"bluetooth.startUartService": "Starts the Bluetooth UART service",
|
||||
"bluetooth.stopAdvertising": "Stops advertising Eddystone end points",
|
||||
"bluetooth.uartReadUntil": "Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.",
|
||||
"bluetooth.uartWriteNumber": "Prints a numeric value to the serial",
|
||||
"bluetooth.uartWriteString": "Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.",
|
||||
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power",
|
||||
"bluetooth.onBluetoothConnected|block": "on bluetooth connected",
|
||||
"bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",
|
||||
"bluetooth.startAccelerometerService|block": "bluetooth accelerometer service",
|
||||
@ -8,6 +9,7 @@
|
||||
"bluetooth.startMagnetometerService|block": "bluetooth magnetometer service",
|
||||
"bluetooth.startTemperatureService|block": "bluetooth temperature service",
|
||||
"bluetooth.startUartService|block": "bluetooth uart service",
|
||||
"bluetooth.stopAdvertising|block": "bluetooth stop advertising",
|
||||
"bluetooth.uartReadUntil|block": "bluetooth uart|read until %del=serial_delimiter_conv",
|
||||
"bluetooth.uartWriteNumber|block": "bluetooth uart|write number %value",
|
||||
"bluetooth.uartWriteString|block": "bluetooth uart|write string %data",
|
||||
|
@ -11,7 +11,6 @@ using namespace pxt;
|
||||
namespace bluetooth {
|
||||
MicroBitUARTService *uart = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Starts the Bluetooth accelerometer service
|
||||
*/
|
||||
@ -120,4 +119,29 @@ namespace 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="bluetooth advertise url %url|with power %power"
|
||||
//% parts=bluetooth weight=11 blockGap=8
|
||||
//% 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="bluetooth stop advertising"
|
||||
//% parts=bluetooth weight=10
|
||||
//% help=bluetooth/stop-advertising
|
||||
void stopAdvertising() {
|
||||
uBit.bleManager.stopAdvertising();
|
||||
}
|
||||
}
|
@ -16,20 +16,29 @@
|
||||
"config": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 1,
|
||||
"pairing_mode": 1,
|
||||
"enabled": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"optionalConfig": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"private_addressing": 0,
|
||||
"open": 0,
|
||||
"whitelist": 1,
|
||||
"advertising_timeout": 0,
|
||||
"tx_power": 6,
|
||||
"dfu_service": 1,
|
||||
"event_service": 1,
|
||||
"device_info_service": 1
|
||||
"device_info_service": 1,
|
||||
"eddystone_url": 1,
|
||||
"eddystone_uid": 0,
|
||||
"pairing_mode": 1,
|
||||
"open": 0,
|
||||
"security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM"
|
||||
}
|
||||
},
|
||||
"gatt_table_size": "0x700"
|
||||
}
|
||||
}
|
||||
},
|
||||
"installedVersion": "vzlhfd"
|
||||
}
|
18
libs/bluetooth/shims.d.ts
vendored
18
libs/bluetooth/shims.d.ts
vendored
@ -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="bluetooth advertise url %url|with power %power"
|
||||
//% parts=bluetooth weight=11 blockGap=8
|
||||
//% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl
|
||||
function advertiseUrl(url: string, power: number): void;
|
||||
|
||||
/**
|
||||
* Stops advertising Eddystone end points
|
||||
*/
|
||||
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
|
||||
//% parts=bluetooth weight=10
|
||||
//% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising
|
||||
function stopAdvertising(): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
2
libs/core/dal.d.ts
vendored
2
libs/core/dal.d.ts
vendored
@ -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,
|
||||
|
@ -42,8 +42,7 @@
|
||||
"public": true,
|
||||
"dependencies": {},
|
||||
"yotta": {
|
||||
"configIsJustDefaults": true,
|
||||
"config": {
|
||||
"optionalConfig": {
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 0
|
||||
|
@ -162,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": {
|
||||
|
@ -166,11 +166,10 @@ namespace pxsim.bluetooth {
|
||||
// TODO
|
||||
}
|
||||
export function uartWrite(s: string): void {
|
||||
// TODO
|
||||
serial.writeString(s)
|
||||
}
|
||||
export function uartReadUntil(del: string): string {
|
||||
// TODO
|
||||
return ""
|
||||
return serial.readUntil(del);
|
||||
}
|
||||
export function onBluetoothConnected(a: RefAction) {
|
||||
// TODO
|
||||
@ -178,5 +177,7 @@ namespace pxsim.bluetooth {
|
||||
export function onBluetoothDisconnected(a: RefAction) {
|
||||
// TODO
|
||||
}
|
||||
export function advertiseUrl(url: string, power: number) { }
|
||||
export function stopAdvertising() { }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user