-
I noticed that trying to connect to ESP_203D1D with my desktop computer makes espruino fail.
Happened as soon as I tried to connect:
abort() was called at PC 0x40084b1f on core 0
or the normal error we see:
E (36210) event: post event to user fail!
E (39052) event: post event to user fail!
E (41894) event: post event to user fail!
E (44737) event: post event to user fail! -
-
Hello everybody,
I am trying to match the second string between quotes and while it works fine on node.js it fails on espruino v1.99.
With the resources available on espruino, how else would you do it?
espruino 1.99: >/\w+\.\w+/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[0] ="me=\"file.txt" node.js: /\w+\.\w+/g.exec("form-data; name=\"file\"; filename=\"file.txt\"")[0] => 'file.txt'
v2.01 is broken too.
Thank you.
-
Thank you Gordon. I will give it a try.
I saw that the espruino tool is capable of placing a file in the storage area, but it seems that this is only for the original espruinos.
EDIT: It worked perfectly. Had to make 'var boundary = "";' else it would complain about it not having the .length property.
-
@Wilberforce
Were you ever able to to upload files to your espruino with the pipe?I am following your example, but I am not seeing the complete file save in the flash.
File index.htm size is 4752, printed POST data is "cRcv": 4752, but file in flash does not match.
I know that the problem is not in the filesystem, because using "multipart/form-data" on the form post I get the complete file... plus some added strings like this:
------WebKitFormBoundaryZ2Lus84JA68itxnM
Content-Disposition: form-data; name="file"; filename="index.html"
Content-Type: text/html...html file contents...
------WebKitFormBoundaryZ2Lus84JA68itxnM--
httpSRq: { "type": 1, "res": httpSRs: { }, "svr": httpSrv: { "type": 1, "#onconnect": function (b,d) {if(b.headers.Connection&&0<=b.headers.Connection.indexOf("Upgrade")){var f=b.headers["Sec-WebSocket-Key"];f=btoa(E.toString(require("crypto").SHA1(f+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")));d.writeHead(101,{Upgrade:"websocket",Connection:"Upgrade","Sec-WebSocket-Accept":f,"Sec-WebSocket-Protocol":b.headers["Sec-WebSocket-Protocol"]});var g=new e(void 0,{masking:!1,connected:!0});g.socket=d;b.on("data",g.parseData.bind(g));b.on("close",function(){clearInterval(g.srvPing);g.srvPing=void 0;g.emit("close")}); g.srvPing=setInterval(function(){g.emit("ping",!0);g.send("ping",137)},g.keepAlive);c.emit("websocket",g)}else a(b,d)}, "#onwebsocket": function (ws) {print(ws); ws.on('message', msg => { print("[WS] " + JSON.stringify(msg)); }); ws.on('close', evt => { print("[WS] CLOSED"); });}, "port": 80, "sckt": 4098 }, "sckt": 4099, "headers": { "Host": "192.168.25.8", "Connection": "keep-alive", "Content-Length": "4752", "Origin": "http://192.168.25.8", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.53 Safari/537.36", "DNT": "1", "Accept": "*/*", "Referer": "http://192.168.25.8/upload", "Accept-Encoding": "gzip, deflate", "Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,it;q=0.6,ja;q=0.5,es;q=0.4" }, "cRcv": 4752, "method": "PUT", "url": "/upload", "hdrs": true, "dRcv": "" }
>fs.statSync("upload") ={ "size": 3216, "dir": false, "mtime": Date: Mon Feb 1 2077 00:00:00 GMT+0000 }
if (a.pathname == "/upload") { print(req); if (req.method == "PUT") { try { fs.unlink(a.pathname); } catch (e) { } var f = E.openFile(a.pathname, "w"); req.pipe(f, { chunkSize: 512, end: false, complete: () => { f.close(); res.end(); } }); } else { res.writeHead(200, {'Content-Type':'text/html'}); res.end(html_index); } }
-
Hello,
I am seeing a message that I believe comes from the lower level wifi interface after espruino idles for a while.
wifi.connect(wifi_options.ssid, { password: wifi_options.password }, e => { print("WIFI: " + e); } ); wifi.on('connected', () => { print('WIFI:', wifi.getIP()); setTimeout(() => { httpServer(); }, 1000); }); wifi.on('disconnected', () => { print("WIFI: Reconnecting..."); setTimeout(() => { wifi.connect(wifi_options.ssid, {password: wifi_options.password}); }, 5000); });
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v01 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate > WARNING: Scan stop failed WARNING: set rssi scan not implemeted yet >ets Jun 8 2016 00:22:57 rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:2588 load:0x40078000,len:7192 load:0x40080000,len:5288 entry 0x40080278 E (28) boot: ota data partition invalid, falling back to factory E (517) spiram: SPI RAM enabled but initialization failed. Bailing out. WARNING: Wifi:startMDNS - espressif WIFI: null WIFI: { "ip": "192.168.25.8", "netmask": "255.255.255.0", "gw": "192.168.25.1", "mac": "84:0d:8e:20:3d:1c" } >Date.now() =16948.5 { "method": "GET", "host": "", "path": "/", "pathname": "/", "search": null, "port": null, "query": null } >E (56743709) event: post event to user fail! E (56746550) event: post event to user fail! E (56749390) event: post event to user fail! E (56752231) event: post event to user fail! WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WIFI: Reconnecting... WARNING: Wifi:startMDNS - espressif WARNING: Wifi:stopMDNS WIFI: { "ip": "192.168.25.8", "netmask": "255.255.255.0", "gw": "192.168.25.1", "mac": "84:0d:8e:20:3d:1c" } ERROR: Socket listen failed Uncaught InternalError: Unable to create socket at line 3 col 17 server.listen(80) ^ in function "httpServer" called from line 1 col 12 httpServer() ^ in function called from system { "method": "GET", "host": "", "path": "/", "pathname": "/", "search": null, "port": null, "query": null } WIFI: Reconnecting... WARNING: Wifi:startMDNS - espressif WARNING: Wifi:stopMDNS WIFI: { "ip": "192.168.25.8", "netmask": "255.255.255.0", "gw": "192.168.25.1", "mac": "84:0d:8e:20:3d:1c" } ERROR: Socket listen failed Uncaught InternalError: Unable to create socket at line 3 col 17 server.listen(80) ^ in function "httpServer" called from line 1 col 12 httpServer() ^ in function called from system >
-
Ha! Thank you. I used the forum search for "openfile" without results ;(
Here is one solution to help other users.
It fixes the heap leak, but still eventually fails to open the file.
var f = E.openFile(a.pathname, "r"); if (f !== undefined) { // File open succeeded - send it! res.writeHead(200, {'Content-Type': 'text/plain'}); f.pipe(res, {chunkSize: 512, complete: f.close}); } else { // couldn't open file res.writeHead(404, {'Content-Type': 'text/plain'}); res.end("404: Page "+a.pathname+" not found"); }
-
Hello everybody,
I am experimenting a bit with the http server (espruino versions from 1.99) and this snippet works most of the time.
First time the page is opened it shows the files in the system as hyperlinks. Downloading a file many times breaks the code.
I´ve found that calling E.openFile many times in the left webide pane makes it fail too. No examples show a close method after openFile, so I believe that it is not needed.
Am I doing it wrong?
>fs.readdir() =[ "xx.txt" ] >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 1857, "usage": 643, "total": 2500, "history": 239, "gc": 0, "gctime": 1.839 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 1592, "usage": 908, "total": 2500, "history": 242, "gc": 0, "gctime": 1.669 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 1327, "usage": 1173, "total": 2500, "history": 242, "gc": 0, "gctime": 1.5 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 1062, "usage": 1438, "total": 2500, "history": 242, "gc": 0, "gctime": 1.345 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 797, "usage": 1703, "total": 2500, "history": 242, "gc": 0, "gctime": 1.159 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 532, "usage": 1968, "total": 2500, "history": 242, "gc": 0, "gctime": 0.997 } >E.openFile("xx.txt"); =File: { } >process.memory() ={ "free": 267, "usage": 2233, "total": 2500, "history": 242, "gc": 0, "gctime": 0.828 } >E.openFile("xx.txt"); =undefined >E.openFile("xx.txt"); =undefined >
var fs = require("fs"); try { fs.readdirSync(); } catch (e) { console.log('Formatting FS - only need to do once'); E.flashFatFS({ format: true }); fs.writeFileSync("xx.txt", ".."); } function onPageRequest(req, res) { var a = url.parse(req.url, true); print(a); if (a.pathname.substr(-1)=="/") { // a slash at the end, list the directory res.writeHead(200, {'Content-Type': 'text/html'}); res.write("<html><body><p>Contents of "+a.pathname+"</p><ul>"); fs.readdir().map(function(f) { res.write('<a href="'+f+'">'+f+'</a>'); }); res.end("</ul></body></html>"); } else { // No slash, try and open file var f = E.openFile(a.pathname, "r"); if (f !== undefined) { // File open succeeded - send it! res.writeHead(200, {'Content-Type': 'text/plain'}); f.pipe(res); // streams the file to the HTTP response } else { // couldn't open file res.writeHead(404, {'Content-Type': 'text/plain'}); res.end("404: Page "+a.pathname+" not found"); } } }
-
-
-
This is what I use
function wifiConnect() { wifi = require('Wifi'); wifi.connect(wifi_options.ssid, { password: wifi_options.password }, (e)=> { if (e) { print("WIFI: " + e); } }); wifi.on('connected', ()=> { print('WIFI:', wifi.getIP()); }); wifi.on('disconnected', ()=> { print("WIFI: Reconectando..."); wifi.connect(wifi_options.ssid, {password: wifi_options.password}); }); }
-
-
Looks like the original esp32 port used RMT then changed to the Espruino style. I wonder why.
@Gordon Can the timer functions be used with or changed to use the floating point delay to achieve sub ms timing?
Sub millisecond would only make sense in the digitalPulse function, because I see that:
setInterval(()=> { D5.toggle(); }, 5);
Gives a high pulse from 3.6 to 7ms.
-
-
-
Hello @allObjects,
Is it useable as it is? It is certainly cool to use signaling from external chips.
-
-
...quite an impressive advancement in just over a week. Be careful, as at this rate, you may be teaching the class you are about to take!!
Actually js is not too far from C. What I find hard to digest is .NET with its amount of reserved words.
@Robin You know that I am not writing these from scratch, right? I am taking many samples and figuring out what and how each thing does what it does. The rest is finding the hundreds of variable fields available on each element. Like the < select > < option > set() function from js that is still missing in the dash.
...The simple explanation is to maintain alignment to ensure valid Html is being coded, typically to locate closing elements in a tag set.
I am not used to read html anyway... so it does not make a big difference to me. I was only following the original sources style.
-
This is an attempt to create a dropdown menu.
HTML:
d: TD.dropdown({ x: 10, y: 505, width: 200, height: 25, label: "A dropdown", name: "dropdown", items: ["Link 1", "Link 2", "Test entry"], onchange: function(e, v) { console.log(e + " " + v); ws.send(JSON.stringify(e)); } }),
css:
.td_dropdown { -webkit-appearance: none; background: var(--forecolor); } .td_dropdown select { background-color: var(--forecolor); color: [#fff](https://forum.espruino.com/search/?q=%23fff); font-size: 16; border: 0; border-radius: 3px; width: 100%; height: 100%; text-overflow: ''; padding-right: 1.25em; } .td_dropdown select option { font-size: inherit; text-align: center; } .td_dropdown select::-ms-expand { /*Hiding the select arrow for IE10*/ display: none; }
js:
TD.dropdown = function(opts) { function a(arr) { var txt = ""; arr.forEach(function(item, indice, array) { txt += `<option value="${item}">${item}</option>`; }); return txt; } var el = setup("dropdown", opts, toElement(`<div class="td"><span class="td_dropdown"><select name="${opts.name}">${a(opts.items)}</select></span></div>`)); document.addEventListener('DOMContentLoaded', function() { document.querySelector('select[name="'+opts.name+'"]').onchange = function(x) { sendChanges(el, x.target.value); }; }, false); el.setValue = function(v) { }; return el; };
-
Here is a new css button class.
.td_button { margin-top: 10px; margin-left: auto; margin-right: 10px; /* centered */ display: inline-block; padding: 6px 16px; font-size: 24px; font-weight: bolder; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: [#fff](https://forum.espruino.com/search/?q=%23fff); background-color: [#4CAF50](https://forum.espruino.com/search/?q=%234CAF50); border: none; border-radius: 15px; box-shadow: 0 4px #888; -webkit-transition-duration: 0.2s; /* Safari */ transition-duration: 0.2s; overflow: hidden; cursor: pointer; } .td_button:active { background-color: [#4CAF50](https://forum.espruino.com/search/?q=%234CAF50); box-shadow: 0 0px #888; transform: translateY(4px); } .td_button:hover { background-color: [#06B](https://forum.espruino.com/search/?q=%2306B); }
/* {label, glyph, value, toggle}*/ TD.button = function(opts) { var pressed = opts.value ? 1 : 0; opts.glyph = opts.glyph || "💡"; var el = setup("button", opts, toElement(`<div align="right" class="td td_btn" pressed="${pressed}"><span>${opts.label}</span><div class="td_button">${opts.glyph}</div></div>`)); el.getElementsByClassName("td_button")[0].onclick = function() { togglePressed(el); }; el.setValue = function(v) { el.pressed = v ? 1 : 0; el.setAttribute("pressed", el.pressed); }; return el; };
-
Hello everybody,
In continuation of another thread: http://forum.espruino.com/conversations/327325/#comment14492142
I am working my way on learning html+css+js while improving tinydash.
Got initially a scrollbar running and generating events.
The look is not compatible with the other widgets yet.
What would be the correct/best way to center the bar... < center > html tag or css?
add to tinydash.css:
.td_slider_container { width: 100%; } .td_slider { -webkit-appearance: none; width: 90%; height: 15px; border-radius: 8px; background: [#d3d3d3](https://forum.espruino.com/search/?q=%23d3d3d3); outline: none; opacity: 0.7; -webkit-transition: .2s; transition: opacity .2s; } .td_slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 25px; height: 25px; border-radius: 50%; background: [#4CAF50](https://forum.espruino.com/search/?q=%234CAF50); cursor: pointer; } .td_slider::-moz-range-thumb { width: 25px; height: 25px; border-radius: 50%; background: [#4CAF50](https://forum.espruino.com/search/?q=%234CAF50); cursor: pointer; } /* Mouse-over effects */ .td_slider:hover { opacity: 1; /* Fully shown on mouse-over */ }
add to tinydash.js:
/* {slider} */ TD.slider = function(opts) { var el = setup("slider", opts, toElement('<div class="td td_slider_container"><span>' + opts.label + '</span><center><br><br><input type="range" min="' + opts.min + '" max="' + opts.max + '" value="' + opts.value + '" class="td_slider"</center></br></br></div>')); el.setValue = function(v) { el.setAttribute("value", v); }; el.oninput = function(x) { sendChanges(el, x.srcElement.value); }; return el; };
-
I tried tinydash minified and obfuscated :) It works.
The stepping bug fix is a simple line swap where it must first set the widget value and then send. It was sending before!
I found a html+css+js course opening in mid january and got enrolled on it. For now I will be on my own figuring out the js capabilities.
Today I stepped on this:
https://scotch.io/bar-talk/a-new-code-editor-for-the-webContinues here: http://forum.espruino.com/conversations/327568/
Add a RC filter to those buttons. It will help reducing interrupts.