to test out writing using fs.pipe() on Espruino/8266 to the new file system enhancement. And I came across a strange problem -- at least for me. I may not be coding it right, and or it maybe a known problem I'm not aware of, though its happened on two boards now. So I thought I'd share it with you to get your feedback.
Basically with this code:
var http = require("http");
var wifi=require("Wifi");
var esp8266=require("ESP8266"); // for esp8266.printLog()
var page = "<html><head><title>test pipe</title><script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js\"></script></head><body><button id=\"getPage\">Reload Page</button><textarea rows=\"5\" cols=\"100\" id=\"Htmlfile\"></textarea></body><script>$(\"#getPage\").click(function(){$.get(\"/getPage\",function(data){$(\"#Htmlfile\").val(data);})});</script></html>";
function handleGet(req,res) {
console.log("handleGet() -> req");
console.log(req);
if (req.url=="/getPage" || req.url== "/") {
res.writeHead(200,{"Content-Type":"text/html"});
res.end(page);
} else {
res.writeHead(404);
res.end("404 Not Found");
}
}
function onPageRequest(req,res) {
console.log("onPageRequest() -> req");
console.log(req);
if(req.method == 'GET')
handleGet(req,res);
//else req.connection.destroy();
}
E.on("init", function () {
wifi.connect(wifi.getDetails().ssid, {password: wifi.getDetails().password}, function(err) {
if (err) {
console.log("Connection error: "+err);
return;
}
console.log("Connected!");
console.log(wifi.getIP());
server = http.createServer(onPageRequest);
server.listen(80);
});
});
After 7 to 9 sequential requests spaced by a few seconds (ie: pressing the button in the example), I would get a failure status in Chrome's developer tools and of course no data would be returned, as shown in the included screenshot. I was doing this manually (pressing the button), and made sure to wait until the requests had completed in the browser. If I pressed RELOAD in the browser (not the button in the html page), the 8266 would also fail to send anything, though interestingly it was still seeing the requests, as they would be "consoled" properly. Just nothing was returned.
If I waited 5 minutes or so, I could do it again another 7-9 times then it would fail. I suppose it could be a fun game if I had been drinking, but this was not the case. :) And I suppose the more practically minded of you would tell me just not to press it so often :P
So my first question is have I done anything visible wrong in my code? And then if not, can anyone replicate this? Or have any other ideas?
For what its worth, I have a few ESP8266s talking to each other (so 2-4) in another project, so we could imagine that this scenario would occur if some of the units made some requests quickly in sequence. So its something that could be seen "live" somewhere outside of this example, at least for me.
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.
Hello Everyone,
I was in the process of adapting some code from
http://forum.espruino.com/conversations/301910/
to test out writing using fs.pipe() on Espruino/8266 to the new file system enhancement. And I came across a strange problem -- at least for me. I may not be coding it right, and or it maybe a known problem I'm not aware of, though its happened on two boards now. So I thought I'd share it with you to get your feedback.
Basically with this code:
After 7 to 9 sequential requests spaced by a few seconds (ie: pressing the button in the example), I would get a failure status in Chrome's developer tools and of course no data would be returned, as shown in the included screenshot. I was doing this manually (pressing the button), and made sure to wait until the requests had completed in the browser. If I pressed RELOAD in the browser (not the button in the html page), the 8266 would also fail to send anything, though interestingly it was still seeing the requests, as they would be "consoled" properly. Just nothing was returned.
If I waited 5 minutes or so, I could do it again another 7-9 times then it would fail. I suppose it could be a fun game if I had been drinking, but this was not the case. :) And I suppose the more practically minded of you would tell me just not to press it so often :P
By including this line:
I could see easily that free memory almost always stayed between around 1400-1513.
After each failure esp8266.printLog shows something like this:
and another time:
So my first question is have I done anything visible wrong in my code? And then if not, can anyone replicate this? Or have any other ideas?
For what its worth, I have a few ESP8266s talking to each other (so 2-4) in another project, so we could imagine that this scenario would occur if some of the units made some requests quickly in sequence. So its something that could be seen "live" somewhere outside of this example, at least for me.
Thanks :)
-hfc
BTW: I'm using 1v91.741.
1 Attachment