Hi,
I have a problem with my BLE application on BalenaOS.
The device name in “BLENO_DEVICE_NAME” environment variable is ignored and it sets the UUID string instead.
Also I can’t see the characteristic that I’ve defined in the code.
The exact same code is working on the same PC with Ubuntu 18.04.
You can see the attached picture and test program for the BLE below.
Any idea why?
Thanks.
Code:
var util = require('util');
var bleno = require('@abandonware/bleno');
var BlenoPrimaryService = bleno.PrimaryService;
var Descriptor = bleno.Descriptor;
var Characteristic = bleno.Characteristic;
class BLE {
constructor() {
var self = this;
this._allowStartAd = false;
this._testInfo = { "Info": "Test", "A": "B"};
this.TestCharacteristic = function () {
self.TestCharacteristic.super_.call(this, {
uuid: '2c7183e0-2cac-4bc8-8bc4-ef4851db51d9',
properties: ['read'],
descriptors: [
new Descriptor({
uuid: '2901',
value: 'My Test Characteristic'
}),
new Descriptor({
uuid: '2904',
value: new Buffer.from([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00])
})
]
});
};
util.inherits(this.TestCharacteristic, Characteristic);
this.TestCharacteristic.prototype.onReadRequest = function (offset, callback) {
console.log(`BLE Info request`);
callback(this.RESULT_SUCCESS, Buffer.from(JSON.stringify(self._testInfo), 'utf8'));
};
this.TestService = function() {
self.TestService.super_.call(this, {
uuid: 'e892c45c-f5f7-4882-96e8-3a2ff792c29c',
characteristics: [
new self.TestCharacteristic()
]
});
}
util.inherits(this.TestService, BlenoPrimaryService);
this._primaryService = new this.TestService();
bleno.on('stateChange', function (state) {
console.log("BLE state: " + state);
if (state === 'poweredOn') {
console.log("BLE ON!");
self._allowStartAd = true;
} else {
self._allowStartAd = false;
}
});
bleno.on('advertisingStart', function (error) {
if (!error) {
bleno.setServices([self._primaryService], function (error) {
console.log('setServices: ' + (error ? 'error ' + error : 'success'));
});
} else {
console.error(error);
}
});
}
Start(deviceName) {
if (this._allowStartAd) {
console.log(`Device name: ${deviceName}`);
process.env['BLENO_DEVICE_NAME'] = deviceName;
bleno.startAdvertising(deviceName, [this._primaryService.uuid]);
}
}
Stop() {
bleno.stopAdvertising();
bleno.disconnect();
}
}
async function main() {
const ble = new BLE();
setTimeout(function() {
ble.Start("Test-BLE");
}, 3000);
}
main();
Docker file:
FROM balenalib/genericx86-64-ext-ubuntu-node:12-build AS build
COPY package.json package.json
RUN JOBS=MAX npm install --production --unsafe-perm && npm cache verify && rm -rf /tmp/
FROM balenalib/genericx86-64-ext-ubuntu-node:12-run
RUN apt-get clean && apt-get -q update && apt-get install -yq --no-install-recommends ffmpeg
#RUN apt-get --assume-yes install net-tools
RUN apt-get --assume-yes install bluetooth bluez libbluetooth-dev libudev-dev libusb-1.0-0-dev
RUN apt-get --assume-yes install network-manager v4l-utils
WORKDIR /app
COPY --from=build ./node_modules ./node_modules
COPY ./*.js ./
COPY ./package.json ./package.json
#COPY ./start.sh ./start.sh
#ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
ENV UDEV=1
ENTRYPOINT ["node", "test.js"]
docker-compose.yml
version: '2.1'
volumes:
resin-data:
services:
server:
container_name: server
build: ./simple-ble
network_mode: 'host'
privileged: true
volumes:
- 'resin-data:/data'
- 'resin-data:/config'
labels:
io.balena.features.kernel-modules: '1'
io.balena.features.firmware: '1'
io.balena.features.dbus: '1'
io.balena.features.sysfs: '1'
io.balena.features.procfs: '1'
io.balena.features.supervisor-api: "1"