-
Hi @Gordon,
i bought Puck-js while they are BLE 5 ready but now i see it's still on BLE 4.2. 3 years ago scince your last post. Is there any Change?
-
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});
@Gordon yes that off course fixed the issue i have ;-). I've changed my code over the day it works like aspactad.
Now i have two new problems. First of all, after starting and stopping, i can't connect to the Puck-js scince i'm pull out the battery and plug it in again.
~~The second problem is the advertising interval. If i change the interval to somthing under 100ms i don't reseive any packages from the device. ~~
[Edit] Answere for the second Question:
NOTE: Non-connectable advertising can't have an advertising interval less than 100ms according to the BLE spec.