I have revisited this and think for my requirement I would want to work it after device is paired with phone, otherwise device will read advert from all buttons. While looking I came across NRF.setServices() which sends data only when device is paired. I hope it work like below [see Js code below for Puck]. I now hope I'll find code which will read this service data in android code. Can you suggest your views on this?
var C = {
set : "SET",
update : "UPDATE",
every_30_sec : 3000
};
var iCounter = 0;
function publishTemp(cmd) {
//digitalPulse(LED2, 1, 200);
if (cmd == C.set)
NRF.setServices({
0x1809 : { // Health Thermometer
0x2A6E: {
readable: true,
broadcast: true,
value : iCounter
}}});
if (cmd == C.update)
NRF.updateServices({
0x1809 : { // Health Thermometer
0x2A6E: {
readable: true,
broadcast: true,
value : iCounter
}}});
}
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.
Hi Gordon,
I have revisited this and think for my requirement I would want to work it after device is paired with phone, otherwise device will read advert from all buttons. While looking I came across NRF.setServices() which sends data only when device is paired. I hope it work like below [see Js code below for Puck]. I now hope I'll find code which will read this service data in android code. Can you suggest your views on this?
var C = {
set : "SET",
update : "UPDATE",
every_30_sec : 3000
};
var iCounter = 0;
function publishTemp(cmd) {
//digitalPulse(LED2, 1, 200);
if (cmd == C.set)
NRF.setServices({
0x1809 : { // Health Thermometer
0x2A6E: {
readable: true,
broadcast: true,
value : iCounter
}}});
if (cmd == C.update)
NRF.updateServices({
0x1809 : { // Health Thermometer
0x2A6E: {
readable: true,
broadcast: true,
value : iCounter
}}});
}
setWatch(function(e)
{
iCounter++;
print(iCounter);
}, BTN, {repeat:true,edge:"rising",debounce:50});
// first time
publishTemp(C.set);
// every 30 sec
setInterval(publishTemp,C.every_30_sec,C.update);
Regards