-
Thanks @Gordon. Beacons are by definition non-connectable advertisers, so no need for the .connect :-} Both Eddystone and iBeacon use Manufacturer Specific advertisements, with different Company ID's and, of course, define the advertising payload differently. There are several 'competing' for the beacon standards, but IMHO, iBeacon and Eddystone are the current front-runners by far. Eddystone allows several different types of beacons, ranging from URL to data. I'm using the UID format.
Note that beacons become quite a bit more powerful in Bluetooth 5 with enhanced and extended advertising. I'm hoping you'll be considering potential updates for that support in Nordic's updated Softdevices?
-
Thanks @Gordon -- yes, that will work just fine, but I was hoping for a bit more support. Certainly an 'enhancement request' if you decide to provide specific support for iBeacon and Eddystone scanning. What would be great would be:
NRF.requestDevice({ filters: [{ eddystoneNamepace: '1234567890' }] }).then(function(device) { ... });
Support for iBeacon might be something like:
NRF.requestDevice({ filters: [{ ibeaconUuid: 'B9407F30F5F8466EAFF925556B57FE6D' }] }).then(function(device) { ... });
-
Hi @Gordon- did you have a chance to try the example above? I'm curious if you (or others) repeat my issues and especially if there is a solution. Thanks!
Bill -
Hi @Gordon,
Tried your suggestions above to no avail. I have a nice test bench using two puck-js devices as follows: set up one using the LBS (LightButtonService) I published several months ago. Set up the other to find and set the LED. Here's the code; I've verified that the LBS is still working as advertised (pun intended).I get either no service found or an IDE disconnect, sometimes requiring I pull the battery to reset the (finder) device.
Let me know if you get the same/different results, THANKS!
LBS code:
NRF.setAdvertising({}, {name: "Nordic_Blinky"}); pinMode(D5, "output"); pinMode(D6, "output"); pinMode(D7, "output"); pinMode(D31, "output"); pinMode(D16, "input"); NRF.setServices({ "00001523-1212-EFDE-1523-785FEABCD123" : { "00001524-1212-EFDE-1523-785FEABCD123" : { // button value : 0x00, // optional broadcast : false, // optional, default is false readable : true, // optional, default is false writable : false, // optional, default is false notify : true, // optional, default is false indicate : false, // optional, default is false }, "00001525-1212-EFDE-1523-785FEABCD123" : { // LED value : 0x00, // optional broadcast : false, // optional, default is false readable : true, // optional, default is false writable : true, // optional, default is false notify : false, // optional, default is false indicate : false, // optional, default is false onWrite : function(evt) { digitalWrite([D5,D6,D31,D7], evt.data[0]); } } } }); setWatch(function() { NRF.updateServices({ "00001523-1212-EFDE-1523-785FEABCD123" : { "00001524-1212-EFDE-1523-785FEABCD123" : { value : 0x01, notify: true } } }); }, D16, {edge:"rising", debounce:50, repeat:true}); setWatch(function() { NRF.updateServices({ "00001523-1212-EFDE-1523-785FEABCD123" : { "00001524-1212-EFDE-1523-785FEABCD123" : { value : 0x00, notify: true } } }); }, D16, {edge:"falling", debounce:50, repeat:true});
Finder code:
var devices; NRF.findDevices(function(devices) { if (devices.length < 1) throw new Error("Nothing found!"); devices[0].gatt.connect().then(function(g) { gatt = g; return gatt.getPrimaryService("00001523-1212-EFDE-1523-785FEABCD123"); }).then(function(service) { return service.getCharacteristic("00001525-1212-EFDE-1523-785FEABCD123"); }).then(function(characteristic) { characteristic.writeValue( [0xff] ); }).then(function() { gatt.disconnect(); console.log("Done!"); }); }, 4000);
-
The IDE is running on MacOS, correct. The code I posted is exactly what I'm running on a completely reset and restored device (both with released and experimental Espruino). I'll try a different (128-bit) characteristic on another device, good suggestion, although LightBlue on both iOS and MacOS work just fine with it. I'll also try the more explicit representation you suggest.
The truly maddening thing is that I've actually seen it work twice, but can't repeat it with any predictability! Thanks @Gordon!
-
@zarconi No. That profile is on Bluetooth Classic. I doubt the 3G modem supports Bluetooth low energy which is the only thing the puck 'speaks'. It may/may not expose a modem serial port profile on Bluetooth Classic (also called BR/EDR).
-
@Gordon I'll look into the serial console connection. I have 14-18 devices within range, but went to a coffee shop where I was able to reduce that to 6 (too many fitness devices) and had similar results. The connection works just fine with an iOS, MacOS using LightBlue and my custom apps, so this is an issue I'm having solely with these espruino-based devices. I've had noble-based javascript application work using raspberry pi as well. Bottom line, it isn't a technology issue IMHO.
Any additional debugging thoughts from you (or the community) would be greatly appreciated. There are several reasons I'd like to get espruino working for this. THANKS!
-
@Gordon one thought: could there be an issue with the number of devices returning information (buffer overflows)? I have at least a dozen BLE devices in my environment. I'll try to find an isolated coffee shop (though lots of devices show up now) to test this theory, but thought I'd pass this on in case there is a way to increase resources.
-
Battery is 100%. I reloaded with 1v92 release and similar behavior: not finding the service sometimes, and sometimes hanging and dropping the IDE. I haven't caught the LED blinking, though sometimes I have to pull the battery to reset to get the IDE connected again. Is there a serial debugger operating that I can catch? Any other ideas?
-
@Gordon trying another method, by mac address. Also disconnects from IDE without changing the characteristic:
var gatt; NRF.connect("d4:df:0a:04:44:03").then(function(g) { gatt = g; return gatt.getPrimaryService("bbc21523-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(service) { return service.getCharacteristic("bbc21525-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(characteristic) { characteristic.writeValue(0xff); }).then(function() { gatt.disconnect(); console.log("Done!"); });
-
Oh @Gordon, forgot to add that I'm running 1v92.54 on the puck-js.
-
Hi @Gordon, I've picked this up again after another interruption. Here's the situation: I have a device with my own custom 128-bit service UUID and characteristics. It is a connectable iBeacon. I can connect easily with LightBlue (iOS) and view/change characteristics. I'm trying to connect to a service and change a characteristic that is an LED (00=off, ff=on). The code below has worked exactly twice, and fails a lot more. Failures are IDE disconnect, and "Uncaught Error: Unhandled promise rejection: No Services found". I can't reproduce when it passes, but it seems to be right after I've loaded a new revision of espruino (the first time). Very frustrating... Any ideas on how to debug what's happening? Code below (you helped me get this fixed last week or two), along with LightBlue screenshots.
var devices; NRF.findDevices(function(devices) { if (devices.length < 1) throw new Error("Nothing found!"); devices[0].gatt.connect().then(function(g) { gatt = g; return gatt.getPrimaryService("bbc21523-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(service) { return service.getCharacteristic("bbc21525-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(characteristic) { characteristic.writeValue(0xff); }).then(function() { gatt.disconnect(); console.log("Done!"); }); }, 3000);
-
I didn't try it out, but I sure can if you'd like.
I was reading through the commands and (erroneously) assumed anything with NRF on it was Bluetooth related, hence the confusion with Bluetooth battery values which are specified in the Battery Service as percentages (since there isn't known voltage and battery type). Sorry for my confusion, but perhaps a bit of clarification in the documentation would be good?
BTW, just got my Ruuvi units; nice to see another espruino-capable product! I'm actually running espruino on my own designed board as well. It makes for handy prototyping.
-
Thanks @Gordon. I guess I'm confused -- since it was an NRF function, I was assuming that it was the battery level of a remote connection, which over Bluetooth is expressed as percentage. Is this the battery voltage of the local system? In other words, an A/D reading from an input connected to the battery? If so, it would be good to document it a bit better to avoid future confusion. Thanks! Bill
-
@Gordon I'm reasonably certain that nRF.getBattery() returns percentage, not voltage as stated in Description and Returns in the API reference...
-
I've confused you @Gordon, sorry. Here's the scenario: I have my own peripheral device (eNote). It is a connectable beacon, advertising at the iBeacon maximum rate. I'm trying to scan and connect to it. I haven't yet tried it, but I believe that I can use the scan response BluetoothDevice "data" field to match its UUID and could then could connect to its "id", but I was trying scanning for its services first. I know this is unusual (connectable beacon), but there are certainly other devices like it on the market.
-
@Gordon - The Web IDE running in Chrome gave the 'disconnected' message, so that would depend on whether it has a timeout.
On the advertising issue: is there any way I can extend that window? I'd assumed that the timeout parameter was a scanning window, but ??
Thanks!!
-
Thanks @Gordon -- I don't think the crash was the oxff issue, it seems to have been related to the 0x prefix on the UUID's. I've actually now had the code work -- once only. It must have been in some sort of state from my trying other things, but I haven't repeated it. I'll spend some more time early next week and try to track it down better, as well as try other methods to reliably connect. The device is a connectable beacon, transmitting every 1.35 seconds, so I imagine I'm just not synching up. I'm trying extending the scan time, but so far it isn't working reliably.
-
-
Thanks @Gordon. It appears that the 0x prefix was causing the crash. I'm using 1v92.21.
Now I'm on to another issue; my device doesn't advertise services since it is a connectable iBeacon, so I'm going to have to find it using the beacon info, connect and then check for services (I believe), right?
-
Thanks @Wilberforce! The code now works (thanks for helping this NOOB), but now I'm into the second issue: it hangs and disconnects from the IDE...
-
So, then I tried the compact example shown below. There is a pause, then the WEB IDE shows "Disconnected". Note: I'm using 1v92.21.
var gatt; NRF.requestDevice({ timeout:2000, filters: [{ services: '0xbbc21523-008e-fe6b-28ee-d6a44f9cb5da' }]}).then( device => device.gatt.connect()).then( g => (gatt=g).getPrimaryService("0xbbc21523-008e-fe6b-28ee-d6a44f9cb5da")).then( service => service.getCharacteristic("0xbbc21525-008e-fe6b-28ee-d6a44f9cb5da")).then( characteristic => characteristic.writeValue(oxff)).then( () => { gatt.disconnect(); console.log("Done!"); } );
-
I'm using the code example from the Bluetooth LE page, modified for my device:
var devices; NRF.findDevices(function(d) { if (devices.length < 1) throw new Error("Nothing found!"); devices[0].gatt.connect().then(function(g) { gatt = g; return gatt.getPrimaryService("0xbbc21523-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(service) { return service.getCharacteristic("0xbbc21525-008e-fe6b-28ee-d6a44f9cb5da"); }).then(function(characteristic) { characteristic.writeValue( 0xff ); }).then(function() { gatt.disconnect(); console.log("Done!"); }); }, 2000); > =undefined Uncaught Error: Field or method "length" does not already exist, and can't create it on undefined at line 1 col 12 if (devices.length < 1) throw new Error("Nothing found!"); ^ in function called from system >
I'm getting an error above that I think is a simple coding error, but I copied it directly. My goof, or documentation error?
edited: never mind!! @Gordon - the first device in the list (with services: feaa) is the Eddystone UID beacon. Please ignore the rest of the blather and remind me to pull out my HP16 more often to convert decimal to hex...
Hi @Gordon -- Sorry, didn't mean to lecture, but I hadn't understood the question. So I tried looking for my Eddystone UID tag and couldn't see it with the following. Is espruino doing some sort of filtering on manufacturer specific data types?
Below is the output from this code with the puck.js positioned on top of the Eddystone UID beacon (should have RSSI ~ -25 or so). Attached is a screenshot from the nRF Connect app on iOS showing the beacon.