• @Aleksandrs, for what ever reason the conversation about After reboot HTTP do not working need reflash from WEB IDE is closed. It shows a closed pad lock next to the conversation title, and therefore nobody can respond to it. Furthermore, it has no explaining text about the steps you took to get to where you are.

    Because @ClearMemory041063 wanted to respond, he 'recreated' the conversation. To include everything in this conversation, I'm replicating the code. @Aleksandrs, please provide context - board, wiring, etc,... and steps you took.

    var wifi = require("Wifi");
    var dht = require("DHT22").connect(D0); // GPIO4
    var lastDhtData ="none";
    // Init WiFi Networks
    wifi.setHostname("my1");
    wifi.connect("XXX", {password:"XXX"}, function(err){
      console.log("connected? err=", err, "info=", wifi.getIP());
    });
    wifi.stopAP();
    wifi.save();
    function init() {
      initServer();
      //setInterval(function(){ console.log(process.memory()); }, 100000);
      //require("ESP8266").setLog(2);
    }
    function initServer() {
      var http = require("http");
      console.log("Initalizing server instance...");
      // Create Http Answer
      http.createServer(function(req, res){
        var request = url.parse(req.url, true);
        var action = request.query;
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write('<html><head></head><body>');
        res.write(lastDhtData);
        res.end('</body></html>');
      }).listen(80);
    }
    // Get data from sensor every 1 minut
    setInterval(function(){
      dht.read(function (a) {
        lastDhtData = a.temp.toString()+","+a.rh.toString();
      });
    },60000);
    // Send to server every 10 minut
    setInterval(function(){
       postToServer(lastDhtData); 
    },600000);
    function postToServer(data){
      var options = {
        host: 'MAINLINK',
        port: '80',
        path:'/event',
        method:'POST',
        headers: {
          "Content-Type":"application/json",
          "Content-Length":data.length 
        }
      };
      require("http").request(options, function(res){
        var d = "";
        res.on('data', function(data) { d+= data; });
        res.on('close', function(data) {
          console.log("Closed: "+d);
        });
      }).end(data);
    } 
    E.on('init', function() { 
      init();
    });
    /*
    setWatch(function(e){
      console.log(e.time - e.lastTime);
    }, D1, {repeat: true, edge:"both"});
    */
    
About

Avatar for allObjects @allObjects started