You are reading a single comment by @tve and its replies. Click here to read the full conversation.
  • I'm having a problem with http / sockets on the esp8266 that falls into the "how can this possibly be?" category at the moment. I have a little test program that issues a POST request every 200ms and after a few hundred requests the object returned by http.request ends up not having an end() function! The end function is part of the prototype, if I understand correctly, so that must get messed-up somehow? I'm looking for some guidance about what to try, where to insert checks, etc.
    The same test program runs fine on linux, so either there is timing involved or something somewhere else in the esp8266 implementation that is messing JSvars up, at this point I don't understand what kind of messing up I should even be looking for...

    The test program is:

    var postUrl = "http://h.voneicken.com:4567/temp";
    
    var http = require("http");
    
    var int1, int2;
    
    var errCnt = 0;
    var okCnt  = 0;
    
    function sendTemp(temp) {
      var q = url.parse(postUrl + "?temp=" + temp);
      q.method = "POST";
      q.headers = {'Content-Length': 0};
      //console.log("REQ:", q);
      var req = http.request(q, function(resp) {
        resp.on('data', function(d) { if (d !== 'OK') console.log("Got unexpected response:", d); });
        resp.on('close', function(gotErr) {
          if (!gotErr && resp.statusCode !== "200") console.log("Got HTTP code", resp.statusCode);
          if (gotErr || resp.statusCode !== "200") errCnt++; else okCnt++;
        });
        resp.on('error', function(err) { console.log("HTTP response error: ", err.message); });
      });
      req.on('error', function(err) { console.log("HTTP request error: ", err.message); errCnt++; });
      req.on('close', function(gotErr) { console.log("HTTP done"); });
      if (typeof req.end === 'function') {
        req.end();
      } else {
        console.log("OOPS, no end function:", req);
        trace(req);
        clearInterval(int1);
        clearInterval(int2);
      }
    }
    
    var t = 10.0;
    int1 = setInterval(function(){sendTemp(t); t+=0.01;}, 200);
    int2 = setInterval(function(){console.log("*** OK:"+okCnt, "ERR:"+errCnt, process.memory());}, 10000);
    

    The output is:

    *** OK:49 ERR:0 { "free": 722, "usage": 301, "total": 1023, "history": 129 }
    *** OK:99 ERR:0 { "free": 722, "usage": 301, "total": 1023, "history": 129 }
    *** OK:149 ERR:0 { "free": 722, "usage": 301, "total": 1023, "history": 129 }
    *** OK:199 ERR:0 { "free": 722, "usage": 301, "total": 1023, "history": 129 }
    *** OK:249 ERR:0 { "free": 722, "usage": 301, "total": 1023, "history": 129 }
    OOPS, no end function: { "type": 1,
      "#onconnect": function (resp) {resp.on("data",function(d){if(d!=="OK")­console.log("Got unexpected response:",d)});resp.on("close",function­(gotErr){if(!gotErr&&resp.statusCode!=="­200")console.log("Got HTTP code",resp.statusCode);if(gotErr||resp.s­tatusCode!=="200")errCnt++;else okCnt++});resp.on("error",function(err){­console.log("HTTP response error: ",err.message)})},
      "res": {  },
      "opt": {
        "protocol": "http:",
        "method": "POST",
        "host": "h.voneicken.com",
        "path": "/temp?temp=12.54",
        "pathname": "/temp",
        "search": "?temp=12.54",
        "port": 4567,
        "query": "temp=12.54",
        "headers": { "Content-Length": 0 }
       },
      "#onerror": function (err) {console.log("HTTP request error: ",err.message);errCnt++},
      "#onclose": function (gotErr) {console.log("HTTP done")}
     }
    
About

Avatar for tve @tve started