• Hi!

    I try to get espruino cli working.

    I ran

    npm install -g espruino
    espruino --list --verbose
    

    and get several errors. The complete log is in the attachment, the problematic parts are shown here (the actual user dir was masked to by me before posting this):

    :
    Found <MYUSERDIR>\AppData\Roaming\npm\node_mod­ules\espruino/core/serial_winnus.js
    'winnus' module not found, no Windows Bluetooth Low Energy Error: Cannot find module 'winnus'
    Require stack:
    - <MYUSERDIR>\AppData\Roaming\npm\node_mod­ules\espruino\index.js
    - <MYUSERDIR>\AppData\Roaming\npm\node_mod­ules\espruino\bin\espruino-cli.js
    :
    Initialising SetTime
    Searching for serial ports...
    Noble: getPorts - initialising...
    Noble: module couldn't be loaded, no node.js Bluetooth Low Energy
     Error: Cannot find module '@abandonware/noble'
    Require stack:
    - <MYUSERDIR>\AppData\Roaming\npm\node_mod­ules\espruino\index.js
    - <MYUSERDIR>\AppData\Roaming\npm\node_mod­ules\espruino\bin\espruino-cli.js
    :
    [Error: ENOENT: no such file or directory, open 'C:\serial\ports'] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'open',
      path: 'C:\\serial\\ports'
    }
    /serial/ports doesn't exist - disabling WebSocket support
    PORTS:
      COM6  (Microsoft)
      COM5  (Microsoft)
    

    Any suggestions?


    1 Attachment

  • What are you actually trying to connect to? A Bluetooth device? And you're on a Windows system by the look of it? which version?

    It looks like despite the errors, Serial is still working ok.

    If it's windows and you want Bluetooth, your issue is that the modules that would handle Bluetooth LE on windows haven't installed properly. Best bet is to remove espruino again using NPM, then re-install it and see what the log message displays.

    Note: If anyone knows of a module that handles Bluetooth LE on windows properly, and that actually installs without trouble then I'm very happy to include this in the CLI

  • As the title says, it's Windows 10.
    Version 22H2, to be precise.

    Espruino Command-line Tool 0.1.46

    I like to access my Bangle.js 2, but I thought this is some generic problem. I don't know what the COM-ports actually are on my system.

    I've already reinstalled the cli and still get the error. I also assume that no bluetooth modules are installed, since AppData\Roaming\npm\node_modules\espruin­o\node_modules\ does not contain folders winnus or noble, and the @abandonware subfolder is empty. The npm install espruino command, however, did not show any errors.

    By the way, while looking at the code where the noble error comes from, I discovered serial_noble.js lines 58ff

    function startNoble() {
        try {
          process.on('uncaughtException', nobleExceptionHandler);
          try {
            noble = require('noble');
          } catch (e) {
            noble = require('@abandonware/noble');
          }
        } catch (e) { ... }
    

    where the exception from require('noble') is swallowed, which (at least in my case) is the root problem. I suggest adding some log message that noble could not be loaded and @abandonware/noble is tried instead.

  • Note: If anyone knows of a module that handles Bluetooth LE on windows properly, and that actually installs without trouble then I'm very happy to include this in the CLI

    I briefly tried https://github.com/Timeular/noble-winrt mentioned here
    https://forum.espruino.com/conversations­/379406/#16669085
    if you can do const noble = require('noble-winrt'); only on Windows>=10 then it could be worth trying.

    EDIT: It even says "On non-Windows platforms or Windows versions lower than 10.0.15063 this will use the regular noble implementation"

  • Sorry - I missed the title.

    The npm install espruino command, however, did not show any errors.

    Ok, wow, that's strange then. I guess because they're listed as 'optional' it now doesn't show you if they fail to install.

    The idea with the code you posted is to allow it to work with noble or @abandonware/noble as the abandonware one is the one that is more recently updated - so you'd expect that noble might fail because we don't choose to install that one, but hopefully @abandonware/noble would show.

    Please can you try again now? I just updated the espruino package to attempt to use noble-winrt on windows, which is actually a much better, more seamless solution.

    If that doesn't work, maybe try npm install noble-winrt and then it might tell you what was wrong - when you install Node.js you usually get given the option of installing something ('Chocolatey'?) that makes it possible to install 'native' libraries - it's possible that if you didn't do that, it would fail to install these modules. Definitely when I tried again on a Windows PC here it was fine (although BLE still refused to work out of the box until these most recent changes).

    I should add that even if that fails, you can still use the CLI by using your phone as a Bluetooth connection: https://github.com/espruino/EspruinoTool­s#web-ide-relay

  • Thank you, Gordon! It now works. That's so great! I'm always impressed how quickly and well you reply to any issue here!

    BTW, I first tried espruino within the Git Bash in Windows and got some error that that setRawMode could not be called on stdin (serialport error: TypeError: process.stdin.setRawMode is not a function). Luckily, that's no issue when using cmd or Powershell.

  • when you install Node.js you usually get given the option of installing something ('Chocolatey'?) that makes it possible to install 'native' libraries - it's possible that if you didn't do that, it would fail to install these modules.

    I just installed latest LTS node from https://nodejs.org/en/download and did not check the checkbox to install those extra tools on last screen. Then I run npm -g install espruino and espruino --list --verbose and while the BLE sort of works it won't find my devices.

    Looks like the var hasUartService = dev.advertisement.serviceUuids && dev.advertisement.serviceUuids.indexOf(N­ORDIC_SERVICE)>=0; fails most probably because of https://github.com/Timeular/noble-winrt/­issues/18

    When logging advertising data in else console.log("Noble: Found device:", name, dev.address,dev.advertisement); I see most devices have manufacturerData: null, serviceUuids: [],

    There is even PR for that bug waiting here https://github.com/Timeular/noble-winrt/­pull/29 :-(

    Can I force the device address/name somehow from command line? When I added device name to https://github.com/espruino/EspruinoTool­s/blob/master/core/utils.js#L665 it connected and seems to work. maybe when passing -p macaddress the check could be skipped as a workaround. Or maybe when called like -d deviceName the deviceName could be added to recognisedBluetoothDevices list.

    Well, at least it works for all official devices in the list for now, which is good :-)

  • and got some error that that setRawMode could not be called on stdin

    Thanks! I'll get a fix in for that.

    Can I force the device address/name somehow from command line?

    Yes, you just do -p ma:ca:dd:re:ss I think?

    fails most probably because of https://github.com/Timeular/noble-winrt/­issues/18

    What's concerning actually is I'm using https://www.npmjs.com/package/noble-winr­t but maybe I should actually be using https://www.npmjs.com/package/@jefflloyd­/noble-winrt instead? It seems more actively maintained - and it's possible that even without that change it would behave better?

    But it's also odd that the current solution works for us, but not for you

  • But it's also odd that the current solution works for us, but not for you

    It is because for official devices you skip the check for advertised service uuids here
    https://github.com/espruino/EspruinoTool­s/blob/master/core/serial_noble.js#L109

    I am trying with custom board name not in the list here
    https://github.com/espruino/EspruinoTool­s/blob/master/core/utils.js#L665
    which is used to skip the check.

    So that's why I suggested to skip this hasUartService check also when you pass -p ma:ca:dd:re:ss or -d deviceName because maybe you really want to connect to this no matter what. But also it is workaround for this bug.

    EDIT: as for https://www.npmjs.com/package/@jefflloyd­/noble-winrt yes, it is worth trying

  • So that's why I suggested to skip this hasUartService check also when you pass -p ma:ca:dd:re:ss

    Sorry, I missed that. That sounds good - do you want to do a PR for it?

  • do you want to do a PR for it

    ok, here it is https://github.com/espruino/EspruinoTool­s/pull/162

  • I tried the https://www.npmjs.com/package/@jefflloyd­/noble-winrt but unfortunately it needs to compile it from C sources via node-gyp (unlike the previous version). After installing build tools it fails to compile it. Looks like current LTS node uses VS2019 compiler which is more strict and does not like the source code so I gave up on this.

  • Thanks - that's a shame... But the whole Node.js native addition stuff is (or at least was) a mess. I basically gave up on Winnus in the end :(

  • do you want to do a PR for it?

    maybe you missed that one in post #11? https://github.com/espruino/EspruinoTool­s/pull/162

    With that it is actually quite usable for me on Windows 10 with https://www.npmjs.com/package/noble-winr­t you have there now. Fortunately this one does not need native compilation and just pulls some binary.

  • Just merged.

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

espruino-cli not working (Windows 10, BLE, winnus/noble)

Posted by Avatar for neshanjo2 @neshanjo2

Actions