Actually I made the same mistake with the example code - using advertise instead of get. It should be:
var bUrl = "stackoverflow.com"; // Updated from Node-Red
function updateAdv() {
var data = [JSON.stringify(Puck.light().toFixed(3) * 1000), Math.round(E.getTemperature())];
console.log(data);
NRF.setAdvertising([
NRF.getAdvertisingData({},{manufacturer: 0x0590, manufacturerData:data}),
require("ble_eddystone").get(bUrl)
], {interval:100});
}
updateAdv();
setInterval(updateAdv, 5000);
I just tried this and it works for me. Your inability to connect is most likely because the interval was 1000ms - BLE broadcasts on 3 frequencies in turn, and it's also alternating advertising packets so a computer trying to connect is only seeing an advertising packet every 6 seconds - pretty much any connecting computer will time out connecting unless you're very lucky.
Hope that helps!
Just to add [JSON.stringify(Puck.light().toFixed(3) * 1000), Math.round(E.getTemperature())] is probably not what you want... It's creating a String of ascii characters with quotes around it, which is then being converted to a series of bytes (which could be variable length).
It's probably best to just pack it into a byte with: [Puck.light()*255, Math.round(E.getTemperature())] (the conversion to integer gets done automatically).
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.
NRF.setScanRespose
doesn't return anything, so what you're doing is effectively:Which is just:
Actually I made the same mistake with the example code - using
advertise
instead ofget
. It should be:I just tried this and it works for me. Your inability to connect is most likely because the
interval
was1000ms
- BLE broadcasts on 3 frequencies in turn, and it's also alternating advertising packets so a computer trying to connect is only seeing an advertising packet every 6 seconds - pretty much any connecting computer will time out connecting unless you're very lucky.Hope that helps!
Just to add
[JSON.stringify(Puck.light().toFixed(3) * 1000), Math.round(E.getTemperature())]
is probably not what you want... It's creating a String of ascii characters with quotes around it, which is then being converted to a series of bytes (which could be variable length).It's probably best to just pack it into a byte with:
[Puck.light()*255, Math.round(E.getTemperature())]
(the conversion to integer gets done automatically).