• Ahh, I think I see your problem.

    You are using nus_tx to write to the Puck as well to signal the button press?

    To write to the Puck a connection has to be opened (and it's kept open for a few (10?) seconds after the write in case another write comes along), but while that connection is open the Puck isn't advertising, so you don't receive any data from it.

    So after the initial button press, there's then 10 sec of not receiving anything.

    So you have two options:

    • Don't write to Puck.js (you could still make the Puck blink itself)
    • Switch the way you transfer data so that you always keep an open connection.

    You can do the second option by:

    • Program the Puck just to do Bluetooth.write("PRESS\r\n") (no setAdvertising) when the button is pressed
    • In your NodeRed flow, make sure you send a MQTT packet to /ble/notify/DEVICE/nux/nus_rx every 5 seconds
    • Listen on /ble/data/DEVICE/nus/nus_rx for data
    • To send commands to the Puck, send to /ble/data/DEVICE/nus/nus_tx as before

    The only problem with that approach is you can't also scan for advertising packets with EspruinoHub at the same time as holding open a connection.

    There's a third option which is to stop EspruinoHub from holding the connection open, but right now that's not something available in the config so would need a code change

  • thanks, found the culprit.
    so what is the best solution, quickest and best for battery please?

About

Avatar for Gordon @Gordon started