EspruinoHub not disconnecting from device?

Posted on
  • I just installed EspruinoHub on a Raspberry Pi 4 with node-red and an external BLE dongle with an external antenna. hciconfig shows the dongle ok.
    The config for EspruinoHub points mqtt to a separate machine that only runs a mosquitto.
    The web pages works fine, I can see advertisement etc etc. Ok.
    Using an mqtt sub app I can see the /ble/# messages. Ok.
    I start the webIDE, and it shows me the Espruino devices. Ok.
    Click on a device and it connects and I can interact with the device. Ok.
    Looking at the /ble/# topic on the mqtt server I get all devices messages before starting the webIDE, when the webIDE starts I only get the connected device messages. Ok.
    I then click the disconnect icon, and the webIDE says disconnected :mac:. Ok.
    But, looking att the /ble/# subscription I'm still getting the console messages from that device.
    To get espruinoHub back to it's original state I need to stop and start it.
    To me it looks like the disconnect is missed when the webIDE closes.

  • Ahh - that's interesting. Is the device you're connecting to printing data to the console all the time?

    So what usually happens is the Web IDE connects and sends ping/notify messages every few seconds, which force EspruinoHub to stay connected. When the IDE stops (eg the window is shut or you disconnect), after a few seconds EspruinoHub times out and disconnects.

    I wonder if having the device you're connected to sending data back to EspruinoHub causes it not to time out? Could you try stopping the device from sending anything, and see if it then auto-disconnects?

  • Yes it is always printing data to the console :-)

    The module polls a device over a serial port, but I need to modify the code to not print any errors when I lift the TX pin on the device. Normally it would print an error every time it timeouts.

    I have previously tried using the tx function in EspruinoHub to write data to a device via mqtt, I'm guessing that function will be effected by this to?? Never got it to work...

  • Ahh, right. Well, you could just remove this single line:

    https://github.com/espruino/EspruinoHub/­blob/c4632552b4eb85f77eea02def5e413c15f6­c34e7/lib/connect.js#L423

    And it should work? Honestly I'm not sure I see much of a reason why it should be kept in, so if you find that fixes it for you let me know and I'll remove it from the main build.

    TX should definitely work (after all the Web IDE uses it) - maybe you could snoop MQTT (which you're doing it seems?), see what the Web IDE does, and copy that yourself and see if it works?

  • I tried with the "connection.setUsed()" commented out, but that made no difference.

    Will rewire my lab setup later tonight and se what happens if I make it silent.

  • So a bit more testing done.
    I changed my js code so that is dont print anything to the console by it self. So when connecting with the IDE it's silent.
    I run EspruinoHub stock, line 423 is active in connect.js.
    It starts, finds the devices, updates the mqtt with all the data.
    I have enabled all the mqtt options so there is a stream of messages at /ble/# that i subscribe to.
    I open the IDE from EspruinoHub, and I can connect to my device. Press enter a few times and I can see the packets on the console from start.sh.
    Press disconnect.
    After som time the console states "Connection [] IDLE"
    But there is no stream of messages on the MQTT, all silent.
    The clock is ticking over on the console output from start.sh, but the list of devices does not update.
    And reloading the IDE and pressing connect does not show any devices to connect to.

    [MQTT] Connected
    [Discover] Re-sending presence status of known devices
    [Discover] Noble StateChange: poweredOn
    [Config] Config config.json loaded
    [MQTT] Connecting...
    [HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
    [HTTP] Server is listening on http://localhost:1888
    [Config] Config config.json loaded
    [MQTT] Connecting...
    [HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
    [HTTP] Server is listening on http://localhost:1888
    [HTTP] www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
    [History] history_path value is empty, thus not providing history.
    [MQTT] Connected
    [Discover] Re-sending presence status of known devices
    [Discover] Noble StateChange: poweredOn
    [Discover] Starting scan...
    [Discover] Scanning started.
    [HTTP] Serving /home/pi/EspruinoHub/www/ide.html
    [HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
    [HTTP] Wed Apr 14 2021 20:55:27 GMT+0100 (British Summer Time) Connection accepted.
    [HTTP] Websocket MQTT connected
    [Discover] Scanning stopped.
    [Connect] d2:fd:13:f9:3d:32: Connecting...
    [Connect] Connected.
    [Connect] d2:fd:13:f9:3d:32: Getting Service...
    [Connect] d2:fd:13:f9:3d:32: found service: 6e400001b5a3f393e0a9e50e24dcca9e
    [Connect] d2:fd:13:f9:3d:32: found characteristic: 6e400003b5a3f393e0a9e50e24dcca9e
    [Connect] d2:fd:13:f9:3d:32: startNotifications complete
    [Connect] serviceQueue jobs 1
    Starting job from Queue
    [Connect] d2:fd:13:f9:3d:32: Getting Service...
    [Connect] d2:fd:13:f9:3d:32: found characteristic: 6e400002b5a3f393e0a9e50e24dcca9e
    [Connect] d2:fd:13:f9:3d:32: Written 1 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 19 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 19 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 16 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 1 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 1 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 1 bytes
    [Connect] d2:fd:13:f9:3d:32: Written 1 bytes
    [Connect] d2:fd:13:f9:3d:32: Disconnecting due to lack of use (after 20 secs)
    [Connect] d2:fd:13:f9:3d:32: Disconnecting.
    [Connect] d2:fd:13:f9:3d:32: Disconnected
    [Connect] Connections remaining: []
    [Connect] Disconnected by device
    [HTTP] Websocket MQTT closed (WebSocket)
    [HTTP] Websocket MQTT closed (MQTT)
    [HTTP] Serving /home/pi/EspruinoHub/www/rssi.html
    [HTTP] Serving /home/pi/EspruinoHub/www/tinydash.css
    [HTTP] Serving /home/pi/EspruinoHub/www/tinydash.js
    [HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
    [HTTP] Wed Apr 14 2021 20:56:12 GMT+0100 (British Summer Time) Connection accepted.
    [HTTP] Websocket MQTT connected
    [HTTP] Websocket MQTT closed (WebSocket)
    [HTTP] Websocket MQTT closed (MQTT)
    [HTTP] Serving /home/pi/EspruinoHub/www/ide.html
    [HTTP] Serving /home/pi/EspruinoHub/www/paho-mqtt.js
    [HTTP] Wed Apr 14 2021 21:00:02 GMT+0100 (British Summer Time) Connection accepted.
    [HTTP] Websocket MQTT connected
    
    Wed Apr 14 2021 21:00:56 GMT+0100 (British Summer Time)
    
    08:66:98:c2:97:36 - ? (RSSI -69)
    1c:47:96:28:4e:d5 - ? (RSSI -76)
    3b:90:3a:9d:b2:3d - ? (RSSI -70)
    48:a3:04:51:65:3a - ? (RSSI -44)
    5c:b4:40:88:b2:a0 - ? (RSSI -70)
    68:7b:52:1b:85:cf - ? (RSSI -72)
      fe9f => {"Google":{"type":"Buffer","data":[2,100­,114,85,55,65,101,114,117,82,89,73,0,0,1­,120,209,248,23,164]}}
    6a:f0:dc:31:39:a3 - ? (RSSI -53)
    c8:d0:83:ba:9d:e1 - ? (RSSI -69)
    d2:fd:13:f9:3d:32 - CTx1 (RSSI -68)
    [CONNECT] Connections [] IDLE
    
  • Ok, thanks - that's interesting then.

    Looks like after [Connect] Disconnected by device it doesn't restart scanning for advertisements, I'm taking a look at this now...

  • Ok, try now - should be fixed.

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

EspruinoHub not disconnecting from device?

Posted by Avatar for JohanWinas @JohanWinas

Actions