If you are asking a question, please follow this template:
- My goal is: [describe your goal] I am trying to get notifications from a device. I am certain that the device is sending notifications upon subscription. Here is a link to video of it working with nRF. http://pinatabot5000.xyz/Notifications.mov
- My actions are: [describe your actions - code, commands, etc] Using the helpful example in mongoose-os-apps I have copied and pasted till I get the charectaristic and try to set the notifications.
load('api_config.js');
load('api_events.js');
load('api_gpio.js');
load('api_timer.js');
load('api_sys.js');
load('api_mqtt.js');
load('api_bt_gap.js');
load('api_bt_gattc.js');
let conn = null;
let btn = Cfg.get('board.btn1.pin'); // Built-in button GPIO
let wi = 0, wh = 0;
if (btn >= 0) {
let btnCount = 0;
let btnPull, btnEdge;
if (Cfg.get('board.btn1.pull_up') ? GPIO.PULL_UP : GPIO.PULL_DOWN) {
btnPull = GPIO.PULL_UP;
btnEdge = GPIO.INT_EDGE_NEG;
} else {
btnPull = GPIO.PULL_DOWN;
btnEdge = GPIO.INT_EDGE_POS;
}
GPIO.set_button_handler(btn, btnPull, btnEdge, 20, function() {
if (conn === null) {
bob = [];
if (!jim) print("no jim");
print('Connecting to', jim);
GATTC.connect(jim);
}
else {
disconnect();
}
}, null);
}
let bob = [];
let jim = "";
let ntf = false;
Event.on(GAP.EV_SCAN_RESULT, function(ev, evdata) {
let sr = GAP.getScanResultArg(evdata);
let name = GAP.parseName(sr.advData) || "No name jackson";
let adv = sr.advData;
let hala = "\xff2\v";
// print('ev scan result', JSON.stringify(sr), name); //noise
// print('ev scan result', sr.advData, name); //noise
if ((adv.indexOf(hala) >0) && (JSON.stringify(bob).indexOf(sr.addr) === -1)) {
print('***vvv genuine hala device over here vvv***');
print('sr', JSON.stringify(sr));
print("addr?", JSON.stringify(sr.addr));
let adr = JSON.stringify(sr.addr);
jim = sr.addr
bob.push(adr);
let tof = ffi('double tof(int, int, int, int)');
let tmp = tof(sr.advData.at(11), sr.advData.at(12), sr.advData.at(13), sr.advData.at(14));
print('Calling C tof:', tmp);
// sending to AWS is working...
let fml = JSON.stringify({ mac: sr.addr, temp: tmp});
let res = MQTT.pub('tangerine/temp', fml, 1);
print('send it: ', res ? 'yes' : 'no', res)
}
}, null);
function discover() {
if (!conn) return;
print('Enumerating characteristics on', conn.addr, conn.connId);
GATTC.discover(conn.connId);
}
function disconnect() {
if (!conn) return;
print('Disconnecting from', JSON.stringify(conn));
GATTC.disconnect(conn.connId);
}
Event.on(GAP.EV_SCAN_STOP, function(ev, evdata) {
print('...stopped');
// if (!jim) return;
// print('Connecting to', jim);
// GATTC.connect(jim);
}, null);
Event.on(GATTC.EV_CONNECT, function(ev, evdata) {
print('connected!')
conn = GATTC.getConnectArg(evdata);
discover();
// Timer.set(5000, 0, disconnect, null);
}, null);
Event.on(GATTC.EV_DISCOVERY_RESULT, function(ev, evdata) {
print('discovered!')
let dr = GATTC.getDiscoveryResultArg(evdata);
print('Found', JSON.stringify(dr));
if (dr.chr === 'a6ed0202-d344-460a-8075-b9e8ec90d71b') {
GATTC.read(dr.conn.connId, dr.handle);
// GATTC.setNotifyModeCCCD(conn.connId, dr.handle + 1, GATTC.NOTIFY_MODE_NOTIFY);
let set = GATTC.setNotifyModeCCCD(dr.conn.connId, dr.handle+1, GATTC.NOTIFY_MODE_NOTIFY);
print('setting notifier', dr.conn.connId, dr.handle+1, GATTC.NOTIFY_MODE_NOTIFY);
GATTC.read(dr.conn.connId, dr.handle+1);
print('set??', set)
let adr = GATTC.getDiscoveryResultArg(evdata);
print('xxxxx', JSON.stringify(adr));
}
// else if ((dr.chr === 'a6ed0203-d344-460a-8075-b9e8ec90d71b') && (ntf === true)) {
// GATTC.read(dr.conn.connId, dr.handle);
// print('writing?', conn.connId, dr.handle, "data", true);
// GATTC.write(conn.connId, dr.handle, "data", true);
// }
}, null);
Event.on(GATTC.EV_READ_RESULT, function(ev, evdata) {
let rd = GATTC.getReadResult(evdata);
print('/////Read data:', rd.handle, rd.ok, rd.data);
}, null);
Event.on(GATTC.EV_WRITE_RESULT, function(ev, evdata) {
let rd = GATTC.getWriteResult(evdata);
print('Write result:', rd.handle, rd.ok);
print('the write was okay???')
}, null);
Event.on(GATTC.EV_NOTIFY, function(ev, evdata) {
let na = GATTC.getNotifyArg(evdata);
if (na.isIndication) {
print('\\\\Indication:', na.handle, na.data);
} else {
print('\\\\Notification:', na.handle, na.data);
}
}, null);
Event.on(GATTC.EV_NOTIFY, function(ev, evdata) {
let na = GATTC.getNotifyArg(evdata);
print('\\\\Got notification:', na.data);
}, null);
Event.on(GATTC.EV_DISCONNECT, function(ev, evdata) {
let c = GATTC.getConnectArg(evdata);
print('Disconnected from', JSON.stringify(c));
wi = wh = 0;
conn = null;
}, null);
Timer.set(5000, Timer.REPEAT, function() {
if (conn === null) {
bob = [];
print('starting scan...', JSON.stringify(bob))
GAP.scan(2000, false);
}
else {
print("idle...");
}
}, null);
- The result I see is: [show the result - log, etc]
...
[May 6 16:42:36.280] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"180a","chr":"2a29","handle":26,"prop":0}
[May 6 16:42:36.293] discovered!
[May 6 16:42:36.302] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"180a","chr":"2a2a","handle":28,"prop":0}
[May 6 16:42:36.316] discovered!
[May 6 16:42:36.325] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"180a","chr":"2a50","handle":30,"prop":0}
[May 6 16:42:36.338] discovered!
[May 6 16:42:36.351] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"a6ed0201-d344-460a-8075-b9e8ec90d71b","chr":"a6ed0202-d344-460a-8075-b9e8ec90d71b","handle":33,"prop":0}
[May 6 16:42:36.379] setting notifier 0 34 1
[May 6 16:42:36.383] set?? true
[May 6 16:42:36.396] xxxxx {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"a6ed0201-d344-460a-8075-b9e8ec90d71b","chr":"a6ed0202-d344-460a-8075-b9e8ec90d71b","handle":33,"prop":0}
[May 6 16:42:36.413] discovered!
[May 6 16:42:36.421] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"a6ed0201-d344-460a-8075-b9e8ec90d71b","chr":"a6ed0203-d344-460a-8075-b9e8ec90d71b","handle":36,"prop":0}
[May 6 16:42:36.439] discovered!
[May 6 16:42:36.447] Found {"conn":{"addr":"ea:cb:3e:cf:00:0f,1","connId":0,"mtu":60},"svc":"a6ed0201-d344-460a-8075-b9e8ec90d71b","chr":"a6ed0204-d344-460a-8075-b9e8ec90d71b","handle":38,"prop":0}
[May 6 16:42:36.469] /////Read data: 33 false
[May 6 16:42:36.474] /////Read data: 34 true \x00\x00
[May 6 16:42:39.265] idle...
...
- My expectation & question is: [describe your expectation and your question] The example has the handle +1 I have tried with and without adding one to this. I have tried notifications and indications. I have tried staying connected and disconectiong. Any thoughts would be helpful. But I think I should be getting the notifications from the peripheral with what I have??? Thanks