low.js and MacOS



  • To prepare the transfert of my Nodejs project on Neonious One hardware, I started installing lowjs on my Mac/Mojave and tried to run it to discover incompatibilities problems and develop walkarouds.

    I found lowjs very easy with ES5 but not ES6 syntax (functions arrow by example)

    I started to align my code with ES5 syntax but I founded that I use external packages with ES6b extensions.

    What can I do ?



  • lowsync and the neonious IDE transpile the code when they are pushed onto the microcontroller.

    To test the code on the PC, you can run the code with low --transpile <file>. This transpiles all files on-the-fly, however it is slow because it is done every time and low.js is not as fast as Node.JS. But for testing it works!

    Thomas



  • Thanks, It works but I have to progress amount incompatibilities.



  • On my Mac 2Ghz Core i7, one core is used during 2 minutes before the process starts.
    Also I changed the starting .js with a very light one and add step by step some fat...



  • How much code do you have? If transpilation takes so long, it might be a too big project for the microcontroller. Just warning 🙂

    In any case:

    Babel, the transpiler, is CPU draining, and low.js is naturally far slower than Node.JS on CPU draining things, because it does not include all the JIT features (see This comparison from the Blog). So it takes time.

    You can always do the transpilation step with Node.JS before running low.js. With TypeScript setting up the transpilation to do the whole directory is easy (here a config). With Babel it should also work somehow.



  • Actually my projet contains 4600 raw lines (with comments...) of ES5/ES6 code

    • "dependencies": {
      "aisparser": "0.0.13",
      "async": "^2.6.3",
      "cron": "^1.7.2",
      "gps": "^0.4.9",
      "kalmanjs": "^1.1.0",
      "node-gpsd": "^0.3.0",
      "node-lzw": "^0.3.1",
      "request": "^2.88.0"
      }

    57 modules in node_modules directory !!

    My program do not use a lot of RAM memory (2/3 Ko in global object like a 'database' and many local dynamic scalars, no local explicit arrays) and I hope it will be good.

    I am a little bit afraid my the dependency modules, especially "request"

    I have the possibility to suppress and rewrite walkarounds for some of them.

    I do not know how to evaluate the size used by an external module to estimate the benefit.

    To start I will concentrate on the compatibility step and will try to transpile the actual project with nodejs to progress faster.



  • Most npm modules out there were written without any CPU/RAM/Disk restrictions in mind... They often just make code a bit better to write, and consume lots of resources while doing that.

    request is such a module. If you rewrite with using the built-in http/https modules, you will notice that the code is not so much larger or more difficult to read.

    And if you need request for example because the built-in http/https modules do not handle redirects, take a look at axios. Far smaller and more modern design.



  • @neoniousTR some news :
    I followed your ideas.
    I replaced usage of fat request module by http module for gets ans posts
    I transpiled all the project (about 2secs.) from src directory to dist directory using babel+gulp
    It runs well with : node src/index.js and with : node dist/index.js

    I tried with : low dist/index.js
    It starts quickly
    I wrote walkarounds for fs.readdir() and fs.truncate()
    It works except http/post requests. (Connection reset by peer (at read))

    I replaced http by axios.
    the 2 node versions works always well

    the low execution works well for axios/get but has always trouble with axios/post
    (Request failed with status code 400)
    but my node server received nothing and never respond 400!
    and after some axios/post requests :

    Error: Connection reset by peer (at read)
    at [anon] (src/low_system.cpp:693) internal
    at [anon] () native strict preventsyield
    at [anon] (lib:internal/http:187) strict
    at [anon] (lib:stream:100) strict
    at [anon] (lib:stream:114) strict preventsyield

    I continue to search and test.
    Probably I will write a small node/low program with axios/post and a small node server to reproduce the problem.

    If you have some ideas ...



  • @ygageot With a very small test project which I can start on my own machine I can see the problem quickly and fix - if there is something to fix - without guessing. If you can help me here, that would be perfect!



  • @neoniousTR

    I need only to run the client side with LOW
    You will nee probably to change http HOST:PORT
    Thanks in advance

    --- client ------------------------------------------------------

    var axios = require('axios').default;

    const datasTest = {
    path: [
    { lat: 46.97605, lng: -2.2783 },
    { lat: 46.965, lng: -2.318983 },
    { lat: 46.957499999999996, lng: -2.318983000000003 },
    { lat: 46.95, lng: -2.318983 },
    { lat: 46.93652164250023, lng: -2.3895092759186127 },
    { lat: 46.923, lng: -2.46 },
    { lat: 44.5, lng: -11 },
    { lat: 42, lng: -13.3 },
    { lat: 28, lng: -23 },
    { lat: 14.6, lng: -60 },
    { lat: 14.38, lng: -60.84 },
    { lat: 14.38, lng: -60.88 },
    { lat: 14.39677, lng: -60.885 },
    { lat: 14.4041, lng: -60.879 }
    ]
    };

    function postWWW(data, url, callback) {
    var axiosConfig = {
    method: 'post',
    baseURL: 'http://localhost:8081',
    url: url,
    timeout: 10000,
    data: data
    };
    axios(axiosConfig).then(function (response) {
    return callback(null, response.data);
    }).catch (function (error) {
    return callback(error);
    });
    // .finally(function () {});
    }

    postWWW(datasTest, '/test', function (error, body) {
    if (error) console.log(error);
    console.log(body);
    });

    --- server ------------------------------------------------------

    "use strict";
    const http = require("http");

    const server = http.createServer().listen(8081);

    server.on('request', function (request, response) {
    var body = '';

    request.on('data', function (data) {
        body += data;
    });
    
    request.on('end', function () {
         console.log(body);
         response.writeHead(200, {'Content-Type': 'text/plain'});
         response.end('OK');
    });
    

    });

    server.on('error', function (error) {
    console.log(error);
    });



  • Fixed, in the three commits:

    The real problem:
    https://github.com/neonious/lowjs/commit/40fd0097c7fe1252762b0e4bccfd79ae02dac914

    Makes the server also work:
    https://github.com/neonious/lowjs/commit/85f3b7a37560ced9e83021190c081a42fcee4f5c

    To fix that axios can handle timeouts:
    https://github.com/neonious/lowjs/commit/6b833f2fe172f8a0d4a911b06b66c5c491d9cc24

    Now axios should be working perfectly!

    The new macOS binary will be compiled and put online automatically within the next 24 hours.
    The ESP32 version will be out hopefully this week, it also includes other large developments..



  • The low.js PC binaries are updated. Please try it out.

    The ESP32 version will hopefully be out tomorrow. The release will be announced here: https://neonious.com/documentation/changelog



  • @neoniousTR
    It’s fine all my project works well with low on my Mac. Thanks a lot.
    Next step flash soldering...


Log in to reply