what happens after "Serial".setConsole ?

Posted on
  • After calling Bluetooth.setConsole I get a timeout in IRQ.
    Before doing this, a BLE service with

    If consoleDevice = device; is commented, it works fine. Obviously on old settings.

    What happens after setting consoleDevice ?
    Do I have to add something to Bluetooth object ?

  • Well, it:

    • Initialises the device if it's not done already (I think jshUSARTSetup may get called for Bluetooth)
    • Outputs -> Bluetooth to the old device
    • Sets the console deviec
    • Outputs '<- OldDevice` to the new device
    • Prints the JS console characters (>)

    It's all here: https://github.com/espruino/Espruino/blo­b/master/src/jsinteractive.c#L168

    I can't remember anything else offhand, but you'd have to look at the source of jsiSetConsole.

    I guess it could be the Bluetooth serial write IRQ that's crashing? You need to have a way of taking data out of the txBuffer and transmitting it via Bluetooth from an IRQ - if you don't have that then the txBuffer will just get full and things will stall.

    Does just doing Bluetooth.write("sometext") cause problems, or does that work?

  • Hmmm,
    so I've to catch device EV_BLUETOOTH in jshUSARTSetup.
    Anyway, if EV_BLUETOOTH is already initialised this should be skipped.
    I see -> Bluetooth on console, up to that point everything is fine.
    If next step (set Console Device) is done, app runs into IRQ timeout.

    I cannot find the step, where something like Bluetooth.write is called. There should be a, let me say connection/function, to write data to ESP32 bluetooth device from Serial object.

    Walking through jswrap_serial and jsdevices, at the end, it should go to jshUSARTKick with device = EV_BLUETOOTH, is that correct ?

  • it should go to jshUSARTKick with device = EV_BLUETOOTH, is that correct ?

    Yes, and you can kick off Bluetooth transmission from there. However you still need a way to detect when a Bluetooth packet has finished sending so you can send the next one.

    Also, using USARTKick isn't ideal - it'll get called after the very first character. Ideally you want to be able to write multiple characters from the buffer at once.

    nRF52 uses a 'radio notification' event to do that: https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/bluetooth.c#L744

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

what happens after "Serial".setConsole ?

Posted by Avatar for JumJum @JumJum

Actions