No reason why not, I think: itâs just a matter of formatting the advertising data packet appropriately. I used iBeacons in the documentation because thatâs what Iâm familiar with; Eddystone wasnât around when I first looked at iBeacons back in 2013. Eddystone beacon data is formatted this way.
One nice feature I like about Eddystone is the ability to interleaf different data packet formats so that you can insert say TLM data (which would most often consist of the battery and other health check data) on say every 10th advertisement instead of say URL/UID format. I assume this is possible.
Where I think the IMP004 version will be really powerful is the ability to use the EID format (or a derivative of this). With this option, you can dynamically change the advertising 10-byte namespace making it much more secure.
Would this BLE functionality, on the condition that the right device code is pre-loaded during production, allow for â end-user blinkup lessâ operation ? ie. device boots first time and just loops while awaiting a BT connection for the end-user to set itâs wifi credentials which then subsequently allow it to go online ?
Yes, you can do âblinkup over bluetoothâ post factory. This includes things like scanning for wifi networks that the imp can see, which prevents the user specifying (eg) a 5GHz network which the imp canât hear.
We have some example code which implements this and will be expanding on that in the future.
Iâm struggling with this a bit. I am simply trying to use my phone to connect to the device and trigger the onconnect callback. Iâm using several BLE terminal apps and I can see the device, but the connection fails and I have not been able to trigger onconnect.
`#require "ConnectionManager.lib.nut:2.1.0"
const IMP004M_BT_FIRMWARE =
// Instantiate ConnectionManager so BlinkUp is always enabled,
// and we automatically agressively try to reconnect on disconnect
cm <- ConnectionManager({
"startupBehavior" : ConnectionManager.START_CONNECTED,
"stayConnected" : true
});
// Set the recommended buffer size (see note below)
imp.setsendbuffersize(8096);
led <- hardware.pinB;
// Set up BT on imp004m Breakout Board
bt <- null;
bt_uart <- hardware.uartFGJH;
bt_lpo_in <- hardware.pinE;
bt_reg_on <- hardware.pinJ;
// Boot up BT
bt_lpo_in.configure(DIGITAL_OUT, 0);
bt_reg_on.configure(DIGITAL_OUT, 1);
// Pregnant pause while BT boots...
imp.sleep(0.05);
local start = hardware.millis();
try {
// Instantiate BT
bt = hardware.bluetooth.open(bt_uart, IMP004M_BT_FIRMWARE);
server.log("BLE initialized after " + (hardware.millis() - start) + " ms");
} catch (err) {
server.error(err);
server.log("BLE failed after " + (hardware.millis() - start) + " ms");
}
bt.setsecurity(1);
bt.onconnect(function (conn) {
server.log("Connection attempt made from " + conn.address());
// Register the remote closure notifier function
conn.onclose(function () {
server.log("Connection closed by " + conn.address());
});
});
local BTadvertisement = "\x02\x01\x01\x09\x09\x42\x6c\x75\x65\x66\x69\x73\x68\x05\x02\x0F\x18\x0A\x18\x00"; // length:2 - flags - gen discoverable - length:9 - comp local name - B-L-U-E-F-I-S-H - length:5 - incomplete list of services - dev info service (2) - batt inf service (2) - end
//local BTadvertisement = "\x02\x01\x1A\x1A\xFF\x4C\x00\x02\x15\x92\x77\x83\x0A\xB2\xEB\x49\x0F\xA1\xDD\x7F\xE3\x8C\x49\x2E\xDE\x00\x00\x00\x00\xC5\x00"; //ibeacon
try {
bt.startadvertise(BTadvertisement, 100, 100);
}
catch (err){server.log(err)}
bt.servegatt([
{ uuid = 0x180a, // Device information service
chars = [
{ uuid = 0x2a29, value = "Electric Imp" }, // manufacturer name
{ uuid = 0x2a25, value = hardware.getdeviceid() }, // serial number
{ uuid = 0x2a24, value = imp.info().type }, // model type
{ uuid = 0x2a26, value = imp.getsoftwareversion() },// firmware version
]
},
{ uuid = 0x180f, // Battery level service
chars = [
{ uuid = 0x2a19, read = function(conn) {
local b = blob(1);
local battery_percent = hardware.vbat() / 4.2 * 100;
b.writen(battery_percent, 'b');
return b;
}
}
]
}
]);`
With your code and PunchThroughâs LightBlue app in iOS, I can see my imp004m breakout board as Bluefish, and connect to it to retrieve the data served via GATT. The imp004m logs the connection from the app as expected.
Are you using a âclassic Bluetoothâ monitor, or one that uses Bluetooth LE, as LightBlue does?
I tried half a dozen BLE terminal apps. Just downloaded the Android version of Punchthroughâs Light Blue and it doesnât work either. I can see the device, see the name, but it wonât connect⌠.
Could be, but seems unlikely. As I say, I used your code and it worked for me. LightBlue sees and connects to both of my imp004m breakout boards, one running your code, the other running mine. The only difference is that I didnât include the ConnectionManager lines, but I canât see how that would cause any issues.
Iâm using iOS. Maybe itâs something to do with your Android phone? Iâll dig out an Android device and seeâŚ
Update Just tried LightBlue on a MotoG3 and it doesnât see the imp004m at all â or my other imp004m. Yet the Bluetooth section of the Settings app does see it. Go figure.
I would see if you can borrow an iOS device - it seems to make Bluetooth more accessible
Well, nRF Connect works perfectly on Android for me using your code, so I think we can say the issues you have been experiencing are more to do with the apps than Android itself.