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);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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 anend()
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:
The output is: