• While Web BLE is simply genius when it comes to ease of using pre-built development tools, I want to build a 'server' side app/tool to suck up all data from my Bangle watch. Web BLE's valid https cert requirement is really getting in the way at the moment for me.

    I just want a Node console application that connects to my Bangle JS and pulls existing files (created by my BangleJS App on the watch).

    I saw the example of using Puck.js over Web BLE, can I do something like that without Web BLE? Say I pair my watch with my laptop, can I use simple NodeJS to pull files over Bluetooth? Any guidance is appreciated. It need not be Bangle JS specific, any Espruino sample will do.

    Cheers

  • Just after posting, I find this... https://github.com/noble/noble

    I am going to see if I can connect to my Bangle using this and build a nice bridge.

  • Just a word of warning that Noble is currently unmaintained and does not work with the most recent versions of Node.js.

    This version works quite well on Mac and Linux: https://github.com/abandonware/noble (less so on Windows)

    And this version still seems to be ok on Windows despite lack of updates: https://github.com/jasongin/noble-uwp

  • I used web-ble on localhost without issues.
    Either there is an exception for localhost, or had a valid https cert, not sure right now. Maybe used dotnet serve as it has https?
    One simplistic way would be to check out some of the Puck.js' tutorials, and just hack away in the console. Loaded from https -> Web BLE is happy :)
    Or clone & host it on github pages -> free and easy https & hosting & source control. Commit when you reach something semi-stable. Unless it's secret / sensitive / private. Of course than don't host it on any public site!

    If you try noble: read the docs and node docs, last time I checked it only worked on node 8. Might be better now.

  • @ConorONeill thanks for the heads up... I was having trouble with my dev environment, first OSX baulked, but I don't have full XCode (only bare minimum) installed, so I thought I would try Linux.

    Then my linux box baulked, someone has messed the apt-repository index files and it won't install anything.

    So my third step was to setup a Pi... This is where I had left it until I saw your note. Will proceed with caution.

    Any alternates you know of?

    @AkosLukacs yeah I think all I need to do it stick the self signed cert into the Trusted Keystore, now if I could only find a reliable documentation on how to do that on OSX. The cert generated by OSX Keystore isn't accepted by http-server (node app) and the one generated by openssl isn't accepted into the Keystore atm.

    Might come back to this if Noble fails.

  • @PiOfThings The most reliable setup for me remains Pi3 and Pi4. Still using abandonware/noble.

  • This might be what you're after: https://www.espruino.com/Interfacing#blu­etooth-le

    It's a set of example code for communicating with Bluetooth LE over:

    • Web Bluetooth
    • Node.js / JavaScript
    • Python
    • Bash via gatttool on Linux

    So hopefully one of those will work for you :)

  • @ConorONeill Thanks... and @Gordon woah... how did I miss that... Thanks a ton... Given noble is unhappy on my laptop, I'll give Python a go...

  • Brilliant! Finally got something to work... bleak works on my laptop.

    The example gives the impression that the mac address of the BangleJS is good enough to connect to it, but that didn't work. So instead I commented out the command run and used the discover run to first get the address. It came out as a long set of strings for all the nearby BLE devices, thankfully it identified Bangle as follows (I've mangled the last 5 characters).

    0DB07D6F-8F0F-4CB3-A801-0D9A868XX9XX: Bangle.js ed8a
    

    I then used this as the address and the following code came back with a list of files though it is still a bit mangled, but it's a start.

    import asyncio
    import array
    from bleak import discover
    from bleak import BleakClient
    
    address = "0DB07D6F-8F0F-4CB3-A801-0D9A868XX9XX"
    UUID_NORDIC_TX = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
    UUID_NORDIC_RX = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
    command = b"\x03\x10var f = require('Storage')\n\x10 print(f.list())\n\x10print('Hello World')\n"
    
    def uart_data_received(sender, data):
        print("RX> {0}".format(data))
    
     # You can scan for devices with:
     # async def run():
     #    devices = await discover()
     #    for d in devices:
     #        print(d)
    
    print("Connecting...")
    async def run(address, loop):
        async with BleakClient(address, loop=loop) as client:
            print("Connected")
            await client.start_notify(UUID_NORDIC_RX, uart_data_received)
            print("Writing command")
            c=command
            while len(c)>0:
              await client.write_gatt_char(UUID_NORDIC_TX, bytearray(c[0:20]), True)
              c = c[20:]
            print("Waiting for data")
            await asyncio.sleep(1.0, loop=loop) # wait for a response
            print("Done!")
    
    
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run(address, loop))
     # loop.run_until_complete(run())
    
  • Okay, as per this example from bleak, Darwin aka OSX doesn't work with MAC address, it needs the funky string ID of the device.

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

Guidance needed on file transfer over BLE without Web BLE [Resolved]

Posted by Avatar for PiOfThings @PiOfThings

Actions