IMP004 Bluetooth - This is a nice addition


#1

Just spotted the imp blog post - http://blog.electricimp.com/post/168293177440/electric-imp-announces-platform-native-bluetooth

This is a great addition to the range.

Say will this IMP004 be dual-core, as per Cypress PSoC 6 and similarly ESP32 development platform hardware.


#2

This isn’t a new device - all imp004m’s have bluetooth and always have… we just kept it hidden until it was ready :slight_smile:


#3

I see from the documentation no mention of (the far superior, IMHO) Eddystone beacon protocol. Is this something that a user can implement.


#4

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.


#5

ok, that’s good news.

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.


#6

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 ?


#7

Yes, it’s possible to alternate beacons, but this needs to be done by your squirrel app. Not exactly very hard.

Advertising data is totally up to you, so you can use any format you want.


#8

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.


#9

Ready to get going with this. :smiley:

How long before the API is available?


#10

It’s all up on the dev center now. if you want to try it, PM me a mac address.


#11

Hi @smittytone,

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;
    }
  }
]
  }
]);`

#12

What app are you using?

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?


#13

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… .


#14

I found an Android app that works: “nRF Connect”

Apps that don’t work for me:
“Bluetooth LE Scanner”
“Ble Term”
“BLE Terminal Free”
“BLE Tool”
“BLE Scanner”
“LightBlue”

Maybe the connection is timing out with the other apps?


#15

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…


#16

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


#17

From what I know, LightBlue app should be only used on IOS and not on Android even though also available in Play Store.

nRF Connect or BLE Scanner by Bluepixel Technologies would be the go-to apps for Android.


#18

Good tip, @Gerrikoio - thanks. I’ll try nRF Connect.


#19

@smittytone It’s for a commercial product. So if I am going to have issues with Android not playing nice then I might as well stop right now.


#20

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.