-
I can confirm espruino for Linux compiles and runs on ubuntu on windows 10. It's great for testing things like websockets and using the filesystem code as you can edit the files from within windows and have them change in the windows sub-system.
I also build the esp32 code within the sub-system - it's easier than starting a virtual machine that uses more resources.
-
-
It fails on all pins after a while. It used to work, but it seems that recent timer changes might have effected the Irq handling on gpios. We have a similar crash with pin pulse too...
All a work in progress.. @JumJum and I are the only ones looking at this - and this is in our spare time.
-
This is a known issue...
https://github.com/espruino/Espruino/issues/1176
Using D0 - the inbuilt flash button, it does not crash straight away. I suspect a stsck issue, but so far increasing the stsck size has had no effect..
-
-
I just had a similar situation with an ESP32 and 2 one wire devices using a breadboard.
A search would show the codes:
var ow = new OneWire(D23); var sensors = ow.search().map(function (device) { return require("DS18B20").connect(ow, device); });
=[ { "bus": OneWire { "pin": D23 }, "sCode": "28cc2e230500006b", "type": 28 }, { "bus": OneWire { "pin": D23 }, "sCode": "283260dc04000001", "type": 28 } ]
however - the reads failed. It turns out the pins were not seated properly - enough to get the ROM code, but not enough for a reading.
var model = { temp: [50,50] }; function readTemps() { sensors.forEach(function (sensor, index) { model.temp[index]=sensor.getTemp(); console.log(model); }); }
-
Hi @user80339,
The FileSystem libraryfs
was updated to throw errors, so that these could be caught (It used to just output a warning when the docs were written)I have updated the docs, your code needs to look like this:
try { fs.readdirSync(); } catch (e) { //'Uncaught Error: Unable to mount media : NO_FILESYSTEM' console.log('Formatting FS - only need to do once'); E.flashFatFS({ format: true }); } fs.writeFileSync("hello.txt", "Hello World"); console.log(fs.readFileSync("hello.txt")); // prints "Hello World" fs.appendFileSync("hello.txt", "!!!"); console.log(fs.readFileSync("hello.txt")); // prints "Hello World!!!"
If the filesystem is attempted to be read and can't, then the filesystem is created.
Please note that this only needs to occur once. If the flash memory is erased, them you will need to format again.
The try/catch above prevents
E.flashFatFS({ format: true });
from erasing your files. -
-
-
-
@Gordon
Thanks very much Gordon for your help!I have added the
ws.on('close')
and confirmed it works, and also rebuilt with your fix and confirmed that throws an error too!When you mentioned
quit()
above - that does not work in the left side of ide - where do you use this? -
-
Thanks for the reply..
In chrome on the receiving end of the web socket, I can see the json packets coming in 106 bytes at a time, so they are getting sent once... so I wonder if this is a bug related to the fact that the websocket does not close, so the current data gets added to the queue, the most recent addition gets sent, but because the socket is not closed, the queue keeps on growing. Probably not explained myself very well!
I'll have to try the quit() tomorrow..
-
Here is the code (which won't run in isolation) as it requires files too...
var model = { setpoint : 66, timer : 60, temp: [50,50] // counter : 3600 }; var event_cb = { timer : function (t) { model.counter = t * 60; } }; event_cb.timer(model.timer); function tick() { var d = new Date(model.counter * 1000); model.counterstr = d.toString().split(' ')[4]; model.counter -= 1; model.free=process.memory().free; model.usage=process.memory().usage; } setInterval(tick, 1000); function onPageRequest(req, res) { var a = url.parse(req.url, true); /**/ // console.log(a); console.log({sckt:req.sckt}); console.log(req.headers); //console.log(req.method); /**/ var file = a.pathname; if (file == '/') { file = '/index.htm'; } var headers = {}; if (req.method == 'PUT') return put_file(req, res); var f; try { f = E.openFile('www' + file, "r"); } catch (e) { // look for compressed try { f = E.openFile('www' + file + '.gz', "r"); headers['Content-Encoding'] = 'gzip'; } catch (e) { console.log('no file' + file); } } if (f !== undefined) { var mime = 'text/html'; if (file.substr(-2) == 'js') mime = 'application/javascript'; if (file.substr(-3) == 'css') mime = 'text/css'; if (file.substr(-3) == 'ico') mime = 'image/vnd.microsoft.icon'; headers['Content-Type'] = mime; res.writeHead(200, headers); console.log('started:' + file ); f.pipe(res, { chunkSize : 512, end : false, complete : function () { console.log("Complete:" + file); f.close(); res.end(); } }); } else { res.writeHead(404, { 'Content-Type' : 'text/plain' }); res.end("404: Page " + a.pathname + " not found"); } } var server = require('ws').createServer(onPageRequest); var update_model=false; server.on("websocket", function (ws) { ws.on('message', function (msg) { //console.log((msg)); var data = JSON.parse(msg); console.log(data); if ( update_model ) { for (var o in data) { //console.log( o, data[o] ); model[o] = data[o]; if (event_cb.hasOwnProperty(o)) { event_cb[o](data[o]); } } } }); function send_model() { var s=JSON.stringify(model); ws.send(s); s=null; } setInterval(send_model, 1000); }); function start() { server.listen(8080); } start();
-
This is running on the linux version of espurino, and will apply to other boards too.
It looks like the dSnd part of the underyling socket is growing each second evert time the
model
is updated...I've tried to do a simplier use case, but have not yet got a simple case working, so I'll just post what I have so far...
the output of
trace()
shows the dSnd string getting larger each iteration...>trace(); #1[r2,l1] Object { #2[r1,l2] Name String [1 blocks] "\xFF" #3[r1,l2] Object { #6[r1,l2] Name String [1 blocks] "timers" #7[r2,l1] Array(8) [ #382[r1,l2] Name Integer 1 #378[r1,l1] Object { #380[r1,l2] Name String [1 blocks] "time"= int 705003 #381[r1,l2] Name String [1 blocks] "interval"= int 1000000 #379[r1,l2] Name String [1 blocks] "callback" #358[r2,l1] ... } #834[r1,l2] Name Integer 3 #830[r1,l1] Object { #819[r1,l2] Name String [1 blocks] "time"= int 693088 #820[r1,l2] Name String [1 blocks] "interval"= int 1000000 #803[r1,l2] Name String [1 blocks] "callback" #890[r2,l1] Function { #867[r1,l2] Name String [1 blocks] "\xFFcod" #1006[r1,l1] FlatString [3 blocks] "var s=JSON.stringify(model);\n ws.send(s);\n s=null;" #779[r1,l2] Name String [1 blocks] "\xFFsco" #847[r2,l1] Function { #781[r1,l2] Name Param "ws" #926[r1,l1] Object { #927[r1,l2] Name String [2 blocks] "__proto__" #151[r4,l1] ... #951[r1,l2] Name String [1 blocks] "socket" #945[r1,l1] Object { #944[r1,l2] Name String [2 blocks] "__proto__" #394[r4,l1] ... #863[r1,l2] Name String [1 blocks] "dSnd" #5[r1,l1] String [1171 blocks] "\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5373,\"counterstr\":\"01:29:34\",\"free\":3415,\"usage\":681}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5373,\"counterstr\":\"01:29:34\",\"free\":3415,\"usage\":681}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5400,\"counterstr\":\"01:29:33\",\"free\":3238,\"usage\":858}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5399,\"counterstr\":\"01:30:00\",\"free\":3234,\"usage\":862}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5398,\"counterstr\":\"01:29:59\",\"free\":3229,\"usage\":867}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5397,\"counterstr\":\"01:29:58\",\"free\":3225,\"usage\":871}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5396,\"counterstr\":\"01:29:57\",\"free\":3220,\"usage\":876}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5395,\"counterstr\":\"01:29:56\",\"free\":3216,\"usage\":880}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5394,\"counterstr\":\"01:29:55\",\"free\":3211,\"usage\":885}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5393,\"counterstr\":\"01:29:54\",\"free\":3207,\"usage\":889}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5392,\"counterstr\":\"01:29:53\",\"free\":3202,\"usage\":894}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5391,\"counterstr\":\"01:29:52\",\"free\":3198,\"usage\":898}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5390,\"counterstr\":\"01:29:51\",\"free\":3193,\"usage\":903}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5389,\"counterstr\":\"01:29:50\",\"free\":3189,\"usage\":907}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5388,\"counterstr\":\"01:29:49\",\"free\":3184,\"usage\":912}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5387,\"counterstr\":\"01:29:48\",\"free\":3180,\"usage\":916}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5386,\"counterstr\":\"01:29:47\",\"free\":3175,\"usage\":921}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5385,\"counterstr\":\"01:29:46\",\"free\":3171,\"usage\":925}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5384,\"counterstr\":\"01:29:45\",\"free\":3166,\"usage\":930}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5383,\"counterstr\":\"01:29:44\",\"free\":3162,\"usage\":934}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5382,\"counterstr\":\"01:29:43\",\"free\":3157,\"usage\":939}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"counter\":5381,\"counterstr\":\"01:29:42\",\"free\":3153,\"usage\":943}\x81j{\"setpoint\":66,\"timer\":\"90\",\"temp\":[50,50],\"countermore.. ....
-
-
-
-
-
@hungryforcodes
thisload()
issue has been seen before - @MaBe might recall and have some input. -
@hungryforcodes - ok - get your point after a flash erase.
This is a bit odd - searching the sources for that error message - no ESP8266 sources come up:
https://github.com/espruino/Espruino/search?utf8=%E2%9C%93&q=Not+connected+to+the+internet&type=
So if the "Modules uploaded as functions" is left off - everything works as usual?
If that is the case it looks like the addition of this feature has changed the start up initialisation order and wifi does not get initialised?
Congratulations- well done and all the best to you and your family.