Avatar for barbiani

barbiani

Member since Mar 2018 • Last active Feb 2019
  • 12 conversations
  • 48 comments

Most recent activity

  • in ESP32
    Avatar for barbiani

    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!

  • in ESP32
    Avatar for barbiani

    Thank you.

    I am not good at regular expressions. A better solution would be to look for the content between quotes after 'filename=' (to also get filenames without extension), but at least we spotted a small bug.

  • in ESP32
    Avatar for barbiani

    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.

  • in JavaScript
    Avatar for barbiani

    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.

  • in JavaScript
    Avatar for barbiani

    @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.C­onnection.indexOf("Upgrade")){var f=b.headers["Sec-WebSocket-Key"];f=btoa(­E.toString(require("crypto").SHA1(f+"258­EAFA5-E914-47DA-95CA-C5AB0DC85B11")));d.­writeHead(101,{Upgrade:"websocket",Conne­ction:"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("c­lose",function(){clearInterval(g.srvPing­);g.srvPing=void 0;g.emit("close")});
    g.srvPing=setInterval(function(){g.emit(­"ping",!0);g.send("ping",137)},g.keepAli­ve);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);
                }
            }
    
  • in ESP32
    Avatar for barbiani

    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_d­rv: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
    > 
    
  • in ESP32
    Avatar for barbiani

    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");
        }
    
    • 3 comments
    • 95 views
Actions