• Hi there! Just got my physical Bangle JS2 device today and have been tinkering, after using the emulator and the web IDE for about a week.

    I have been having a couple fishy issues with bluetooth, but this one particular issue has me scratching my head. I hope someone can offer some suggestions! Basically what happens is:

    1. I load up the web IDE, hit the connect button, and select my bangle from the list (it's there!)

    2. Once connected, I send a couple commands through the console on the left of the IDE (console.log, Bangle.beep, etc). Everything works fine.

    3. I take some benign code and put it in the right side: console.log("Hello world!");

    4. I hit UPLOAD (RAM). It looks like it is trying to do it, but then it says the Bangle has disconnected.

    5. Same thing happens if I hit the little Database icon (view storage). Here's what I am seeing in the developer console for the IDE

    Pre disconnect:

    >>> BLE configured. Receiving data...
    index.js:92945 Connected {portName: 'Bangle.js dbad'}
    index.js:92945 Received a prompt after sending newline... good!
    index.js:92945 >>> Sending...
    index.js:92945 ---> "\u0010print(\"<\",\"<<\",JSON.stringify­(process.env),\">>\",\">\")\n"
    index.js:92945 >>> Sent
    index.js:92945 BT> Received packet of length 128 - assuming increased MTU
    index.js:92945 >>> Receiving...
    index.js:92945 Got "< << {\"VERSION\":\"2v18\",\"GIT_COMMIT\":\"7­171b2832\",\"BOARD\":\"BANGLEJS2\",\"RAM­\":262144,\"FLASH\":1048576,\"SPIFLASH\"­:8388608,\"HWVERSION\":2,\"STORAGE\":838­8608,\"SERIAL\":\"366870f4-6dfecf14\",\"­CONSOLE\":\"Bluetooth\",\"MODULES\":\"Fl­ash,Storage,heatshrink,crypto,tensorflow­,locale\",\"EXPTR\":485764,\"APP_RAM_BAS­E\":536882880} >> >\r\n>"
    index.js:92945 >>> 
    index.js:92945 [notify_info] Found BANGLEJS2, 2v18
    index.js:92945 Loading https://www.espruino.com/json/BANGLEJS2.­json
    index.js:92945 Board JSON loaded
    blockly_espruino.js:114 Blockly.setBoardJSON  {VERSION: '2v18', GIT_COMMIT: '7171b2832', BOARD: 'BANGLEJS2', RAM: 262144, FLASH: 1048576, …}
    index.js:92945 Firmware >1.43 supports faster writes over USB
    index.js:92945 Set Slow Write = false ('Throttle Send'='Auto')
    index.js:92945 FIRMWARE: Current 2v18, Available 2v18
    index.js:92945 Device found {"portName":"Bangle.js dbad"}
    index.js:92945 [success] Connected to Bangle.js dbad
    index.js:92945 >>> Connected to Bangle.js dbad
    

    And then this additional content appears in the console after I hit "Send to Espruino (RAM)"

    >>> Minifying
    index.js:92945 >>> Minification complete
    index.js:92945 Found a prompt... great!
    index.js:92945 Splitting for reset(), delay 250
    index.js:92945 BT> SEND ERROR: NotSupportedError: GATT operation failed for unknown reason.
    index.js:92945 BT> Disconnected (gattserverdisconnected)
    index.js:92945 Disconnect callback... {"port":"Bangle.js dbad","portName":"Bangle.js dbad"}
    index.js:92950 [notify_warn] Disconnected from Bangle.js dbad
    (anonymous) @ index.js:92950
    warning @ index.js:94266
    (anonymous) @ index.js:100843
    (anonymous) @ index.js:95763
    cb @ index.js:92895
    (anonymous) @ index.js:131777
    cb @ index.js:92893
    (anonymous) @ index.js:130080
    cb @ index.js:92893
    (anonymous) @ index.js:101952
    cb @ index.js:92893
    (anonymous) @ index.js:100710
    cb @ index.js:92893
    (anonymous) @ index.js:100609
    cb @ index.js:92893
    (anonymous) @ index.js:98239
    cb @ index.js:92893
    (anonymous) @ index.js:94319
    cb @ index.js:92893
    callProcessor @ index.js:92898
    (anonymous) @ index.js:95762
    closeSerial @ index.js:96758
    btDevice.addEventListener.once @ index.js:96697
    closeSerial @ index.js:96751
    (anonymous) @ index.js:96782
    Promise.catch (async)
    writeSerial @ index.js:96780
    writeSerialWorker @ index.js:95899
    (anonymous) @ index.js:95902
    setTimeout (async)
    (anonymous) @ index.js:95901
    (anonymous) @ index.js:96779
    Promise.then (async)
    writeSerial @ index.js:96777
    writeSerialWorker @ index.js:95899
    writeSerial @ index.js:95921
    (anonymous) @ index.js:98706
    getEspruinoPrompt @ index.js:93244
    writeToEspruino @ index.js:98691
    cb @ index.js:92895
    (anonymous) @ index.js:130010
    cb @ index.js:92893
    wrap @ index.js:129922
    (anonymous) @ index.js:129914
    cb @ index.js:92893
    (anonymous) @ index.js:129682
    cb @ index.js:92893
    findBinary @ index.js:130846
    (anonymous) @ index.js:130782
    cb @ index.js:92893
    callback @ index.js:129621
    minify @ index.js:129642
    (anonymous) @ index.js:129489
    cb @ index.js:92893
    (anonymous) @ index.js:102993
    cb @ index.js:92893
    findASMBlocks @ index.js:102649
    (anonymous) @ index.js:102548
    cb @ index.js:92893
    compileCode @ index.js:102162
    (anonymous) @ index.js:102049
    cb @ index.js:92893
    loadModules @ index.js:99117
    (anonymous) @ index.js:98953
    cb @ index.js:92893
    callProcessor @ index.js:92898
    getEspruinoCode @ index.js:95472
    (anonymous) @ index.js:100593
    ensureConnected @ index.js:100852
    click @ index.js:100589
    index.js:92945 >>> Disconnected from Bangle.js dbad
    

    Any ideas of what I might be able to try?

  • I hit the post character limit, so here's a little more info about the board:

    VERSION	2v18
    GIT_COMMIT	7171b2832
    BOARD	BANGLEJS2
    RAM	262144
    FLASH	1048576
    SPIFLASH	8388608
    HWVERSION	2
    STORAGE	8388608
    SERIAL	366870f4-6dfecf14
    CONSOLE	Bluetooth
    MODULES	Flash,Storage,heatshrink,crypto,tensorfl­ow,locale
    EXPTR	485764
    APP_RAM_BASE	536882880
    

    And Bangle bluetooth settings:

    BLE: Checked
    Programmable: Checked
    HID: Off
    Passkey BETA: none
    Whitelist: on
    

    Code I'm trying to send to RAM:

    console.log("hello world");
    
    Bangle.beep(200,220.00*8);
    

    Additionally, I have written at least one custom app, got the app loaded running in a fork, and uploaded my app on the device, and that all works fine. I did have a few hiccups with connections and loading working initially but restarting the device seemed to fix things. The only issue I'm experiencing is with the IDE upload feature.

  • I always feel a little goofy when I solve my own problems only moments after posting about them on these forums, but apparently I have no problem anymore:

    Steps to resolve:

    1. Update and restart computer.

    2. Try exact same thing again.

    3. Note that this time the Banglejs2 device was NOT in the list for connections in the IDE, I had to pick web bluetooth and pair with it again.

    4. Everything just seems to work now. Didn't restart the bangle or anything.

    Huzzah!

    Edit: A similar, or the same issue has arisen again, this time with the app launcher. I am going to reboot my computer again to see if it still resolves the issue.

    <BLE> Device Name:       Bangle.js dbad
    puck.js:408 <BLE> Device ID:         mhStQJUeTW1Tlah21FzG+Q==
    puck.js:408 <BLE> Connected
    comms.js:231 <COMMS> Ctrl-C gave ""
    comms.js:278 <COMMS> getDeviceInfo Object
    loader.js:85 sendUsageStats: Submitting usage stats...
    index.js:941 Current device time is Mon Jun 05 2023 23:23:04 GMT-0400 (Eastern Daylight Time)
    loader.js:91 sendUsageStats (200): 
    espruinotools.js:139 Minifying
    espruinotools.js:139 Minification complete
    espruinotools.js:139 Minifying
    espruinotools.js:139 Minification complete
    comms.js:150 <COMMS> uploadApp: barometer.app.js, barometer.img, barometer.info
    comms.js:41 <COMMS> reset
    comms.js:43 <COMMS> reset: got "\u001b[?7l\r\n ____                 _ \r\n|  __|___ ___ ___ _ _|_|___ ___ \r\n|  __|_ -| . |  _| | | |   | . |\r\n|____|___|  _|_| |___|_|_|_|___|\r\n         |_| espruino.com\r\n 2v18 (c) 2021 G.Williams\r\n\r\n>"
    comms.js:52 <COMMS> reset: rebooted - sending commands to clear out any boot code
    puck.js:408 <BLE> SEND ERROR: NotSupportedError: GATT operation failed for unknown reason.
    puck.js:408 <BLE> Disconnected (gattserverdisconnected)
    

    Edit: Yes that fixed it again. The issue seems to be associated with whether or not the bangle appears "paired" already in the 'connection' dialogue. I suspect a similar thing is going on between both the web IDE and the app loader.

    I notice if I navigate in chrome to : chrome://bluetooth-internals/#devices
    I can see my device (DB:AD) and it sometimes shows stuff in the services column and even shows "connected" at times despite not being in the "connected" state in the app loader. Fiddling around with the "forget" and "disconnect" buttons in the chrome bluetooth management tab seemed to eventually get the app loader to work again.

  • Sometimes something similar happens to me - it always disconnects when I copy paste to left side of IDE while typing stuff letter by letter works. Reloading the page with shift key clears the cache and it often helps in this case. Next time I'll also try the chrome://bluetooth-internals/#devices

  • Wow, that's an odd problem - glad you got it working (kindof) though.

    What type of computer and browser do both of you have?

    I wonder whether again this could be MTU related - the IDE will try and use a higher MTU if it receives that much data, but perhaps there is some issue writing it. In the App Loader at least there's a setting (Bluetooth Compatibility mode) that allows you to not do that, and it'd be interesting to see if it solves the issue for you.

    If so I could look at adding it to the IDE...

  • What type of computer and browser do both of you have?

    Chrome in Windows 10 or 11. But in my case I do a lot of stuff that might confuse Chrome, like running E.reboot() while connected, renaming device, reflashing FW over SWD and reconnecting, switching just softdevice version, ...

    In normal usage it mostly works just fine. Disabling higher MTU is maybe too much. But maybe it could be indeed somehow related. What if they negotiate higher MTU and then Chrome would reconnect behind scenes without telling the web bluetooth part that MTU is lower now? But that is quite unlikely. Or could WebIDE cache MTU for next connection that would negotiate lower MTU? I guess not. I think I also have the "SEND ERROR: NotSupportedError: GATT operation failed for unknown reason." error in console in that case. Will check again when it happens next time (which is quite rare). I'll also try to paste less than 21 characters in such case to see if that works. And then try paste something over 20.

  • I am using chrome on windows 10 with both the web IDE, the app loader, the unofficial forked app loader with my in-progress apps, and sometimes the chrome plugin version of the web IDE.

    So far the issue only seems to appear when I have already connected at least once. I intuitively suspect it has to do with trying to connect to one service after having already connected to another, similar service, but I have not tried systemic reproduction yet. Will comment again if I can get exact reproduction. Will also check the Bluetooth compatibility mode on the app loader.

    EDIT: Another tidbit - when I am using the web IDE, the user interface doesn't even let me choose what to connect to. Found out I had bookmarked https://www.espruino.com/ide/?emulator and that caused that issue.

    After a complete reboot of my computer it seems to work just fine at least once in the web IDE. Then, if I disconnect and attempt to reconnect, it fails to upload code chunks, access device storage, etc.

    This seems to be 100% predictable based on whether or not I see the word paired written next to the bangle device in the web bluetooth selection interface. Reproduction so far only requires a reboot of computer (plus clearing all cookies and site data for the web IDE), visiting the web IDE, connecting to the bangle, uploading code, disconnecting, and reconnecting.

  • Edit: Deleted previous content in this comment because I am positive I have found the root cause for myself.

    The exact reproduction steps are

    1. Turn on Logitech K380 bluetooth keyboard. Make sure it's paired and connected with computer.

    2. Connect the BangleJS2 to the web IDE or the app loader (with compatibility mode turned off in the app loader)

    3. Send commands through the console (left side) - noting that they work fine.

    4. Send code snippets through the IDE editor to RAM (right side) - or attempt to send data with the app loader - noting that it fails and the connection is lost.

    To resolve the issue you merely

    1. Run the app loader in bluetooth compatibility mode all the time OR

    2. Connect the BangleJS2 to either the app loader or the web IDE while the keyboard is turned off. (you can turn the keyboard back on after the initial connection is made)

    It seems like some kind of bluetooth interference but I am not familiar enough with the technology to say exactly what could be happening. Some connection parameter negotiation problem / incongruity? It definitely connects either way, it just has issues sending data (MTU related?)

  • Thanks - so you think without the Logitech keyboard it all works? To be honest it sounds a lot like a Bluetooth driver issue on your PC.

    One other thing what you guys said made me think of: Do you have anything on the Bangle that might be changing the services it advertises (like HID mode, or the Bluetooth HRM app/similar)?

    Because maybe if the Bangle changes its services, the characteristic handles would change number and that might throw off Chrome if it cached them.

    ... but in terms of real fixes, all I see as options are:

    • Option in the IDE to disable higher MTUs
    • Create a build (or maybe have it an option somehow) for Bangle.js to have the lower MTU
  • I have been having the same issue with the apploader for a long time now. I dont know the exact reason for it. After connecting to the bangle js beta apploader and disconecting my bangle js 2 would only connect for about 10-20 seconds to both the normal and beta apploader. It used to fix itself after resetting the watch. But if I would connect to the beta apploader the same thing would happen again.

  • I am running default apps on my Bangle right now - I do have one custom app I am working on, but it doesn't interact with bluetooth.

    so you think without the Logitech keyboard it all works? To be honest it sounds a lot like a Bluetooth driver issue on your PC.

    Yeah if I turn off the logitech keyboard everything works perfectly - and it only needs to be off at the moment the bangle connects, then I can turn it right back on. I'm interested in the idea it might be something with the bluetooth driver on my PC. I have a couple other bluetooth devices - a keyboard, a camera, and some speakers (all are typically disconnected). If the same issue does not happen with them it might suggest its specific to this keyboard. I'll also see if there are any driver updates out there.

    Utimately, the issue is very small for me now - it's extremely easy to work around, just a flick of a switch and then back one second later. Happy to help with additional diagnostics but just want to make sure the lack of urgency on my end is clear.

    Edit: Ooh I can also try with my phone, since that has bluetooth as well - eliminate the PC from the equation. Will report back if I find out anything useful.

  • Wow, that is interesting. Personally, I feel like if one Bluetooth peripheral can affect another, that's definitely an issue with the host computer's bluetooth stack. There's really not that much I can do at my end.

    ... maybe you could check all your drivers for your PC's bluetooth are totally up to date?

    @kjek do you have other Bluetooth peripherals connected to your PC as well?

  • @Gordon I checked for other bluetooth peripherals, and made sure none were connected. I also turned off whitelist and HID, and turned on bluetooth compatibility mode in the apploader but the bangle js 2 still disconects after about 10-20 seconds.

  • @kjek If you were using Whitelist, are there other Bluetooth settings you changed too, like Passcode? Maybe you could try booting the Bangle with the button held down (all the way through bootloader, until it starts). That should hopefully boot the Bangle without loading any code at all - and i'd be interested to see if you can keep a connection for longer in that case

  • Just a note that it seems this happens on other Espruino devices too - see https://forum.espruino.com/conversations­/387632/#comment17024772

    The change went in over 3 years ago and it seems like nobody has issues until this month, so I'm pretty sure this is a driver issue on Windows.

    I have a Windows 11 Laptop here with a Realtek Bluetooth Adaptor in and it's fine. If you check in Device Manager, what make is yours?

  • Don't forget the throttle send option: always in the web ide which is very similar to the bluetooth compatibility checkbox on the apploader site. I use this all the time to get my broken phone's bluetooth working.

  • @Gordon
    Something that is quite interesting is that the disconnects do not happen on my original bangle js 1 which is running old firmware (2.13), so it might not be a windows issue

  • Well, 2.13 already has the larger MTU feature that may be related to this issue (it was part of 2.09 https://forum.espruino.com/conversations­/362761/ ) so in theory it could break also with Bangle 1. But at least for me this issue is pretty random so even if it works for you now you may still hit the issue with Bangle1 later.

    To verify it is MTU related you can try the copy paste test in WebIDE described here https://forum.espruino.com/conversations­/387632/#17024455

    If it is the same issue then pasting block of text over 20 bytes will disconnect your Banglejs2 device too while pasting smaller block would work.

    It may not be strictly Windows related but maybe it is Chrome vs OS Bluetooth stack related. And Chrome also changes quite often just like Windows updates. I wonder if it happens in Linux too, I use both and it happens to me from time to time but I am not sure which OS I was using when it happened.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Bangle disconnects from IDE when uploading code from right hand side / viewing filesystem

Posted by Avatar for Philip @Philip

Actions