Avatar for Bunny

Bunny

Member since Apr 2019 • Last active Jun 2019
  • 3 conversations
  • 8 comments

A developer girl programming on JavaScript and Espruino

Most recent activity

  • in ESP8266
    Avatar for Bunny

    Great way! It's works! Thanks all by your support.

    • 6 comments
    • 2,784 views
  • in ESP8266
    Avatar for Bunny

    Ok I already read that. But How can I enable CORS on Espruino or why's happening that?

  • in ESP8266
    Avatar for Bunny

    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?

  • in ESP8266
    Avatar for Bunny

    Thanks a lot by the answers. Its works!

  • in ESP8266
    Avatar for Bunny

    Please send me an code example.

  • in ESP8266
    Avatar for Bunny

    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"]=="applicatio­n/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_wp­a2"}, (error) => {
          if (error) throw error;
          console.log("Wifi  UP!, my IP is "+ wifi.getAPIP().ip);
          httpServer.createServer(onRequest).liste­n(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).liste­n(80); its works. What's happening with httpServer and why doesnt run at start?

    Thanks a lot

    Bunny

    • 3 comments
    • 3,766 views
  • in ESP8266
    Avatar for 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

Actions