You are reading a single comment by @user109783 and its replies. Click here to read the full conversation.
  • 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;
            }
          }
        }
    
About

Avatar for user109783 @user109783 started