Avatar for user114366

user114366

Member since Jun 2020 • Last active Oct 2020
  • 4 conversations
  • 43 comments

Most recent activity

  • in ESP32
    Avatar for user114366

    Hey 🙂,

    I'm working with the ESP32 in an application where I have to switch between being in AP mode, and connect to my home WiFi.

    Problem:
    I need to send a list of available access points created using the wifi.scan()-function, but sometimes an old scan seems to "hang" and I get the error: A scan is already in progress. forever.

    I found the place in the source code, that generates the error: jswrap_wifi_scan.

    Something strikes me as odd though;
    the variable for the callback function g_jsScanCallback is assigned in the beginning of that function, and released again in the end of a function called scanCB. But I see multiple return statements in jswrap_wifi_scan in case of different errors, so couldn't it be that the variable is assigned, but the scan never kicked off 🤔. It would never get cleared again.
    I'll admit, I can't figure out how the event that calls scanCB is finally kicked off, but g_jsScanCallback is assigned in line 894, and jswrap_wifi_scan could be exited only a few lines below at line 906, and I don't see the scan getting started anywhere in between.

    Observations:
    ... in any case, the problem is a bit hard to re-produce, but this is roughly what I observe:

    1. If I completely shut power off the board, and re-connect it, I'm allowed to scan. And successsfully perform scans after that. Starting an AP, and still perform scans after that.
    2. However, if I've had a failed attempt on connecting to wifi using bad credentials with the wifi.connect-function, I get the scan error the next time I try to scan, and now it seems to hang forever
    3. If I flash my code onto the board again, and wait for onInit to run, the scan still fails
    4. I have always gotten these two errors when I connect the board, but haven't given them much thought until now:

    WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
    Running onInit()...
    

    Thoughts?

  • in ESP32
    Avatar for user114366

    It's a bit of a hack but it's possible

    I'll take it--thanks 😎!

  • in ESP32
    Avatar for user114366

    Yeah, this is what someone suggested on SO as well.

    If I've understood correctly, callbacks seem to be the general convention used across the project, so I think it would be more correct to have connect provide a callback-function with an error object/string, but perhaps I'm missing something 🙂.

    I'll leave messing with the modules to the pros 😊.

  • in ESP32
    Avatar for user114366

    Hey Robin,

    Thanks for taking the time to write such a detailed answer 🙂!

    I had hoped that the review of the var's value and use of dump() from last week would have triggered the answer.

    I still havn't learnt how the output from dump() can help me out--I'm still just a novice in all this Espruino business 😁. I'll have to read up on that sometime.

    Opening module SX127x.js I searched for the error that is displayed.

    Yes, I got the same result regarding the source of the error.

    and there may be some reason the bubble up error is not able to be trapped.

    As AkosLukacs suggests, the reason seems to be that it's eventually thrown inside a setTimeout ?

    I'm with you here, but in defense of the author .... In bold text: 'however it is extremely beta'

    Sure, I'm not blaming anyone for making code for free, and I'm extremely satisfied with the library--I was just explaining that my assertion on JavaScript is that errors should be catchable, but apparently in some cases are not 😊.

    So I guess the case is closed--I'll never be able to catch it 🤔. Catching the error was my only concern of this thread, fixing the communication is not going to be a problem.

    Thank you so much for helping out again, you are always very thorough 😁!

  • in ESP32
    Avatar for user114366

    Hi MaBe,

    While AkosLukacs has confirmed that I will never be able to catch the exception, I'll see that come in handy next time I'm debugging Espruino modules--thanks 👍.

  • in ESP32
    Avatar for user114366

    Hi AkosLukacs,

    You won't be able to catch that exception

    Although regrettable, thanks for confirming that--that basically settles it 😕👍 .

  • in ESP32
    Avatar for user114366

    Hi Robin 🙂!

    It's uploaded from the right-hand side, then uploaded to Flash using the "Send to Espruino" button in the IDE.

    I have boiled down the code to this (right-hand side):

    // ****************************************­*********************
    // *** CONST / VARS
    // ****************************************­*********************
    
    // Pins
    const PIN_RESET = D17;
    const PIN_CS = D4;
    const PIN_SCK = D5;
    const PIN_MISO = D19;
    const PIN_MOSI = D23;
    
    let sx;
    
    // ****************************************­*********************
    // *** MAIN
    // ****************************************­*********************
    
    /*
     * Called on boot
     */
    function onInit() {
    
        try {
            SPI1.setup({ sck: PIN_SCK, miso: PIN_MISO, mosi: PIN_MOSI });
    
            sx = require('SX127x').connect({
                spi: SPI1,
                cs: PIN_CS,
                rst: PIN_RESET
            });
    
        } catch (e) {
            console.log('e: ', e);
        }
    
    }
    

    Should this be taken literally as actual error text?

    No, the error is always as shown below:

    Uncaught Error: Radio not found!
     at line 1 col 65
    ...ow Error("Radio not found!");this.setOpMode(0);this.mask(1,1­...
    

    Persusing the source will reveal what var objects are created as the module is fetched/parsed. Maybe a conditional test against 'undefined' or what might be expected as those are initialized, and/or throw your own user defined error to catch?

    I don't quite understand what you are suggesting 🙂. Which properties could I test against undefined? I mean the error is happening inside the Espruino module, and apparently I'm unable to catch it externally. Modules are not my strongest side, but should't I be able to do that?--I mean, why throw an error if you are prevented from handling it 🤔..

    Thanks for taking the time to help 😁!

  • in ESP32
    Avatar for user114366

    Hi 👋,

    I'm getting this error from time to time when using the "SX127x" module in a couple of projects (custom HW, and ESP32).

    Uncaught Error: Radio not found!
     at line 1 col 65
    ...ow Error("Radio not found!");this.setOpMode(0);this.mask(1,1­...
    

    I'm not so concerned with why it fails right now (probably bad SPI communication), but I'd like to catch it so I can handle it properly.

    I've tried the code below, but I still get Uncatched Error: ... in the WEB IDE.

        try {
            sx = require('SX127x').connect({
                spi: SPI1,
                cs: PIN_CS,
                rst: PIN_RESET
            });
        } catch (e) {
            console.log('Error catched: ', e);
        }
    

    Q: Can anyone advise me on how I can catch this error--or is there a more general way to catch errors that happen internally in the Espruino modules 🙂?

Actions