Thanks!

Posted on
  • After getting the bangle 2, I realised I like this event-based loop more than arduino coding style, so I took a bit of yesterday afternoon to reprogram my home environment monitors to be espurinos.

    Hardware-wise 8266 + dht22 + cheap screen.

    I'm on the wrong pc right now, I'll copy-paste the code I threw on them, it's about 3 tutorials sewn together.

    They were sending mqtt to an internal mosquitto server, but it kept falling over and it's a pain to unplug all 3 to fix them wired in. Now the node-red box queries them with the super tiny webserver the espurino can hold. Bonus - I can reprogram them over the air, at least when I'm at the right computer.

  • Nice - thank you! It's always nice to know when people are enjoying using it :)

  • I might try turning this into a full-blown tutorial for the pages, but in case that never gets started, here's the code I've copy-pasted together:

    
    var temperature;
    var humidity;
    
    var dht = require("DHT22").connect(D2);
    
    function onPage(req, res){
      var page = temperature + "," + humidity;
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(page);
    }
    
    function writeScreen(){
      g.clear();
     g.drawString(temperature, 0, 0); 
      g.drawString(humidity, 0, 30);
     g.flip();
    }
    // I2C
    I2C1.setup({scl:D5,sda:D4});
    var g = require("SSD1306").connect(I2C1, writeScreen);
    g.setFont("4x6", 5);
    
    function readDHT(){
      dht.read(function(a) {
       temperature = a.temp.toString();
        humidity = a.rh.toString();
        console.log("Temp is "+a.temp.toString()+" and RH is "+a.rh.toString());
      });
      writeScreen();
    }
    
    
    setInterval(readDHT, 2000);
    
    require("http").createServer(onPage).lisĀ­ten(80);
    
    

    My node.red asks http://esp_hostname.local for the page, and parses it as csv.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Thanks!

Posted by Avatar for jimr1603 @jimr1603

Actions