You are reading a single comment by @countxerox and its replies. Click here to read the full conversation.
  • Thanks for that advice @oesterle. I've had a go and I think it's improved but I can't close the wifi connection. wifi.disconnect() isn't recognised.

    Serial1.setup(115200, { rx: B7, tx : B6 });
    
    I2C3.setup({sda:B4,scl:A8});
    var bh=require("BH1750").connect(I2C3);
    
    var dht = require("DHT11").connect(B5);
    
    function read_sensors(callback) {
      var n=0,i=100;
      while (i--) n+=analogRead(A7);
      bh.start(3);
      light_intensity = Math.round(bh.read()).toString();
      soil_moisture = (100-Math.round(n)).toString();
      dht.read(function (a) { 
        temp = a.temp.toString();
        humidity = a.rh.toString();
        callback (light_intensity, soil_moisture, temp, humidity);
      });
    }
    
    function send(l,m,t,h) {
      wifi = require("ESP8266WiFi_0v25").connect(Seri­al1, function(err) {  
        if (err) throw err;
        wifi.connect("Xxx", "xxx", function(err) {
          if (err) throw err;
          LED2.set();
          sendForm(l,m,t,h);
        });
      });
    }
    
    function onInit() {
      USB.setConsole(1);
      clearInterval();
      setInterval(function() {
        read_sensors(send);
      },30000);
    }
    
About

Avatar for countxerox @countxerox started