I am still trying to have my Pico+ESP8266 act as simple HTTP server. It has been working last week (inconvenient of having this only as a hobby project :/ ) but now I keep getting this error.
I used http://www.espruino.com/Interactive+Web+UI to kick start my code. It still is pretty close to it. The first request I make works, but the second always triggers this error:
Here, as seen in the Web IDE's console:
GET /
GET /
ERROR: Socket error -1 while sending
Uncaught Error: > not registered at line 2 col 64 ...Error(key+" not
registered");
^
in function "unregister" called from line 7 col 26
at.unregister('>');
^
in function "callback" called from line 4 col 40
if (callback && (n=callback(d))) {
^
in function "lineCallback" called from line 29 col 27
lineCallback(l);
^
in function called from system
Code:
var wifi;
function connectWifi(){
Serial2.setup(9600, { rx: A3, tx : A2 });
wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
if (err) throw err;
wifi.reset(function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, WIFI_PASS, function(err) {
if (err) throw err;
console.log("Connected");
// print IP address
wifi.getIP(console.log);
// Create a server
require("http").createServer(pageHandler).listen(80);
});
});
});
}
function pageHandler(req, res) {
console.log(req.method,req.url);
if (req.method=="POST") {
res.writeHead(200);
res.end('POSTHOME');
} else if (req.method=="GET") {
if (req.url=="/") {
res.writeHead(200);
res.end('GEThome');
} else {
res.writeHead(404);
res.end("404: Not found");
}
} else if (req.method=="OPTIONS") {
if (req.url=="/") {
res.writeHead(404);
res.end();
}
}
}
connectWifi();
I spent several hours looking for the origin of the error, as well as its cause with no luck. Does someone recognise it?
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.
Hi,
I am still trying to have my Pico+ESP8266 act as simple HTTP server. It has been working last week (inconvenient of having this only as a hobby project :/ ) but now I keep getting this error.
I used http://www.espruino.com/Interactive+Web+UI to kick start my code. It still is pretty close to it. The first request I make works, but the second always triggers this error:
Here, as seen in the Web IDE's console:
Code:
I spent several hours looking for the origin of the error, as well as its cause with no luck. Does someone recognise it?