Skip to content

Commit abcd65f

Browse files
Merge pull request #2 from electricimp/develop
Bump to 2.0.0: support imp006
2 parents 4731e7a + 63afa2e commit abcd65f

File tree

3 files changed

+101
-15
lines changed

3 files changed

+101
-15
lines changed

Diff for: README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# BTLEBlinkUp 1.0.0 #
1+
# BTLEBlinkUp 2.0.0 #
22

3-
This library provides a foundation for activating end-user devices via Bluetooth LE on imp modules that support this wireless technology (currently imp004m only) using BlinkUp™.
3+
This library provides a foundation for activating end-user devices via Bluetooth LE on imp modules that support this wireless technology (currently imp004m and imp006 only) using BlinkUp™.
44

55
The BTLEBlinkUp library is intended for Electric Imp customers **only**. It contains device-side Squirrel code which enables BlinkUp device activation using enrollment and WiFi credentials transmitted by a companion app running on a mobile device. The companion app must contain the [Electric Imp BlinkUp SDK](https://developer.electricimp.com/manufacturing/sdkdocs), use of which is authorized by API key. Only Electric Imp customers can be provided with a suitable BlinkUp API key. Code for the companion app is not part of this library, but iOS example code is [available separately](https://github.com/electricimp/BluetoothBlinkUp).
66

7-
**To include this library in your project, add** `#require "bt_firmware.lib.nut:1.0.0"` **and** `#require "btleblinkup.device.lib.nut:1.0.0"` **at the top of your device code**.
7+
**To include this library in your project, add** `#require "bt_firmware.lib.nut:1.0.0"` **and** `#require "btleblinkup.device.lib.nut:2.0.0"` **at the top of your device code**.
88

99
## Example Code ##
1010

@@ -26,15 +26,21 @@ This library requires the separate library [Bluetooth Firmware](https://github.c
2626

2727
```squirrel
2828
#require "bt_firmware.lib.nut:1.0.0"
29-
#require "btleblinkup.device.lib.nut:1.0.0"
29+
#require "btleblinkup.device.lib.nut:2.0.0"
3030
```
3131

3232
One of the firmware versions included in [Bluetooth Firmware](https://github.com/electricimp/BluetoothFirmware) should then be included in your BTLEBlinkUp instantiation call:
3333

3434
```squirrel
35+
// For imp004m
3536
local bt = BTLEBlinkUp(serviceUUIDs, BT_FIRMWARE.CYW_43438);
3637
```
3738

39+
```squirrel
40+
// For imp006
41+
local bt = BTLEBlinkUp(serviceUUIDs, BT_FIRMWARE.CYW_43455);
42+
```
43+
3844
### Constructor: BTLEBlinkUp(*uuids, firmware[, lpoPin][, regonPin][, uart]*) ###
3945

4046
#### Parameters ####
@@ -47,6 +53,8 @@ local bt = BTLEBlinkUp(serviceUUIDs, BT_FIRMWARE.CYW_43438);
4753
| *regonPin* | imp **pin** object | No | The imp GPIO pin connected to the Bluetooth LE radio’s BT_REG_ON pin. Default: **hardware.pinJ** |
4854
| *uart* | imp **uart** object | No | The imp UART on which the imp’s Bluetooth radio is connected. Default: **hardware.uartFGJH** |
4955

56+
**Note** The last three parameters are required only on the imp004m. imp006-based applications should not supply arguments to these parameters; indeed, they will be ignored if you do.
57+
5058
#### BLE Service UUIDs ####
5159

5260
The constructor's *uuids* parameter is used to set UUIDs for the BlinkUp services delivered by the library. The UUIDs are supplied as a table which must contain the following keys:
@@ -262,8 +270,10 @@ Nothing.
262270

263271
## Release Notes ##
264272

273+
- 2.0.0
274+
- Support imp006.
265275
- 1.0.0
266-
- Initial public release
276+
- Initial public release.
267277

268278
## License ##
269279

Diff for: btleblinkup.device.lib.nut

+23-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BTLEBlinkUp {
4444
* @property {string} VERSION - The library version.
4545
*
4646
*/
47-
static VERSION = "1.0.0";
47+
static VERSION = "2.0.0";
4848

4949
/**
5050
* @property {imp::bluetooth} ble - The imp API hardware.bluetooth instance.
@@ -69,9 +69,11 @@ class BTLEBlinkUp {
6969
_uart = null;
7070
_blinking = false;
7171
_scanning = false;
72+
_impType = null;
7273

7374
/**
7475
* Instantiate the BLE BlinkUp Class.
76+
* NOTE lpoPin, regonPin and uart only required by imp004m.
7577
*
7678
* @constructor
7779
*
@@ -93,11 +95,18 @@ class BTLEBlinkUp {
9395
if (!_checkUUIDs(uuids)) throw "BTLEBlinkUp() requires the service UUID table to contain specific key names";
9496
_uuids = uuids;
9597

96-
// Set the BLE radio pins, either to the passed in values, or the defaults
97-
// Defaults to the imp004m Breakout Board
98-
_pin_LPO_IN = lpoPin != null ? lpoPin : hardware.pinE;
99-
_pin_BT_REG_ON = regonPin != null ? regonPin : hardware.pinJ;
100-
_uart = uart != null ? uart : hardware.uartFGJH;
98+
_impType = imp.info().type;
99+
if (_impType == "imp004m") {
100+
// Set the BLE radio pins, either to the passed in values, or the defaults
101+
// Defaults to the imp004m Breakout Board
102+
_pin_LPO_IN = lpoPin != null ? lpoPin : hardware.pinE;
103+
_pin_BT_REG_ON = regonPin != null ? regonPin : hardware.pinJ;
104+
_uart = uart != null ? uart : hardware.uartFGJH;
105+
} else {
106+
_pin_LPO_IN = null;
107+
_pin_BT_REG_ON = null;
108+
_uart = null;
109+
}
101110

102111
// Initialize the radio
103112
_init(firmware);
@@ -470,9 +479,12 @@ class BTLEBlinkUp {
470479
*
471480
*/
472481
function _init(firmware) {
473-
// NOTE These require a suitably connected module - we can't check for that here
474-
_pin_LPO_IN.configure(DIGITAL_OUT, 0);
475-
_pin_BT_REG_ON.configure(DIGITAL_OUT, 1);
482+
// FROM 2.0.0, support imp006 by partitioning imp004m-specific settings
483+
if (_impType == "imp004m") {
484+
// NOTE These require a suitably connected module - we can't check for that here
485+
_pin_LPO_IN.configure(DIGITAL_OUT, 0);
486+
_pin_BT_REG_ON.configure(DIGITAL_OUT, 1);
487+
}
476488

477489
// Scan for WiFi networks around the device
478490
local now = hardware.millis();
@@ -533,7 +545,8 @@ class BTLEBlinkUp {
533545

534546
try {
535547
// Instantiate Bluetooth LE
536-
ble = hardware.bluetooth.open(_uart, firmware);
548+
// FROM 2.0.0 - use separate calls for imp004m and imp006
549+
ble = _impType == "imp004m" ? hardware.bluetooth.open(_uart, firmware) : hardware.bluetooth.open(firmware);
537550
} catch (err) {
538551
throw "BLE failed to initialize (error: " + err + ")";
539552
}

Diff for: tests/ble_setup.device.test.nut

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* BLEBlinkUp Library test cases
3+
* Configuration with enable pin
4+
*/
5+
6+
@include "github:electricimp/BluetoothFirmware/bt_firmware.lib.nut"
7+
@include "github:electricimp/BTLEBlinkUp/btleblinkup.device.lib.nut@develop"
8+
9+
class BLESetupTestCase extends ImpTestCase {
10+
11+
_ble = null;
12+
_iType = null;
13+
_isCompatible = false;
14+
15+
/**
16+
* Get the imp Type (impp04m or imp006)
17+
*/
18+
function setUp() {
19+
20+
// Get the test imp’s type and report
21+
_iType = imp.info().type;
22+
this.info("Test running on an " + _iType);
23+
24+
// Check that the imp is compatible
25+
_isCompatible = (_iType == "imp006" || _iType == "imp004m");
26+
this.assertTrue(_isCompatible, "Test run on an incompatible imp");
27+
return "Test running on a compatible imp";
28+
}
29+
30+
/**
31+
* Test sensor readout in async mode
32+
*/
33+
function testBLEInitReadout() {
34+
35+
// Instantiate Bluetooth on a compatible device
36+
if (_isCompatible) {
37+
_ble = BTLEBlinkUp(_initUUIDs(), (this._iType == "imp004m" ? BT_FIRMWARE.CYW_43438 : BT_FIRMWARE.CYW_43455));
38+
39+
local result = (_ble != null);
40+
this.assertTrue(result, "BLEBlinkUp NOT running on " + this._iType);
41+
return "BLEBlinkUp running";
42+
}
43+
44+
this.assertTrue(_isCompatible, "Test run on an incompatible imp");
45+
return;
46+
}
47+
48+
// Auxilliary funtion to set the GATT service UUIDs we wil use
49+
// NOTE Take from the Bluetooth BlinkUp sample code
50+
function _initUUIDs() {
51+
local uuids = {};
52+
uuids.blinkup_service_uuid <- "FADA47BEC45548C9A5F2AF7CF368D719";
53+
uuids.ssid_setter_uuid <- "5EBA195632D347C681A6A7E59F18DAC0";
54+
uuids.password_setter_uuid <- "ED694AB947564528AA3A799A4FD11117";
55+
uuids.planid_setter_uuid <- "A90AB0DC7B5C439A9AB52107E0BD816E";
56+
uuids.token_setter_uuid <- "BD107D3E48784F6DAF3DDA3B234FF584";
57+
uuids.blinkup_trigger_uuid <- "F299C3428A8A4544AC4208C841737B1B";
58+
uuids.wifi_getter_uuid <- "57A9ED95ADD54913849457759B79A46C";
59+
uuids.wifi_clear_trigger_uuid <- "2BE5DDBA32864D09A652F24FAA514AF5";
60+
return uuids;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)