https esp32

Posted on
  • Hello everybody,
    I tried with different versions of firmware (2.04) and have every time the same issue:

    Uncaught InternalError: Failed! mbedtls_ssl_setup: Not enough memory
    
    >process.env
    ={
      VERSION: "2v04",
      GIT_COMMIT: "3956264e",
      BOARD: "ESP32",
      FLASH: 0, RAM: 524288,
      SERIAL: "240ac40a-ef84",
      CONSOLE: "Serial1",
      MODULES: "Flash,Storage,hea" ... "r,crypto,neopixel",
      EXPTR: 1073484860 }
    >process.memory()
    ={ free: 2267, usage: 33, total: 2300, history: 10,
      gc: 0, gctime: 1.86 }
    >WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
    

    Code Testing:

    var ssid = "******";
    var password = "*****";
    var port = 80;
    var wifi = require('Wifi');
    console.log("started");
    wifi.connect(ssid, {password: password}, function() {
        console.log('Connected to Wifi.  IP address is:', wifi.getIP().ip);
        var http = require('http');
        http.get("https://www.google.com", function(res) {
          res.on('data', function(data) {
            console.log(data);
          });
        });
        // wifi.save(); // Next reboot will auto-connect
    });
    

    Full Error:

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v04 (c) 2019 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >started
    ERROR: Wifi: event_handler STA_START: esp_wifi_connect: 12298(SSID is invalid)
    WARNING: Wifi:startMDNS - espressif
    Connected to Wifi.  IP address is: 192.168.2.54
    Uncaught InternalError: Failed! mbedtls_ssl_setup: Not enough memory
     at line 13 col 6
        });
         ^
    in function called from system
    

    Any help will be appreciated

    Regards, pinnchus

  • Sat 2019.12.21

    Good morning @Pinnchus, while I've chosen not to provide support for non official supported boards, I commend you on the structure of your request. Providing that detail is what is necessary for others to grasp what is going on.

    In the mean time, some thoughts. . . .

    Is there any additional detail spelled out in the console dump?
    WebIDE >> Settings >> Console

    From the error 'mbedtls_ssl_setup' for memory requirements, I'm not sure https is supported for the ESP32. Could it be the 's' in L9?

    See forum post HTTPS on ESP32

    Are any of the other WiFi functions returning valid detail after L7 but before L8? I ran into a situation a year ago and the others walked me through that.

    See forum post STA or AP mode browser

    See forum post SSL on ESP32



    EDIT:
    Had an Espruino Wifi lying around to check for memory size/usage.

    The second 'Code Testing' snippet, while it doesn't run without error (it does when I strip out L7-L13 -- callback missing perhaps?), doesn't appear to use but a quarter of available memory. So should be good for the ESP32

    EDIT: See last snippet in this post #2 and note an add'l ~1000+ JsVars are required for the 'http' require section. So I retract the above last sentence. Most likely will fail.

    >process.memory()
    ={ free: 6543, usage: 605, total: 7148, history: 50,
      gc: 292, gctime: 7.61032104492, "stackEndAddress": 536991644, flash_start: 134217728, "flash_binary_end": 460040,
      "flash_code_start": 134283264, flash_length: 524288 }
    >
    
    >process.env
    ={
      VERSION: "2v04",
      GIT_COMMIT: "3956264e",
      BOARD: "ESPRUINOWIFI",
      FLASH: 524288, RAM: 131072,
      SERIAL: "3d003100-0b513532-39333638",
      CONSOLE: "USB",
      MODULES: "Flash,Storage,hea" ... ",neopixel,Wifi,AT",
      EXPTR: 536871212 }
    > 
    

    Did a quick sanity test using the first example at Connecting to an AP as run time errors occurred using the above snippet, and that ran without fail. Maybe the subtle code line differences will assist in locating the error in your particular case.

     2v04 (c) 2019 G.Williams
    >
    Connected!
    Response:  httpCRs: { "hdrs": true,
      "headers": {
        "Date": "Sat, 21 Dec 2019 15:55:20 GMT",
        "Server": "Apache/2.4.18 (Ubuntu)",
        "Last-Modified": "Fri, 15 Nov 2013 15:42:26 GMT",
        "ETag": "\"d-4eb390b887c80\"",
        "Accept-Ranges": "bytes",
        "Content-Length": "13",
        "Connection": "close",
        "Content-Type": "text/plain"
       },
      "cRcv": 0,
      "httpVersion": "1.1",
      "statusCode": "200",
      "statusMessage": "OK"
     }
    --->Hello World!
    > 
    



    EDIT:
    Remove L7 and it works on an Espruino Wifi

     2v04 (c) 2019 G.Williams
    >started
    Connected to Wifi
    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more
    . Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/goo­gleg_standard_color_128dp.png" itemprop="image"
    > 
    

    But, look at the usage

    >process.memory()
    ={ free: 5414, usage: 1734, total: 7148, history: 69,
      gc: 712, gctime: 8.23497772216, "stackEndAddress": 536991644, flash_start: 134217728, "flash_binary_end": 460040,
      "flash_code_start": 134283264, flash_length: 524288 }
    > 
    

    My S.W.A.G. guess is that the ESP32 doesn't have sufficient memory with less than ~400JsVars remaining for Espruino housekeeping. The Wifi has nearly three times. Maybe build a custom .hex to flash?

    also see post #6   SSL on ESP32
    ~600K+ data returned - won't fly

  • Getting ip address may need to be done with a callback... at least that was the case a while back under certain circumstances (independent processors... not like Espruino on ESP8266... and it may be the same in ESP32... (w/ Espruino on ESP8266 I have not much experience, w/ ESP32 none so far, and with Espruino paired w/ ESP8266 / CC3000 some). - Just looked .getIP() up at https://www.espruino.com/Reference#t_l_W­ifi_getIP - and you should be fine using it straight and not need to use the callback. But I though recommend two things:

    Put your (active) stuff into 'the' onInit(){ ...} function so it is not executed while your upload is still going on. You start the code then with entering onInt(); in the console... and if you get tired of it while developing, use my lazy trick and have the last line like this (after the onInit(){} function:

    
    Recommended code beginning w/ line 6 is something like that to catch errors (see https://www.espruino.com/Reference#l_Wif­i_connect ):
    
    

    wifi.connect(ssid, {password: password}, function(err) {
    if (err) {

    // do something w/ the error, like console.log(err) or throw err;
    

    } else {

    // move on with the 'good stuff'
    

    });
    ```

    You may think of an app watch dog to retry - deferred - what ever brings your app down or does not get it started...

    Did you consult forum conversation http://forum.espruino.com/conversations/­313576/ - HTTPS on ESP32?

    ...and yep, if your app eats away too much vars, that may be the problem...

  • https is not working on 2.04

    You have to build your own version, using less jsvars. However no details on how much to reduce the variables. See also: https://github.com/espruino/Espruino/iss­ues/1613

    I'll make a custom build, sooner or later, maybe end of this year. (Without the graphics library, without telnet and without ota.). And, if necessary for https, less jsvars.

  • Sat 2019.12.21

    Nice find @maze1980

    'no details on how much to reduce the variables'

    Starting to look like at least ~500-600 JsVars a good place to start. My S.W.A.G. response.

    @Pinnchus take a looksy at the Feb 12, 2019 post by @Wilberforce in the above link. Then in 2v01, 2300 JsVars were used, which as you'll realize is beyond the available memory for the device you are working with. :-(

  • Thanks for the answers, will try to compile with less jsvars.

  • Tried to reduce JSVARs by changing the 40,000 value in ...../targets/esp32/main.c (Did not find any other place to do it)

    static void espruinoTask(void *data) {
      int heapVars;
      PWMInit();
      RMTInit();
      SPIChannelsInit();
      initADC(1);
      jshInit();     // Initialize the hardware
      heapVars = (esp_get_free_heap_size() - 40000) / 16;  //calculate space for jsVars **** modified 40,000 to 60,000
      heapVars = heapVars - heapVars % 100; //round to 100
      if(heapVars > 20000) heapVars = 20000;  //WROVER boards have much more RAM, so we set a limit
      jsvInit(heapVars);     // Initialize the variables
      // not sure why this delay is needed?
      vTaskDelay(200 / portTICK_PERIOD_MS);
      jsiInit(true); // Initialize the interactive subsystem
      if(ESP32_Get_NVS_Status(ESP_NETWORK_WIFI­)) jswrap_wifi_restore();  
    [#ifdef](http://forum.espruino.com/searc­h/?q=%23ifdef) BLUETOOTH
      bluetooth_initDeviceName();
    [#endif](http://forum.espruino.com/searc­h/?q=%23endif)
      while(1) {
        jsiLoop();   // Perform the primary loop processing
      }
    }
    

    With little or not success, JSVARS reduced, but still not working.

    >process.memory()
    ={ free: 267, usage: 33, total: 300, history: 7,
      gc: 0, gctime: 0.388 }
    >WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v04.300 (c) 2019 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    >started
    ERROR: Wifi: event_handler STA_START: esp_wifi_connect: 12298(SSID is invalid)
    WARNING: Wifi:startMDNS - espressif
    Connected to Wifi.  IP address is: 192.168.2.54
    Uncaught InternalError: Not enough memory to allocate SSL socket
     at line 13 col 6
        });
         ^
    in function called from system
    >WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
    

    My be this is exceeding my knowledge, will wait for @maze1980 version.

    Thanks to all, for your efforts.

  • Well, if you can build your own firmware and do not need a filesystem than remove it

    https://github.com/espruino/Espruino/blo­b/master/boards/ESP32.py#L34

  • Mon 2019.12.23

    'Tried to reduce JSVARs by changing the 40,000 value in .....'

    My belief is that the understanding of what a JsVar really is, is well, . . . misunderstood.

    https://www.espruino.com/Internals

    From L2, the available memory 267 free blocks is an indication here as the board started with 2300 originally.

    As @MaBe is pointing out, it will be necessary to remove those sections of un-necessary code to allow the compiler to build a version that takes up less memory, than the one currently at release.

  • Or try removing bluetooth, if you don't use it. The buffer allocated to bluetooth is roughly 2000jsVars, so a pretty big one.
    Or, maybe just calling ESP32.enableBLE(false) frees up some heap as well. But this is just a guess...

  • HTTPS has been broken for ages no? -- since moving to recent versions of the ESP-IDF. The problem appears to be a lack of available heap memory. Either way there is an open github ticket still for it.

    https://github.com/espruino/Espruino/iss­ues/1613

    Would be great if it worked -- I'd dig out my ESP32s again.

    -hfc

  • Just as an after thought -- the issue might clear up if using a WROOM module with PSRAM. I believe in theory Espruino was updated to support it. The extra memory might be recognized and allocated correctly when doing TLS requests.

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

https esp32

Posted by Avatar for Pinnchus @Pinnchus

Actions