Can i get HTTPS response back?

Posted on
  • Hi @Gordon and others,
    In my Espruino Pico, i'm requesting over https for a response and i get the following error message. Please help me on this. Thanks

    require("http").get("https://www.google.­com", function(res) {
       console.log("Response: ",res);
       res.on('data', function(d) {
       console.log("--->"+d);
       });
    });
    
    >Connecting with TLS...
    ERROR: Failed! mbedtls_ssl_setup: Not enough memory
    ERROR: Unable to create socket
    
  • process.memory()

    { "free": 3658, "usage": 1442, "total": 5100, "history": 1,
      "stackEndAddress": 536958120, "flash_start": 134217728, "flash_binary_end": 377416, "flash_code_start": 134234112, "flash_length": 393216 }
    
  • I'm afraid that's just an issue with HTTPS on the Pico - HTTPS uses a huge amount of RAM, and if your code is using too much then it can't allocate enough for a connection.

    If you're manually specifying keys and certificates, that can really hurt - so if you can just not specify them and leave them automatic it'd save you a bunch of RAM.

    Otherwise you could look at turning on minification and 'save on send' in the IDE options. Save on send writes data to Espruino in such a way that functions can be executed directly from Flash without having to use RAM.

  • @Gordon Thanks for the quick response.

    I don't have any SSL keys/certs in the code. I think, we don't need them for the retrieval of HTTPS doc. Right?

    Yes, i've approx. 80KB code that gets compressed into approx. 20KB while writing into the Pico. How much should the code size be to make it work?

    'Save on send' options says '.... not as memory efficient', Do you really want me to enable this?

  • I don't have any SSL keys/certs in the code. I think, we don't need them for the retrieval of HTTPS doc. Right?

    No, you shouldn't.

    Yes, i've approx. 80KB code

    Wow, yeah - that'd cause some out of memory issues then :)

    How much should the code size be to make it work?

    It totally depends. If you have just 100 bytes of code that allocates a huge array it'll be too much, but if your code it careful with memory then it should be ok.

    'Save on send' options says '.... not as memory efficient', Do you really want me to enable this?

    Yes, give it a go. Basically normal save() will compress the code that gets written, but because save on send is trying to execute straight from flash it can't compress anything. However on the Pico it's not such a big deal - you have 48kB of flash for saved code, so your 20kB should fit fine.

    However: to upload it, you still need enough free RAM to store all your code twice over (it's just how it works I'm afraid), so it could get quite tight if you're uploading much more than 20kB

  • Yes, give it a go. Basically normal save() will compress the code that gets written, but because save on send is trying to execute straight from flash it can't compress anything

    I did enable and corrupted my firmware, it took 2 hours to figure out why wasn't the IDE detecting the Espruino Pico :). Finally i flashed the firmware and it started detecting it.

    I brought down the file size to approx. 40KB, but the when i tried to write the code to Pico, it always says,

    Erasing Flash.....
    Writing..........................
    Compressed 81600 bytes to 23744
    Checking...
    Done!
    Running onInit()...
    

    Any idea, why doesn't it read as "40000 bytes to ...." ?

  • function onInit() {
          digitalWrite(LED1, 1);
    }
    
    save();
    

    Even saving the above code throws the below lines,

    Erasing Flash.....
    Writing.....
    Compressed 81600 bytes to 2705
    Checking...
    Done!
    Running onInit()...
    

    How/Why did it get "81600 bytes" when there is only a few bytes of code? Am i missing something that happens internally?

  • Ok, i brought down to 4KB file size. Still facing the same issue.

  • It sounds like you're typing save()?

    When you check 'Save on Send', it saves automatically when you click the upload button and there's no need to do a save() at all.

    A hardware reset or typing load() will cause everything to be loaded from flash.

  • Thanks, @Gordon
    Now that fixes the firmware corruption. But still get the memory issue for 4K code.

    Can you please tell me, how/why did it get "81600 bytes" when there is only a few bytes of code?

  • It always says 81600 bytes when you save, because that's how much RAM is dedicated to JS code.

    Espruino basically saves an image of RAM to Flash when you save(), so it saves all 81600 bytes as your code and variables could be anywhere within that memory space.

    What it does do is set all the unused RAM to 0, so it compresses down to virtually nothing - hence the compressed to text.

  • I've reduced the code to 18KB and things are normal now

About

Can i get HTTPS response back?

Posted by Avatar for sureshkm @sureshkm

Actions