No connection BLE Espruinohub

Posted on
  • My goal is to send Mqtt messages to my service robot,but since the bangje.js have no Wifi so tried to use the EspruinoHub .

    I have setup a EspruinoHub and Node-red on my Raspberry Pi
    In the first stage my setup failed because the tutorial on the internet use Node.js version 8.x.x but the setup installed 10.x.x
    After find out how to change to version 8. everything seems fine, but it wasn't because Node-red is not working under node.js v 8.x.x and npm install does not work under version 10.x.x
    So decide to use only version 8.x.x and no Node-Red

    But so far I know the hub and BLE is working, but when I try to connect my watch it failed.

    When i use hcitool lescan sometimes my watch is visible but most of the time it does not show up in the scan.

    pi@raspberrypi:~ $ sudo hcitool lescan
    LE Scan ...

    78:5C:09:70:14:91 (unknown)
    C6:65:C2:3D:E6:A7 Bangle.js e6a7
    C6:65:C2:3D:E6:A7 (unknown)

    ^Cpi@raspberrypi:~ $ sudo gatttool -b C6:65:C2:3D:E6:A7 -I
    [C6:65:C2:3D:E6:A7][LE]> connect
    Attempting to connect to C6:65:C2:3D:E6:A7
    Error: connect error: Connection refused (111)

    Can someone help me to connect and send a Mqtt message.

    I am new on javascript so my knowledge is not to much

  • most of the time it does not show up in the scan.

    Are you using Gadgetbridge or connecting to the Bangle some other way? Once it is connected it'll stop advertising, so that could be your issue?

    If you run EspruinoHub just at the command-line rather than as a service, you should hopefully see the Bangle listed under the devices it has found? If you don't see any devices you may need to run the setcap command from the README

  • After starting from scratch to setup the espruinohub again it finally seems to connect.
    But when I use the smartswitch app for test there are no messages coming in at the mosquitto server when I subscribed to the topic
    mosquitto_sub -h localhost -t "ble/advertise/c6:65:c2:3d:e6:a7/data" -v

    I hope there is a simple app available that just can send a string to the Mqtt broker as example so I can see how it works.

  • Did you change the config file, because I think by default the path is /ble/....

    Maybe just try: mosquitto_sub -h localhost -t "#" -v to see all advertising info, and figure out the path from there?

  • Hi Gordon.
    Tried every combination and when I send a message as below no problem at all except messages from the watch.

    mosquitto_sub -h localhost -t "/#" -v

    mosquitto_pub -h localhost -t test/topic -m "Hello world"
    Do you know there is a example of sending a message using BLE and Mqtt?

  • Not sure if you saw this already, but there is some example code here:­mqtt-bridge

  • Yes I have seen that and I think the root of the problem is there. I followed this to setup my Raspberry pi but this information is not up-to-date anymore. This is all based on Node.js version 8. When you do this setup it will install node v10.x.x so the latest command line npm install does not work anymore, so you first have to downgrade to node 8.x.x to complete the setup. But then the next problem dig up node red is only working with version 12.x.x or later.
    So I think the setup is not working 100% and the incoming messages on BLE will not be relayed over MQTT

  • Finally i got it to work. I was accidentally overwriting the boot loader and had to remove everything from the watch, after removing all the apps and just uploaded the basic apps the BLE connections was working 100%. I only have one problem how can I send a text message to the MQTT server.
    0xffff is sending data , 0x1809 is sending the temperature but can't find how to send a text string.

  • Hi Robin. Thanks for your answer but this is not where we looking for, these scripts all use WIFI to connect to the MQTT broker. I made many MQTT connections over the internet with no problem if the device has WIFI. The Bangle.js has no WIFI so we have to connect to the broker with BLE and that's very different then a WIFI connection.

  • Glad you got it sorted!

    I believe you should be able to do:

      manufacturerData:E.toJS("Your text") 
    // or failing that
      manufacturerData:E.toJS({t:"Your text"}) 

    I don't think there is a specific attribute type in EspruinoHub for text yet though - about the closest is Eddystone for URLs

  • The result of your solution above
    /ble/advertise/c6:65:c2:3d:e6:a7/data "123,116,58,34,89,111,117,114,32,116,101­,120,116,34,125"
    The message contains only digits and no text.
    We are writing software for our healthcare robot and we need to send plain text to the MQTT server and in a later stadium the sensor data of the heartbeat. so the robot can pick it up and react on the data it received.

  • Are there any other MQTT messages? Usually when you send manufacturerdata of 0x590 that is Espruino's manufacturer code, so EspruinoHub will decode the JSON into individual MQTT packets

  • Seems sending plain text over BLE is not possible. Work around is using Eddystone and filter the text on my robot device. On forum items I see the use of : NRF.setAdvertising({},{manufacturer: 0x0590, manufacturerData:"Hello"}); but using this on the Bangle.js it will only advertise Hex code.

    But i am also struggling with MQTT topics. I modified a step-counter a bit to send the steps to my device over BLE using 0xffff but also sending my HRM the same time using 0xffff this will automatic create the MQTT topic data for both values. I can't find how to give the HRM and the Steps data a different topic name like data/hrm and data/steps.

  • If you want to add your own named topics (or strings), you probably need to modify EspruinoHub to add those topics.

    Here, you can see the attributes listed:­blob/master/lib/attributes.js#L186

    So just add your own handler. For instance this should produce a string with a str topic for attribute 0xFFFC:

      "fffc": function (d) {
          var s  = "";
          for (var i = 0; i < d.length; i++)
            s += String.fromCharCode(d[i]);
          return {str: s};
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

No connection BLE Espruinohub

Posted by Avatar for user133055 @user133055