• @cuneyt,

    The term single page (web) app is a term used in context of a browser and means that after initial load of the dhtml, xhr request are made to pull data and html fragments to update the page (in the browser) without reloading it.

    The upload function of IDE does make sure that all required modules are uploaded first into the cache so when it comes to execution, they can be pulled from there.

    If you use the command, I'm not sure what is going on... but I'm sure that you can replace previously uploaded code with new / other code. From context I read that command line tool upload does the same like the IDE: upload requested modules first.

    Command line option has more options...

    To your specific case of code: I may be that your http communication you start conflicts with the upload process. Furthermore, it is non-standard ESP8266 board, so it behaves anyway different than the regular Espruino boards. Give this a shot: pack your code in a function, for example, function myCode() {... and then add setTimeout(myCode,50000); as last line.

    If you use the save option, you have to have an function onInit() { ... } in which you get your code rolling.

  • Hi it's cuneyt. I just lost the access to the email I was registered with. So registered another account. Seems I'll be regular here. I liked this Espruino more than any other firmware. Not sure why it's called Espruino though. It should be called NodeMCU as it actually is the true Nodejs for MCU. Lua firmware should be called something else.

    Anyway, I finally managed to do what I was trying to do. Yes require works in a different way in Espruino. So if I use require to include other files it'll be a mess. Instead I should use uglify.js which just concatenates all files into a single file. Nothing else. Then I can use require for firmware libraries and online libraries.

    Please check my repo below to see how I use terminal. I use espruino npm package. You have all control over the code. It's awesome. Did not really use WebIDE but I'm sure it's using this library in the background in a similar way. It's good for starting but I wanna have more control over my library. And automate things.

    https://github.com/aliustaoglu/espruino-­http-server

    Here all files in the /src library bundled into a single file and minified. That's it. I just hate to put everything into a single file.

    "uglifyjs src/* --compress --mangle -o ./index.js "

    Put everything into index.js and upload index.js to ESP8266.

    And also I can use package.json to simplify frequently used commands like erasing or flashing the firmware, uploading the code etc.

    led.js

    function ledStatus(status) {
      digitalWrite(2, status); // is called from httpServer
    }
    
    

    httpServer.js

    function runServer() {
      var http = require('http');
      http
        .createServer(function(req, res) {
          res.writeHead(200);
          var status = req.url.replace('/?', '');
          if (status === 'on') ledStatus(0) // ledStatus is a function from led.js
          if (status === 'off') ledStatus(1)
          res.end('LED status = ' + status)
        })
        .listen(8080);
    }
    
    

    Then when I connect to http://192.168.1.x:8080/?on the LED turns on and turns of when I navigate to http://192.168.1.x:8080/?off

    here is how I use my package.json

    "scripts": {
        "erase": "esptool.py --port /dev/cu.wchusbserial1420 erase_flash",
        "flash": "esptool.py --port /dev/cu.wchusbserial1420 --baud 115200 write_flash --flash_freq 80m  -fm dio --flash_size 4MB 0x0000 firmware/boot_v1.6.bin 0x1000 firmware/espruino_esp8266_user1.bin 0x3FC000 firmware/esp_init_data_default.bin 0x3FE000 firmware/blank.bin",
        "reset": "npm run erase && npm run flash",
        "reupload": "npm run reset && npm run upload",
        "uglify": "uglifyjs src/* --compress --mangle -o ./index.js ",
        "upload": "npm run uglify && espruino -p /dev/cu.wchusbserial1420 -b 115200 --board boards/ESP8266_4MB.json -e 'save()' index.js",
        "screen": "screen /dev/cu.wchusbserial1420 115200"
      },
    
About

Avatar for allObjects @allObjects started