Avatar for user109783

user109783

Member since Feb 2020 • Last active Mar 2020
  • 11 conversations
  • 18 comments

Most recent activity

  • in Other Boards
    Avatar for user109783

    I want to use Storage to cache datas.

    After the some times, I always get the fix length data which I write very early.
    I want to know that do Storage can overwirte the old datas when I user write("",""). Otherwise, why I always read the very first datas? And the data length is always 38.

    console.log("iiiiiiiiiiiiiiiiiiiiiiiiiii­iii_1", JSON.stringify(cac))

      let cac = st.read("http");
      console.log("iiiiiiiiiiiiiiiiiiiiiiiiiii­iii_0", JSON.stringify(line))
      console.log("iiiiiiiiiiiiiiiiiiiiiiiiiii­iii_1", JSON.stringify(cac))
      if (cac) {
        line = line.substr(line.indexOf(tar_flag) + tar_flag.length);
        console.log("iiiiiiiiiiiiiiiiiiiiiiiiiii­iii_2", JSON.stringify(line))
      }
      cac += line;
      console.log("iiiiiiiiiiiiiiiiiiiiiiiiiii­iii_3", JSON.stringify(cac))
      st.write("http", cac);
    

    st.getFree()
    =248900

  • in Other Boards
    Avatar for user109783

    I ran code in STM32F4DISCOVERY board.

    I use Event on for listening the 4G Sim。If the Http Response is a little datas, it work well. But If the Response is relatively much more data, this error will happen.

    In the code, the variable line will receive data as much as the http return.

    How do I avoid this error?

    The main code like this:

    uart.on("data", function cb(d) {
        line += d;
        if (line.startsWith("\r\n")) {
          line = line.substr(2);
        }
        if (line[0] === "\n") {
          line = line.substr(1);
        }
        if (line[0] === "\r") {
          line = line.substr(1);
        }
        if (line[0] === "\u00FF") {
          line = line.replace("\u00FF", "");
        }
        if (line.length > 0) {
          for (let h in lineHandlers)
            if (line.indexOf(h) > -1) {
              line = lineHandlers[h](line.substr(line.indexOf­(h)));
            }
        }
        if (handlers) {
          for (let h in handlers) {
            while (line.substr(0, h.length) === h) {
              let resp = handlers[h](line);
              if (resp) {
                line = resp;
              } else {
                line = "";
              }
              return;
            }
          }
        }
    
  • in Other Boards
    Avatar for user109783

    This is the request message

    GET /hello.txt HTTP/1.1
    User-Agent: Espruino 2v04.401
    Connection: close
    Host: http://www.pur3.co.uk

    And this is the response message

    RECV FROM:93.93.135.13:80
    +IPD259
    HTTP/1.1 200 OK
    Date: Wed, 25 Mar 2020 02:30:54 GMT
    Server: Apache/2.4.18 (Ubuntu)
    Last-Modified: Fri, 15 Nov 2013 15:42:26 GMT
    ETag: "d-4eb390b887c80"
    Accept-Ranges: bytes
    Content-Length: 13
    Connection: close
    Content-Type: text/plain
    Hello World!
    +IPCLOSE: 0,1

    I tried to put debuggers in two places. In this place, I can't reach the debugger 2.

         debugger;  // 1
        http.get("http://www.pur3.co.uk/hello.tx­t", function(res) {
          debugger;  //2
          let str = ''; 
          res.on('data', chunk => {
            console.log("chunk",chunk);
            str += chunk;
          });
          res.on('end', () => {
            console.log("Get some test request contents: --->   ", str);
          });
        });
    

    And the second place here:

    recv: function (sckt, maxLen) {
        if (sockData[sckt]) {
          console.log("ddddddddddddddd",sockData[s­ckt])
          var r;
          console.log("recv", sockData[sckt].length);
          if (sockData[sckt].length > maxLen) {
            r = sockData[sckt].substr(0, maxLen);
            sockData[sckt] = sockData[sckt].substr(maxLen);
            console.log("recv", sockData[sckt]);
          } else {
            r = sockData[sckt];
            sockData[sckt] = "";
            console.log("recv | socks[sckt]", socks[sckt]);
            if (socks[sckt] == "DataClose") {
              dbg("Got DataClose - forcing close");
              socks[sckt] = "closing";
            }
          }
          console.log("[recv data]", r);
          debugger; // 3
          return r;
        }
        if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it
        return "";
      },
    

    I can reach debugger 3. And then where the code goes puzzle me so much! What's the relation between Http.get() and recv()?

    debug>step

              return r;
              ^
    

    debug>step
    Value returned is ="Hello World!"

  • in Other Boards
    Avatar for user109783

    The code

    console.log("back from network?",res)
    didn't print anything.

    tp.get("http://www.pur3.co.uk/hello.txt"­, function (res) {
         console.log("back from network?",res)
          let str = ''; 
          res.on('data', chunk => {
            console.log("chunk",chunk);
            str += chunk;
          });
          res.on('end', () => {
            console.log("result: --->   ", str);
          });
        });
    

    In the Mehtod recv(), I did got datas and retruned them. But where these datas go I really don't know, and how do they go back to http.get response body?

    console.log("[recv data]", r)

    return r;
    
  • in Other Boards
    Avatar for user109783

    Now I use a SIM7600CE for 4G connection. The modules didn't adapt for this kind of sim card.
    So I have to write my own module for it.

    Now I can get response datas in this Method:

    recv: function (sckt, maxLen) {
        if (sockData[sckt]) {
          var r;
          console.log("recv", sockData[sckt].length);
          if (sockData[sckt].length > maxLen) {
            r = sockData[sckt].substr(0, maxLen);
            sockData[sckt] = sockData[sckt].substr(maxLen);
            console.log("recv", sockData[sckt]);
          } else {
            r = sockData[sckt];
            sockData[sckt] = "";
            console.log("recv | socks[sckt]", socks[sckt]);
            if (socks[sckt] == "DataClose") {
              dbg("Got DataClose - forcing close");
              socks[sckt] = "closing";
            }
          }
          console.log("[recv data]", r)
          return r;
        }
        if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it
        return "";
      },
    

    I think this part is the place where return datas to http.get().
    But I can't recieve any datas in this place.
    Do you have any introductions about how the datas flow in the network?

    http.get("http://www.pur3.co.uk/hello.tx­t", function (res) {
          let str = ''; 
          res.on('data', chunk => {
            console.log("chunk",chunk);
            str += chunk;
          });
          res.on('end', () => {
            console.log("result: --->   ", str);
          });
        });
    
  • in Other Boards
    Avatar for user109783

    Sometimes I want the update codes by METHOD load(), and use HTTP to download new codes and eval("new codes"). But it always crashed. Especially when I use serval setInterval() in code.

    When I invoke load() in code, it still have the past codes in the RAM. Is it possible to refresh codes by codes? How can I clean RAM datas, or the garbage?

    ERROR: Ctrl-C while processing interval - removing it.
    Execution Interrupted during event processing.
    New interpreter error: CALLBACK,MEMORY
    ERROR: Ctrl-C while processing interval - removing it.
    ERROR: Ctrl-C while processing interval - removing it.
    Execution Interrupted during event processing.
    ERROR: Ctrl-C while processing interval - removing it.
    Execution Interrupted during event processing.
    MQTT disconnected... reconnecting.
    ERROR: No free sockets found

Actions