-
-
Hi friends of Espruino,
I hope that all ours are OK.
Now I'm trying to connect to a Http server made in Espruino like http://forum.espruino.com/conversations/334253/#comment14748665 from JS Client, but happen a error of permission about Access-Control-Allow-Origin because my JS Client is in another server and my Espruino web server is in another IP. How can I enable CORS on Espruino or why's happening that? -
-
-
Hi,
Please help me with this trouble, i tried to start an http server on a ESP8266 (Nodemcu v3) with this code:
function handlePOST(req, callback) { var data = ""; req.on('data', function(d) { data += d; }); req.on('end', function() { // All data received from the client, so handle the url encoded data we got // If we used 'close' then the HTTP request would have been closed and we // would be unable to send the result page. let postData = {}; data.split("&").forEach(function(el) { var els = el.split("="); postData[els[0]] = decodeURIComponent(els[1]); }); // finally our data is in postData console.log(postData); // do stuff with it! console.log("We got the text on codeJS", postData.codeJS); // call our callback (to send the HTML result) callback(postData.codeJS); }); } function onRequest(req, res) { var rurl = url.parse(req.url,true); if (rurl.pathname=="/") { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(`<h1>Please send commands on HTTP POST at /cmd URL</h1>`); } else if (rurl.pathname=="/cmd" && req.method=="POST" && req.headers["Content-Type"]=="application/x-www-form-urlencoded") { handlePOST(req, (codeJS) => { res.writeHead(200, {'Content-Type': 'text/plain'}); let value = ""; value = eval(codeJS); res.end(value); }); } else { res.writeHead(404, {'Content-Type': 'text/html'}); res.end("<h1>404: Page "+rurl.pathname+" not found</h1>"); } } function onInit() { carro.iniciarCarro(); let wifi = require("Wifi"); let httpServer = require("http"); wifi.disconnect(); wifi.setHostname("mycar"); wifi.startAP("wifi-me", {password:"my-password",authMode:"wpa_wpa2"}, (error) => { if (error) throw error; console.log("Wifi UP!, my IP is "+ wifi.getAPIP().ip); httpServer.createServer(onRequest).listen(80); wifi.save(); save(); }); }
But its doesnt start the http server on port 80. When connect to telnet at port 23, and run
httpServer.createServer(onRequest).listen(80);
its works. What's happening with httpServer and why doesnt run at start?Thanks a lot
Bunny
-
-
Hi everybody,
I wanna to use Espruino on Esp8266 on a WiFi network that this device emits(esp8266), but I cannot find a module in Espruino to SSH Server console. I find that you can send JS Code to Espruino on port 23 (Telnet) but it's insecure and anybody can connect to this ESP8266.
Please help me :(
Thanks a lot
Great way! It's works! Thanks all by your support.