You just need one of the latest builds - or the changes will be in 1v85 when it is released.
The trick is to store the variables in flash memory, and to then use memoryArea to reference them. You could probably load from a connected SD card too if you needed to.
The following code runs, with 1300 JsVars (out of 5100 total) free right in the middle of the HTTPS request, so there's actually a reasonable amount of space left over for your code, although not masses.
It looks like TLS/HTTPS takes around 3000 variables just to run, and potentially more when it's setting up a connection.
// The 128kB of flash memory on Pico that's not supposed to exist :)
var addr = process.memory().flash_start + process.memory().flash_length;
print("Address 0x"+addr.toString(16));
// flash memory module
var flash = require("Flash");
// Erase all data in that flash page
flash.erasePage(addr);
/* This writes data to flash, and returns a 'memoryArea' -
a reference to the actual bytes in flash*/
function fwrite(data) {
var len = data.length;
while (data.length&3) data+="\xFF";
var a = addr;
flash.write(data, addr);
addr += data.length;
return E.memoryArea(a,len);
}
// Load up the key, certificates, etc
var options = url.parse("https://192.168.1.50:443");
options.key = fwrite( atob("MIIEogIBAAKCAQEAwcBeteXIax0S+gNFv4f0K+q4LOv/E7kmiT8IvZl85NvUDF/slro/x/EreRMGmjcxoeT7+U62nrVu07lZhc+WAiluBX6Ykb2h7lJ/1M3MKV4uK5Yq92p1MxVXzYhVbCKBmcKrPu7Od+hLIMLIMTu0zwc23cE4tSUP4WV38BAzol3k9Rhd1MIjdZ3QUBTYYrvPveUv1TCdsQNsAGv5ZhJx57Anm52W7jTzwBw1O4cn31TD0KD3US/yDKL2IH7BSBFiadN5AzBJbh/ch16/aOfUBIlKNZf9LofMOVLxNm9hxpP2vgckl9u9nTtWiCR5EmKZaTqTqN7bsoLkNKR1GJ6yBwIBIwKCAQAQm3XVE7IXz0rE+PdZj09xeoTQpoOT+e1cOJpZZO1ys8G36vcFmu+GKp1ThUm1cnH37w5Ikbfht8erv24SyKZ1NsBJnSMFLYLoirp/9GH06tDB6EzTYOV5aDq52HxZudCYJqD2xAMRl5FpNURb/c2rWGPJ3Vyhz/oMAWINQzegM8in120G0ZmEnbdvdDWivWKJ4Ap1/fqiWr6yBLbG7gKnLkU3PksQG0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D4gElR8W4ypgvAw9pFKlSuOc4y6KS32jaOJk9zWSigPQadI1pOSSk+iKuPp98BBY/gDw+FBKUNARo3ci5F2s1dJZwQSCnuBhVb1r+3aHjnp4PAO7Mq7YyFf7qwSmuA++nF7TGhu3lf3hY1Jzgo+rOi+pFZtebCsewLDJjyNUxhQkOIf4TutC9wPJUtCKDpLA0iJso1AX5297iap5g7y0J0fUls16U+F0arsBHhgIN5ARifImeE+1bVVx7kLtklA23njczUt88ylgsCEnYyu0U+0+kwAkMDyPWDd3KPfDhykhQJ0Ev/44+JTDk3zydO2YvCpqMqLuhbZr9mvmV7uzJVbFnLr3sU75upv0N4JQLIn3XyTtDbWjTqA8d6qbG5BxYL5xkrWRxo3Fd6r1AyFje1ilKUkwZ1YZZCDvgv/2uEFyL0VlgfHfBhNbN2nsTTxijKc19ROeIRXl7eqWq/cyIbA/5LzEy2UbbEhKIroPGosQML4sc="));
// hey, let's just see how much memory we're using
print(process.memory().usage + " vars used");
// And connect to WiFi, then request the web page
digitalWrite(B9,1); // enable on Pico Shim V2
Serial2.setup(115200, { rx: A3, tx : A2 });
var wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect("Espruino","helloworld", function(err) {
if (err) throw err;
wifi.getIP(function(e,ip) {
console.log(ip);
require("http").get(options, function(res) {
console.log("Got response: " + JSON.stringify(res));
res.on('data', function(data) {
console.log(">" + data);
});
}).on("error", function(e) {
console.log("GOT ERROR: "+e);
});
console.log("Back to idle...");
});
});
});
Note: the key and certificate above work, but have been randomly generated. Please don't post keys/certificates that you intend on using in production up here :)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Finally, HTTPS on Pico with ESP8266 now works!
You just need one of the latest builds - or the changes will be in 1v85 when it is released.
The trick is to store the variables in flash memory, and to then use
memoryArea
to reference them. You could probably load from a connected SD card too if you needed to.The following code runs, with 1300 JsVars (out of 5100 total) free right in the middle of the HTTPS request, so there's actually a reasonable amount of space left over for your code, although not masses.
It looks like TLS/HTTPS takes around 3000 variables just to run, and potentially more when it's setting up a connection.
Note: the key and certificate above work, but have been randomly generated. Please don't post keys/certificates that you intend on using in production up here :)