-
Your new firmware exhibits broadly the same behaviour. It disconnects after just under a second (about 0.93 seconds now, but I'm not sure if that's because of the new firmware or because I was messing with
NRF.setConnectionInterval()
earlier).I let it try over 100 times and it didn't work even once.
-
Thanks @fanoush I will give that a go.
For now I have found the most success by writing the sensor values into the "manufacturer data" field, and using
NRF.findDevices
to discover the manufacturer data. Since I only need one-way communication this will probably be good enough for me, but I'll give the firmware a try as it would obviously be better if it worked properly. -
Thanks for the suggestion. I tried
NRF.setConnectionInterval(50)
on both the Bangle.js 1 and 2 and it didn't make any obvious improvement.I have had some success in making the ESP32 connect to the Bangle.js and draw the sensor readings on the screen. This seems more reliable than the other way around, but still quite unreliable. It does seem to work well once it's connected, but getting it connected can take a minute or 2. And again it's much worse on Bangle.js 2 than on the original Bangle.js, I haven't got it to work at all with the Bangle.js 2.
-
Aha,
service.startNotifications()
was helpful, thanks.Sadly I've already built the device that has an ESP32-C3 potted inside it so it's inconvenient to change. Since it was working with
gatttool
I assumed it wouldn't be too much trouble to use it with a Bangle.js.I wrote a Bangle.js program that keeps retrying to connect until it works, but sometimes it takes several minutes to get a working connection even with the original Bangle.js (and it has still not worked even once on the Bangle.js 2). But it does work once it's connected.
I'm thinking of inverting the "client" and "server" to see if that works any better. I.e. make the ESP32 connect to the Bangle.js and send readings that way instead. Slightly inconvenient that you can't use the Web IDE console while something else is connected to the Bangle.js though.
-
OK, some progress on the original Bangle.js. It very rarely works (maybe 1 in 30 times), but I have observed it working and successfully reading out data from the characteristic:
NRF.connect("34:85:18:00:38:8e").then(function(gatt) { console.log(gatt); console.log("connected"); var t = getTime(); gatt.device.on('gattserverdisconnected', function(reason) { console.log("disconnected (" + reason + ") after " + (getTime()-t) + " secs"); }); return gatt.getPrimaryService("4fafc201-1fb5-459e-8fcc-c5c9c331914b"); }).then(function(service) { console.log("got service: "); console.log(service); return service.getCharacteristic("beb5483e-36e1-4688-b7f5-ea07361b26a8"); }).then(function(characteristic) { console.log("got characteristic, value = "); characteristic.readValue().then(function(v) { console.log(v); }); characteristic.on('characteristicvaluechanged', function() { console.log("characteristicvaluechanged: "); characteristic.readValue().then(function(v) { console.log(v); }); }); }).catch(function(e) { console.log("error: " + e); });
gives:
BluetoothRemoteGATTServer: { "device": BluetoothDevice: { "id": "34:85:18:00:38:8e", "gatt": ... }, "connected": true } connected got service: BluetoothRemoteGATTService: { "uuid": "4fafc201-1fb5-459e-8fcc-c5c9c331914b", "isPrimary": true, "start_handle": 40, "end_handle": 65535 } got characteristic, value = DataView: { "buffer": new Uint8Array([4, 0, 0, 0]).buffer, "byteOffset": 0, "byteLength": 4 }
However you'll notice that the "characteristicvaluechanged" callback is not firing. I left it running for several minutes and it didn't fire even once, so I think the "notify" response is not working. But this is progress, at least, and in the worst case I can probably read out the characteristic value on a timer, so there is light at the end of the tunnel!
It would still be better if it worked on Bangle.js 2, and if it worked every time instead of only 1/30 times.
(The MAC address is different because I'm using a different ESP32C3, but that's just an accident - it still doesn't work on the Bangle.js 2).
-
I don't have any ESP32 that's not a C3, so I'd have to wait for one to arrive. Can you suggest what I should buy?
I am now finding that it doesn't work at all even on the original Bangle.js. In fact in total I think it only worked once, and it's not obvious to me whether it actually worked, or just didn't notice that it didn't work.
I know it says "connected", but it's not obvious to me that that callback runs after it actually connected, compared to when it merely thinks it was connected. The "connection failed to be established" error suggests it was never connected in the first place.
-
-
I didn't know about the "core debug level" option. I just tried it with Verbose, and I see a bunch of stuff at startup, and a bunch of stuff when I connect using gatttool, but indeed nothing at all when the Bangle.js 2 tries to connect.
So are we saying that the Bangle.js 2 is just (sometimes, in your case, and always, in my case) not sending the connection request?
I wonder if I could try connecting it to some other type of device to see if that works, I'll try to think of something. Obviously Web Bluetooth works for the IDE so it's not like Bluetooth is completely non-functional.
-
Thanks for taking a look! It's encouraging that you can reproduce the problem, although I'm not sure why it's intermittent. I tried it using your exact code and it disconnects after ~1.0 seconds, exactly the same for me every single time. I'm running the 2v18 firmware on the watch. I tried both with "upload to ram" and pasting into the console.
My Arduino is also an ESP32-C3 FWIW, it's a Xiao from "seeed studio".
-
It's not intended to be a stress test, it's just something I'm adapting to transmit sensor readings over Bluetooth. More frequent is better, but it doesn't need to be that frequent.
Sadly no luck with your suggestion. I tried changing the
delay(10)
todelay(1000)
but it still behaves the same: the Bangle.js 2 disconnects with reason 62 after almost exactly 1 second. -
I'm trying to use my Bangle.js 2 to connect to a Bluetooth service running on an ESP32.
This is the Arduino code running on the ESP32: https://gist.github.com/jes/65832156dc0eded2b167c3c1da184cde - it creates a single characteristic that repeatedly writes "hello\0" and notifies. It is based on an example program I copied.
This is the Espruino code running on the Bangle.js 2: https://gist.github.com/jes/36b8ea811706ee1db4ceab6e37ab8af2 - it connects to the Bluetooth device and tells me how long it took to disconnect, it's always about 1.0 seconds.
This is the output I get on the Web IDE console: https://gist.github.com/jes/731b57ce4c62ba8fcb451858f7dfa024 - reason 62 is
BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED
.And this is a session using
gatttool
, just to show that the Arduino code actually does work: https://gist.github.com/jes/34b7dd8fb1ec4737bb3950ce7f649dd6I'm using the "upload to RAM" method in the Web IDE, but the behaviour seems to be the same even if I write the code to disk, disconnect from Web Bluetooth, and send output to the LCD instead of the console.
If instead of just connecting to the Bluetooth device, I actually try to get a service, then I get an additional error:
Uncaught InternalError: BLE task completed that wasn't scheduled (SERVICE/NONE)
From what I've been able to find on this forum, the most likely cause for this is that the device I'm trying to connect to is simply ignoring the connection attempt. I have tried varying the
minInterval
andmaxInterval
options, and it seems as though the disconnection always comes after 5xmaxInterval
, regardless of what I set it to.Can anyone see anything wrong in either my Arduino code or Espruino code that would cause the problem? Or otherwise suggest what I might be doing wrong? The 2 devices are within 20 centimetres on my desk, the Espruino-reported rssi is very good (about -40) and the problem happens every single time, not intermittently, do I don't think it's a signal strength problem.
Thanks.
I tried putting
BLEDevice::setMTU(131)
(and also 23) just before and just afterBLEDevice::startAdvertising()
in my Arduino code from the first post in this thread. No change, the Bangle.js 2 still says it was disconnected after ~1.0 seconds.My immediate problem is solved anyway, because I can just report my sensor readings in the "manufacturer data" field, and grab it with
NRF.findDevices()
.