Avatar for Planer

Planer

Member since Feb 2017 • Last active Dec 2017
  • 2 conversations
  • 9 comments

Most recent activity

    • 13 comments
    • 278 views
  • in ESP8266
    Avatar for Planer

    ...and also more correct variant

    var wifi = require("Wifi");
    
    var page = "<!DOCTYPE html>\r\n<html>\r\n<body>\r\n\r\n";
    page += "<form action=\"\" method=\"post\">\r\n First name: ";
    page += "<input type=\"text\" value=\"\" name=\"fname\"><br>\r\n  ";
    page += "Last name: <input type=\"text\" value=\"\" name=\"lname\"><br>\r\n  ";
    page += "<input type=\"submit\" value=\"Submit\">\r\n</form>\r\n\r\n";
    page += "<p>Click on the submit button, and the input will be sent to Espruino.";
    page += "</p>\r\n\r\n</body>\r\n</html>";
    
    var b;
    
    function onPageRequest(req, res) {
      if (req.method == "GET") {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end(page);
      } else {  
        req.on("close", function () {
          console.log("AVAIL:" + req.available());
          b = req.read();
          console.log("BODY: " + b);
        });
    
        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end("ok");
      }
    }
    require("http").createServer(onPageReque­st).listen(8080);
    

    var b consist all your data, but data requires parse. (example data: "fname=Pavel&lname=123&xname=rtavel&znam­e=12673")

    for do this i developed little parser:

    var str = "fname=Pavel&lname=123&xname=rtavel&znam­e=12673";
    
    function splitData(data) {
        var dataReady = [];
        var part = true;
        var commVal = "";
    
        for (var index = 0; index < data.length; index++) {
            if (part) {
                if (data[index] != '=') commVal += data[index];
                else {
                    dataReady.push(commVal);
                    commVal = "";
                    part = false;
                }
            }
            else {
                if (data[index] != '&') commVal += data[index];
                if (data[index] == '&') {
                    dataReady.push(commVal);
                    commVal = "";
                    part = true;
                }
                if (index == data.length - 1) {
                    dataReady.push(commVal);
                    return dataReady;
                }
            }
        }
    }
    
    console.log(splitData(str));
    
    

    or more simple variant parser:

    var str = "fname=Pavel&lname=Dubailo&xname=TEST"
    
    var arr = str.split("&")
    var result = {};
    
    arr.forEach(function (pair) {
        var elem = pair.split("=");
        result[elem[0]] = elem[1];
    });
    
    console.log(result);
    
  • in ESP8266
    Avatar for Planer

    i developed most brut variant, but it working)))

    var wifi = require("Wifi");
    
    var page = "<!DOCTYPE html>\r\n<html>\r\n<body>\r\n\r\n";
    page += "<form action=\"\" method=\"get\">\r\n First name: ";
    page += "<input type=\"text\" value=\"\" name=\"fname\"><br>\r\n  ";
    page += "Last name: <input type=\"text\" value=\"\" name=\"lname\"><br>\r\n  ";
    page += "<input type=\"submit\" value=\"Submit\">\r\n</form>\r\n\r\n";
    page += "<p>Click on the submit button, and the input will be sent to Espruino.";
    page += "</p>\r\n\r\n</body>\r\n</html>";
    
    var b;
    
    function onPageRequest(req, res) {
      var a = url.parse(req.url, true);
      res.writeHead(200, { 'Content-Type': 'text/html' });
      res.end(page);
      if (a.query) b = a.query;
    }
    require("http").createServer(onPageReque­st).listen(8080);
    

    var b consist all your data)

  • in ESP8266
    Avatar for Planer

    thanks for all!)

  • in ESP8266
    Avatar for Planer

    thanks!

  • in ESP8266
    Avatar for Planer

    do you have simple code how it do? (input text field with button "send" on web server, and put data on JS code after click button)

  • in ESP8266
    Avatar for Planer

    Hello, i am newbie in html. How i can get data from my http webserver from input text field to variable in code or console.log()? I am trying, but nothing didn't work. ver 1.91 esp8266

  • in ESP8266
    Avatar for Planer

    Hi to masters! I have trouble whith esp8266 12F FW1.91 espruino.
    I send code to espruino. Code working well without errors. But if i do save(), i got error:
    Too big to save to flash (13624 vs 12284 bytes)
    Delete command history and try again...

    (While: process.memory() = {"free": 908, "usage": 792, "total": 1700, "history": 441})
    Enabled minification in ide setup is not helpful.

    I use simple mqtt client sample from original documentation espruino.com/MQTT

    What i do invalid? Why is not free space? How to resolve this problem?
    Help please!

    My code:

    var server = "m13.cloudmqtt.com";
    var options = {
        client_id : "test_machine",
        keep_alive: 60,
        port: 12345,
        clean_session: true,
        username: "user",
        password: "pass",
        protocol_name: "MQTT",
        protocol_level: 4,
      };
    var mqtt = require("MQTT").create(server, options /*optional*/);
    mqtt.connect();
    mqtt.on('connected', function() {
      mqtt.subscribe("test");
    });
    mqtt.on('publish', function (pub) {
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    });
    var topic = "test";
    var message = 1;
    setInterval('mqtt.publish(topic, message++);', 2000);
    
  • in ESP8266
    Avatar for Planer

    Hi to everyone! I have trouble whith esp8266 12F FW1.91 espruino.
    I send code to espruino. Code working well without errors. But if i do save(), i got error:
    Too big to save to flash (13624 vs 12284 bytes)
    Delete command history and try again...

    (While: process.memory() = {"free": 908, "usage": 792, "total": 1700, "history": 441})
    Enabled minification in ide setup is not helpful.

    I use simple mqtt client sample from original documentation http://www.espruino.com/MQTT

    What i do invalid? Why is not free space? How to resolve this problem?
    Help please!

    My code:

    var server = "m13.cloudmqtt.com";
    var options = {
        client_id : "test_machine",
        keep_alive: 60,
        port: 12345,
        clean_session: true,
        username: "user",
        password: "pass",
        protocol_name: "MQTT",
        protocol_level: 4,
      };
    var mqtt = require("MQTT").create(server, options /*optional*/);
    
    mqtt.connect();
    
    mqtt.on('connected', function() {
      mqtt.subscribe("test");
    });
    
    mqtt.on('publish', function (pub) {
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    });
    
    var topic = "test";
    var message = 1;
    setInterval('mqtt.publish(topic, message++);', 2000);
    
Actions