Found the bug
It was in the Get section of the code. I know the light was better in the POST code:)
File Server Example http://www.espruino.com/http_file_server
switch (ext){
case "html":
res.writeHead(200, {'Content-Type': 'text/HTML'});
f.pipe(res); // streams the file to the HTTP response
break;
Notice that in the example fileserver code and my program there is no res.end().
Both produce an obscure error:
Uncaught Error: Expecting a function to call, got Number
By changing the program as follows:
case "html":
res.writeHead(200, {'Content-Type': 'text/HTML'});
f.pipe(res,{chunkSize:4096,end:true,complete:res.end()}); // streams the file to the HTTP response
break;
The error goes away. I first tried 512 instead of 4096 and only got a partial load of my HTML file. The 4096 is the length of the HTML file. Does the chunkSize parameter need to be the file length?
So now the POST code req.on('data') works.
var pdata="";
function onPageRequest(req, res) {
var a = url.parse(req.url, true);
req.on("data", function(d) {pdata+=d;});
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.
Found the bug
It was in the Get section of the code. I know the light was better in the POST code:)
File Server Example
http://www.espruino.com/http_file_server
Notice that in the example fileserver code and my program there is no res.end().
Both produce an obscure error:
By changing the program as follows:
The error goes away. I first tried 512 instead of 4096 and only got a partial load of my HTML file. The 4096 is the length of the HTML file. Does the chunkSize parameter need to be the file length?
So now the POST code req.on('data') works.
Pdata= {"name":"LED2","a":true,"cmd":"pobj.a=!pobj.a;digitalWrite(LED2,pobj.a)"}{"name":"LED2","a":0,"cmd":"pobj.a=!pobj.a;digitalWrite(LED2,pobj.a)"}
So there are two questions.