Using the DeviceOS built-in BLE service for setup

I am trying to utilize the BLE service that DeviceOS advertises in listening mode to help do the initial device provisioning. Essentially I want to create similar functionality to the mobile app for setup, but I want to use BLE for web instead of a mobile app.

Digging around, it appears that the communication is done via writing commands to a write characteristic and receiving responses from a notify characteristic. I have verified I can do both from Javascript in the browser.

My hang-up appears to be in the format of the data I am sending to the device, I am getting no responses from the device at all.

From what I can tell, the format used is protobuf to both send and receive data. I figured I would start with a very basic command to confirm my code was correct so I selected the SystemResetRequest as it takes no arguments and I would notice the device rebooting on success. Below is the js script to write the data to the device.

        const OSwriteUuid = "6fa90004-5c4e-48a8-94f4-8030546f36fc";

	protobuf.load("control/config.proto", function(err, root) {
		if (err)
			throw err;
		// Obtain a message type
		var AwesomeMessage = root.lookupType("SystemResetRequest");

		// Exemplary payload
		var payload = {option: {"(type_id)": 40}};

		// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
		var errMsg = AwesomeMessage.verify(payload);
		if (errMsg)
			throw Error(errMsg);

		// Create a new message
		var message = AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
		//var jmessage = AwesomeMessage.fromObject(payload);

		// Encode a message to an Uint8Array (browser) or Buffer (node)
		var buffer = AwesomeMessage.encode(message).finish();
		// ... do something with buffer

		const writetoOSble = await this.service.getCharacteristic(OSwriteUuid);
		// Decode an Uint8Array (browser) or Buffer (node) to a message
		//var message = AwesomeMessage.decode(buffer);
		// ... do something with message
		// If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
		// Maybe convert the message back to a plain object
		//var object = AwesomeMessage.toObject(message, {
		//	longs: String,
		//	enums: String,
		//	bytes: String,
			// see ConversionOptions

using protobuf.js from here:

and the proto files from here:

When I look at the log information, I think the issue is in the encode function. The Uint8Array seems to have a size of 0 no matter what I put into the payload. Any advice or help is greatly appreciated.

You are heading in the right direction, but there’s an entire protocol that sits on top of the BLE connection. It’s authenticated and encrypted using EC-J/PAKE encryption.

It’s not impossible to figure out, since both the mobile app code and the device code are open source, but it’s complicated and confusing. Also hard to debug because it’s encrypted.

If you can wait a little longer, we’ll have a BLE configuration example app in React Native, as well as some code that could help build a native mobile or browser-based version.

Awesome, and thank you for the quick response.

For now, I created my own BLE service to handle what I need to do, but ultimately we want to migrate to the built in service.

Any idea on a rough timeframe for the initial release of the examples?

1 Like

I wanted to check in again on this to see if there are any updates or a timeframe to when we might be able to expect some BLE configuration examples?

There isn’t a timeframe for the BLE setup example yet.

Is there any documentation at all available now that describes the protocol that sits on the BLE connection and the authentication/encryption. I tried looking through the source code and it wasn’t obvious to me from that alone.

There is no documentation. It’s not a secret as you can reverse engineer it from the open-source mobile apps, but it’s really tricky. Implementing the EC-J/PAKE algorithm is tricky (hint: none of the open-source Javascript libraries implement it in the same way as the devices and mobile apps and won’t work), and doing the protobufs over BLE requires a little effort.

The examples will be released publicly, but I don’t have a schedule for doing so.