Avatar for Planer

Planer

Member since Feb 2017 • Last active Jun 2018
  • 3 conversations
  • 15 comments

Most recent activity

    • 4 comments
    • 59 views
  • in ESP8266
    Avatar for Planer

    in error output i see:
    sometime this:
    ERROR: Error processing Serial data handler - removing it.
    ERROR: Error processing Serial data handler - removing it.
    Execution Interrupted during event processing.
    New interpreter error: CALLBACK,MEMORY

    sometime this:
    ERROR: Ctrl-C while processing interval - removing it.
    Execution Interrupted during event processing.
    Uncaught InternalError: Unable to create socket
    at line 130 col 10
    }).end();

         ^
    

    in function "getTimeOnline" called from line 103 col 21
    try { getTimeOnline(); } catch (error) { }

    process.env:
    "VERSION": "1v99",
    "GIT_COMMIT": "f0d66ba",
    "BOARD": "ESP8266_4MB",
    "FLASH": 0, "RAM": 81920,
    "SERIAL": "5ccf7fed-7f68",
    "CONSOLE": "Telnet",
    "MODULES": "Flash,Storage,net" ... "r,crypto,neopixel",
    "EXPTR": 1073643636 }

  • in ESP8266
    Avatar for Planer

    Hi gyes. Recently write code of internet online clock. But my happiness was not long, because i had unresolved trouble for me. All of operativ memory for some time is went out, and code is stopping. Where could I make a mistake and how to fix it?
    p.s Intervals of lost all memory every time is different.
    all code:

    I2C1.setup({ scl: 5, sda: 4 });
    var wifi = require("Wifi");
    var esp8266 = require("ESP8266");
    
    var lcd;
    var masterPass = "q1w2e3r4";
    var serverStarted = false;
    var allDate = "";
    var yr = 999;
    var oldYr = 99;
    var mns = 999;
    var oldMns = 99;
    var dy = 999;
    var oldDy = 99;
    var hr = 999;
    var oldHr = 99;
    var min = 999;
    var oldMin = 99;
    var sec = 999;
    var oldSec = 99;
    
    //setup part------------------------------------­--------------------------------------
    wifi.on('sta_joined', function (details) {
      if (!serverStarted) {
        serverStart();
        serverStarted = true;
      }
    });
    
    function getPage(text) {
      text = typeof text !== 'undefined' ? text : wifi.getStatus().station;
      return `<!doctype html>
      <html>
      <head>
          <title>System setup</title>
      </head>
      <body>
      <p style="text-align: center;">Status: `+ text + `</p>
      <form action="" method="post">
      <h2 style="text-align: center;">Setup configuration:</h2>
      <hr />
      <p style="text-align: center;"><span style="color:#FF0000;">Access pass:&nbsp;<input name="accpsName" required type="password" /></span></p>
      <p style="text-align: center;"><span style="color:#000000;">SSID name:&nbsp;<input name="ssidName" required type="text" /></span></p>
      <p style="text-align: center;"><span style="color:#000000;">SSID pass:&nbsp;<input name="passName" type="password" /></span></p>
      <p style="text-align: center;"><input type="submit" value="SEND" /></p>
      </form>
      <p style="text-align: center;">&nbsp;</p>
      </body>
      </html>`;
    }
    
    function parseData(data) {
      var arr = data.split("&");
      var result = {};
    
      arr.forEach(function (pair) {
        var elem = pair.split("=");
        result[elem[0]] = elem[1];
      });
      return result;
    }
    
    function serverStart() {
      function onPageRequest(req, res) {
        var reqData;
        if (req.method == "GET") {
          res.writeHead(200, { 'Content-Type': 'text/html' });
          res.end(getPage());
        } else {
          req.on("close", function () {
            reqData = req.read();
            reqData = parseData(reqData);
            if (reqData.accpsName == masterPass) {
              wifi.connect(reqData.ssidName, { password: reqData.passName }, function (ap) { });
              wifi.save();
              setTimeout(function () {
                esp8266.reboot();
              }, 5000);
            }
          });
          res.writeHead(200, { 'Content-Type': 'text/html' });
          res.end(getPage());
        }
      }
      require("http").createServer(onPageReque­st).listen(8080);
    }
    
    //Inet time part------------------------------------­-------------------------------------
    wifi.on('connected', function (details) {
      lcd = require("HD44780").connectI2C(I2C1, 0x27);
      if (!serverStarted) {
        serverStart();
        serverStarted = true;
      }
      /*if (wifi.getStatus().station != "connected") {
        lcd.clear();
        lcd.setCursor(0, 3);
        lcd.print("setup wifi connection");
      }*/
      setInterval(function () {
        try { getTimeOnline(); } catch (error) { }
        updateDisplay();
      }, 1000);
    });
    
    function getTimeOnline() {
      allDate = "";
      var options = {
        host: 'api.timezonedb.com',
        port: '80',
        path: '/v2/get-time-zone?format=json&by=zone&z­one=Europe/Minsk&key=5CZHRPQ83HOC',
        method: 'GET',
        headers: { "Content-Type": "application/json" }
      };
      require("http").request(options, function (res) {
        res.on('data', function (partOfData) {
          allDate += partOfData;
        });
        res.on('close', function (data) {
          try {
            allDate = allDate.split('{');
            allDate = allDate[1].split('}');
            allDate = '{' + allDate[0] + '}';
            allDate = JSON.parse(allDate);
            displayTextParse(allDate.formatted);
          } catch (error) { }
        });
      }).end();
    }
    
    function displayTextParse(params) {
      var date = params.split("-");
      var temp = date[2].split(" ");
      date[2] = temp[0];
      var tme = temp[1];
      tme = tme.split(":");
    
      yr = date[0];
      mns = date[1];
      dy = date[2];
      hr = tme[0];
      min = tme[1];
      sec = tme[2];
    }
    
    function updateDisplay() {
      if (oldYr != yr) {
        lcd.setCursor(0, 1);
        lcd.print(yr);
        oldYr = yr;
        lcd.print("-");
      }
      if (oldMns != mns) {
        lcd.setCursor(5, 1);
        lcd.print(mns);
        oldMns = mns;
        lcd.print("-");
      }
      if (oldDy != dy) {
        lcd.setCursor(8, 1);
        lcd.print(dy);
        oldDy = dy;
        lcd.print(" ");
      }
      if (oldHr != hr) {
        lcd.setCursor(12, 1);
        lcd.print(hr);
        oldHr = hr;
        lcd.print(":");
      }
      if (oldMin != min) {
        lcd.setCursor(15, 1);
        lcd.print(min);
        oldMin = min;
        lcd.print(":");
      }
      if (oldSec != sec) {
        lcd.setCursor(18, 1);
        lcd.print(sec);
        oldSec = sec;
      }
    }
    
    
  • in ESP8266
    Avatar for Planer

    yes. At first attempt unsuccessed flash it whas problem by wifi connection. Seccond attemp it is successful. Thanks

  • in ESP8266
    Avatar for Planer

    hi, i whana try flash my esp8266_4M over wifi, but how add 4MB-c1 parameter on command line from file wiflash.sh?

    sh wiflash.sh 192.168.1.3:88 espruino_esp8266_user1.bin espruino_esp8266_user2.bin
    Flashing user2.bin
    
  • in ESP8266
    Avatar for Planer

    @MaBe,
    Bingo, it's works well)) Thanks!

  • in ESP8266
    Avatar for Planer

    Same problem...
    1.95 not work after wifi.save() and reboot

    1st erase flash command line:

    python esptool.py --port COM7 erase_flash
    

    2nd flash esp12 4mb command line:

    python esptool.py --port COM7 --baud 115200 write_flash --flash_freq 80m --flash_mode dio --flash_size 32m 0x0000 boot_v1.6.bin 0x1000 espruino_esp8266_user1.bin 0x3FC000 esp_init_data_default.bin 0x3FE000 blank.bin
    

    or

    python "../esptool/esptool.py" --port COM7 --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size 4MB 0x0000 boot_v1.6.bin 0x1000 espruino_esp8266_user1.bin 0x3FC000 esp_init_data_default.bin 0x3FE000 blank.bin
    
    • 13 comments
    • 470 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)

Actions