Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
}, 180000);
bleno.on('stateChange', function(state) {
console.log('BLE stateChange: ' + state);
if (state === 'poweredOn') {
poweredOn = true;
} else {
console.log('BLE advertising stopped');
poweredOn = false;
advertisingToggle = false;
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
if (!error) {
bleno.setServices([
new bleno.PrimaryService({
uuid: 'F1D46062-7FD3-4C17-B096-9E8D61E15583',
characteristics: [
// Read device resin-UUID
new bleno.Characteristic({
uuid: 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF1',
properties: ['read'],
descriptors: [
new bleno.Descriptor({
uuid: '2901',
value: 'Read device resin-UUID'
})
],
onReadRequest: function(offset, callback) {
//
// We will also advertise the service ID in the advertising packet,
// so it's easier to find.
//
bleno.startAdvertising(name, [pizzaService.uuid], function(err) {
if (err) {
console.log(err);
}
});
}
else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(err) {
if (!err) {
console.log('advertising...');
//
// Once we are advertising, it's time to set up our services,
// along with our characteristics.
//
bleno.setServices([
pizzaService
]);
}
});
// console.log('check bluetooth')
// console.log(execSync('dmesg |grep -i Bluetooth').toString())
console.log('Bleno starting...')
util.inherits(wifiConfService, BlenoPrimaryService)
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state + ', address = ' + bleno.address)
if (state === 'poweredOn') {
bleno.startAdvertising(config.name, [ UUID.SERVICE_ID ])
} else {
bleno.stopAdvertising()
}
})
// Linux only events /////////////////
bleno.on('accept', function(clientAddress) {
console.log('on -> accept, client: ' + clientAddress)
bleno.updateRssi()
})
bleno.on('disconnect', function(clientAddress) {
console.log('on -> disconnect, client: ' + clientAddress)
})
bleno.on('rssiUpdate', function(rssi) {
console.log('on -> rssiUpdate: ' + rssi)
})
//////////////////////////////////////
bleno.on('mtuChange', function(mtu) {
console.log('on -> mtuChange: ' + mtu)
})
bleno.on('advertisingStart', function(error) {
debug('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
//if (advertisingState = GATT_ADV_STATE) {
debug("Advertising Services");
bleno.setServices([
uartService
]);
//}
}
});
bleno.on('accept', function(clientAddress) {
info('onConnect from: ' + clientAddress);
flipFlopEnabled = false;
});
bleno.on('disconnect', function(clientAddress) {
info('onDisconnect from: ' + clientAddress);
flipFlopEnabled = true;
});
// ---------------------------------------------------------------------------------------------------------
// Notes
/*
});
client.on('message',function(topic, message){
console.log(message.toString());
topicCharacteristic.update(message);
});
bleno.on('stateChange', function(state){
if (state === 'poweredOn') {
bleno.startAdvertising('mqtt', ['ba42561bb1d2440a8d040cefb43faece']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error){
if(!error) {
bleno.setServices([
new BlenoPrimarySerivce({
uuid: 'ba42561bb1d2440a8d040cefb43faece',
characteristics: [
topicCharacteristic
]
})
]);
}
});
var bleno = require('bleno'),
BatteryService = require('./battery-service');
var primaryService = new BatteryService();
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('Battery', [primaryService.uuid]);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
bleno.setServices([primaryService]);
}
});
var EchoCharacteristic = require('./characteristic');
console.log('bleno - echo');
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('echo', ['ec00']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
bleno.setServices([
new BlenoPrimaryService({
uuid: 'ec00',
characteristics: [
new EchoCharacteristic()
]
})
]);
}
});
}
var client = mqtt.connect(config.broker);
var topicCharacteristic = new TopicCharacteristic(config);
client.on('connect', function(){
client.subscribe(config.topic);
});
client.on('message',function(topic, message){
console.log(message.toString());
topicCharacteristic.update(message);
});
bleno.on('stateChange', function(state){
if (state === 'poweredOn') {
bleno.startAdvertising('mqtt', ['ba42561bb1d2440a8d040cefb43faece']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error){
if(!error) {
bleno.setServices([
new BlenoPrimarySerivce({
uuid: 'ba42561bb1d2440a8d040cefb43faece',
characteristics: [
topicCharacteristic
]
})
const args = argv.option([{
name: 'hwid',
description: '[REQUIRED] 10 digits of hexadecimal number. ',
type: 'string',
example: "'--hwid=c0d10ad7f8'"
}, {
name: 'device-message',
description: '[OPTIONAL] 2 .. 26 digits of hexadecimal number.',
type: 'string',
example: "'--device-message=ff'"
}]).run();
const HWID = args.options['hwid'];
const DEVICE_MESSAGE = args.options['device-message'] || '00';
bleno.on('stateChange', function (state) {
console.log('stateChange: ' + state);
if (state === 'poweredOn') {
const data = simplebacon.createLineSimpleBeaconAdvertisingPDU(HWID, DEVICE_MESSAGE);
console.log(data);
bleno.startAdvertisingWithEIRData(data);
} else {
bleno.stopAdvertising();
}
});
console.error("BLE script failed isOnline check");
} else {
if (!online && !advertisingToggle && poweredOn) {
console.log('BLE advertising started');
advertisingToggle = true;
bleno.startAdvertising("resin-" + process.env.RESIN_DEVICE_UUID.substr(0, 7), ['F1D46062-7FD3-4C17-B096-9E8D61E15583']);
} else if (online && advertisingToggle && poweredOn) {
bleno.stopAdvertising();
console.warn('BLE advertising stopped');
advertisingToggle = false;
}
}
});
}, 180000);
bleno.on('stateChange', function(state) {
console.log('BLE stateChange: ' + state);
if (state === 'poweredOn') {
poweredOn = true;
} else {
console.log('BLE advertising stopped');
poweredOn = false;
advertisingToggle = false;
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
if (!error) {
bleno.setServices([
new bleno.PrimaryService({
uuid: 'F1D46062-7FD3-4C17-B096-9E8D61E15583',