Is it possible to scan and advertise at the same time? I would like to do a setup with 3 beacon. Each beacon should scan for the other two beacons and save the current rssi. In the next Advertising package the beacon should send the last received rssi from the other two beacons. I'm new on programming with JavaScript. My current Codebase shows this:
const be = {
name: "BLE-Beacon B", // The name of the device
showName: true, // include full name, or nothing
discoverable: true, // general discoverable, or limited - default is limited
connectable: true, // whether device is connectable - default is true
scannable : false, // whether device can be scanned for scan response packets - default is true
interval: 300, // Advertising interval in msec, between 20 and 10000 (default is 375ms)
manufacturer: 0x0590, // IF sending manufacturer data, this is the manufacturer ID
};
var deviceA = 0;
var deviceB = 0;
var deviceC = 0;
// Start scanning
started = true;
logging = true;
// scanning for the devices
function scanDevice(d) {
let modified = false;
// witch device is scanned
// change the value
switch (d.name) {
case "BLE-Beacon A":
modified = (deviceA !== d.rssi);
deviceA = d.rssi;
break;
case "BLE-Beacon B":
modified = (deviceB !== d.rssi);
deviceB = d.rssi;
break;
case "BLE-Beacon C":
modified = (deviceC !== d.rssi);
deviceC = d.rssi;
break;
}
// if value was modified setAdvertising to new Value
if(modified){
NRF.setAdvertising({
0x180F: [deviceA]
}, {
name: be.name,
manufacturer: be.manufacturer,
interval: be.interval,
manufacturerData: ["A", deviceA, "B", deviceB, "C", deviceC]
});
} else {
console.log("nothing modified");
}
}
// Initiales Scanning
NRF.setScan(scanDevice, {filters: [{namePrefix:"BLE-Locate"}] });
// Initiales Advertising
NRF.setAdvertising({}, {
name: be.name,
manufacturer: be.manufacturer,
interval: be.interval,
manufacturerData: ["A", deviceA, "B", deviceB, "C", deviceC]
});
// Watch if BTN was pressed
setWatch(function(){
console. log("Device: " + be.name);
if (started) {
NRF.setScan();
started = false;
console.log("Stop Scanning");
} else {
NRF.setScan(scanDevice, {filters: [{namePrefix:"BLE-Locate"}] });
started = true;
console.log("Start Scanning");
}
}, BTN, {edge:"rising", repeat:1, debounce:20});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Is it possible to scan and advertise at the same time? I would like to do a setup with 3 beacon. Each beacon should scan for the other two beacons and save the current rssi. In the next Advertising package the beacon should send the last received rssi from the other two beacons. I'm new on programming with JavaScript. My current Codebase shows this: