Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Bryden
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by Bryden

    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      Another I have had these running posts.

      I have had 3 Sonoff relays running on 240v 50Hz for 2-3 months straight.

      2 of them in IP67 outdoor lights with Phillips LED Lamps, switch on and off several times per day, Not a single hardware issue.

      best $6 ever

      posted in OpenHardware.io
      Bryden
      Bryden
    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      Does anyone know how I can request the current state of the relay via MQTT.

      Eg HASS has rebooted, forgotten what state the switch was previously in, then it wont work untill power is cycled to the sonoff.

      I want to send an MQTT message to the sonoff to get its current state. Tried looking over the forums and page and cant seem to see anything about requesting a state from a binary switch / relay actuator

      posted in OpenHardware.io
      Bryden
      Bryden
    • RE: MQ DHT and Relai receive not working

      What @mfalkvidd said, I had the same issue on an esp8266

      posted in Development
      Bryden
      Bryden
    • RE: Combining DHT and Binary sensor update issue

      Thought it might be a little harder than my pay grade.

      might implement it a little later

      posted in Development
      Bryden
      Bryden
    • Combining DHT and Binary sensor update issue

      Having an issue trying to figure how to get instant response from the binary inputs (reed switch) whilst also having a DHT in the mix.

      The issue is that the binary change only gets sent when the temp or humidity is sent.

      Running the code with out the DHT in there work flawlessly. and state changes are sent immediately

      I assume is has to do with the Wait function in the loop, but with out that wait you poll the DHT too much and it wont read any data.

      Set up is NodeMCU as MQTT gateway. running 2.0

      Thanks

      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <DHT.h>
      
      // DHT22
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 12
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 60000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      
      #define CHILD_ID_HUM 4
      #define CHILD_ID_TEMP 5
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      
      // Setting multiple child ID's for each switch and it's GPIO pin
      //Switch 1
      #define CHILD_ID_1 1
      #define BUTTON_PIN_1  4  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 2
      #define CHILD_ID_2 2
      #define BUTTON_PIN_2  5  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 3
      #define CHILD_ID_3 3
      #define BUTTON_PIN_3  10  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 1
      Bounce debouncer_1 = Bounce(); 
      int oldValue_1=-1;
      
      //Switch 2
      Bounce debouncer_2 = Bounce(); 
      int oldValue_2=-1;
      
      //Switch 3
      Bounce debouncer_3 = Bounce(); 
      int oldValue_3=-1;
      
      // Setting mysensor message string (ChildID, V type)
      MyMessage msg1(CHILD_ID_1,V_TRIPPED);
      MyMessage msg2(CHILD_ID_2,V_TRIPPED);
      MyMessage msg3(CHILD_ID_3,V_TRIPPED);
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      DHT dht;
      
      //Presenting each child ID
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        //Switch
        present(CHILD_ID_1, S_DOOR);
        present(CHILD_ID_2, S_DOOR);
        present(CHILD_ID_3, S_DOOR);  
        //DHT 
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        
        metric = getControllerConfig().isMetric;
      }
      
      //Setting up each GPIO pin as an input and turning on internal pull up resistor
      void setup()
      {  
       dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
      
        // Setup button 1
        pinMode(BUTTON_PIN_1,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_1,HIGH);
        // After setting up the button, setup debouncer
        debouncer_1.attach(BUTTON_PIN_1);
        debouncer_1.interval(5);
      
        // Setup button 2
        pinMode(BUTTON_PIN_2,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_2,HIGH);
        // After setting up the button, setup debouncer
        debouncer_2.attach(BUTTON_PIN_2);
        debouncer_2.interval(5);
      
        // Setup button 3
        pinMode(BUTTON_PIN_3,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_3,HIGH);
        // After setting up the button, setup debouncer
        debouncer_3.attach(BUTTON_PIN_3);
        debouncer_3.interval(5);
      }
      
      void loop() 
      {
        //DHT
        // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
        
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
          
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
          
        // Switch 1
        debouncer_1.update();
        // Get the update value
        int value_1 = debouncer_1.read();
        if (value_1 != oldValue_1) {
           // Send in the new value
           send(msg1.set(value_1==HIGH ? 1 : 0));
           oldValue_1 = value_1;
        }
        // Switch 2
        debouncer_2.update();
        // Get the update value
        int value_2 = debouncer_2.read();
        if (value_2 != oldValue_2) {
           // Send in the new value
           send(msg2.set(value_2==HIGH ? 1 : 0));
           oldValue_2 = value_2;
        }
        // Switch 3
        debouncer_3.update();
        // Get the update value
        int value_3 = debouncer_3.read();
        if (value_3 != oldValue_3) {
           // Send in the new value
           send(msg3.set(value_3==HIGH ? 1 : 0));
           oldValue_3 = value_3;
        }
      
          // Sleep for a while to save energy
        wait(UPDATE_INTERVAL); 
      }```
      posted in Development
      Bryden
      Bryden
    • RE: 💬 Sonoff relay using MySensors ESP8266 wifi or mqtt gateway

      This sketch is awesome, First MySensors sketch I have used that worked straight off the bat.

      The details page does need a few extra bits of info....

      3.3v FTDI tool needed

      Hold down the button on the Sonoff when you power it up to enter flash mode.

      posted in OpenHardware.io
      Bryden
      Bryden
    • MQTT 3 Door switch sketch (Single relay to be added)

      Hey Guys,

      After searching a ton and doing a heap of reading, I couldn't find a multiple door switch sketch that works on 2.xx at all.

      I have this sketch working on the bench on a nodeMCU, Works best when 10k external pull ups are used as well.

      Going to add a relay to the sketch as well next now I have the 3 door switch's working.

      So I'm just sharing this so others can see hows its done.

      I'm a copy paste programmer so please dont shoot any mistakes or lack of knowledge, I'm sure there is a better way of doing it like I have seen in the relay sketch with some ++ sort of thing I have yet to work out.

      This is designed to be used with Home Assistant, It will monitor a garage door with open and closed reed switches, The internal door into the house, and the relay will trigger the garage internal light. But you could use it with whatever you want.
      Enjoy.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
       * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
       *
       * LED purposes:
       * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
       * nRF24L01+  ESP8266
       * VCC        VCC
       * CE         GPIO4
       * CSN/CS     GPIO15
       * SCK        GPIO14
       * MISO       GPIO12
       * MOSI       GPIO13
       *
       * Not all ESP8266 modules have all pins available on their external interface.
       * This code has been tested on an ESP-12 module.
       * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
       * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
       * - Connect GPIO15 via 10K pulldown resistor to GND
       * - Connect CH_PD via 10K resistor to VCC
       * - Connect GPIO2 via 10K resistor to VCC
       * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
       *
        * Inclusion mode button:
       * - Connect GPIO5 via switch to GND ('inclusion switch')
       *
       * Hardware SHA204 signing is currently not supported!
       *
       * Make sure to fill in your ssid and WiFi password below for ssid & pass.
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
      #define MY_BAUD_RATE 9600
      
      // Enables and select radio type (if attached)
      //#define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_GATEWAY_MQTT_CLIENT
      #define MY_GATEWAY_ESP8266
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "ESP2-out"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "ESP2-in"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "ESP2"
      
      // Enable these if your MQTT broker requires usenrame/password
      #define MY_MQTT_USER "******"
      #define MY_MQTT_PASSWORD "******"
      
      // Set WIFI SSID and password
      #define MY_ESP8266_SSID "******"
      #define MY_ESP8266_PASSWORD "******"
      
      // Set the hostname for the WiFi Client. This is the hostname
      // it will pass to the DHCP server if not static.
      #define MY_ESP8266_HOSTNAME "ESP2"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      //#define MY_IP_ADDRESS 192,168,178,87
      
      // If using static ip you need to define Gateway and Subnet address as well
      //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
      //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      
      // MQTT broker ip address.
      #define MY_CONTROLLER_IP_ADDRESS ******
      
      // The MQTT broker port to to open
      #define MY_PORT 1883
      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      
      // Setting multiple child ID's for each switch and it's GPIO pin
      //Switch 1
      #define CHILD_ID_1 1
      #define BUTTON_PIN_1  4  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 2
      #define CHILD_ID_2 2
      #define BUTTON_PIN_2  5  // Arduino Digital I/O pin for button/reed switch
      
      //Switch 3
      #define CHILD_ID_3 3
      #define BUTTON_PIN_3  10  // Arduino Digital I/O pin for button/reed switch
      
      //switch 1
      Bounce debouncer_1 = Bounce(); 
      int oldValue_1=-1;
      
      //switch 2
      Bounce debouncer_2 = Bounce(); 
      int oldValue_2=-1;
      
      //switch 3
      Bounce debouncer_3 = Bounce(); 
      int oldValue_3=-1;
      
      // Setting mysensor message string (ChildID, V type)
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg1(CHILD_ID_1,V_TRIPPED);
      MyMessage msg2(CHILD_ID_2,V_TRIPPED);
      MyMessage msg3(CHILD_ID_3,V_TRIPPED);
      
      
      //Presenting each child ID
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(CHILD_ID_1, S_DOOR);
        present(CHILD_ID_2, S_DOOR);
        present(CHILD_ID_3, S_DOOR);   
      }
      
      
      //Setting up each GPIO pin as an input and turning on internal pull up resistor
      void setup()
      {  
        // Setup the button 1
        pinMode(BUTTON_PIN_1,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_1,HIGH);
        // After setting up the button, setup debouncer
        debouncer_1.attach(BUTTON_PIN_1);
        debouncer_1.interval(5);
      
          // Setup the button 2
        pinMode(BUTTON_PIN_2,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_2,HIGH);
        // After setting up the button, setup debouncer
        debouncer_2.attach(BUTTON_PIN_2);
        debouncer_2.interval(5);
      
          // Setup the button 3
        pinMode(BUTTON_PIN_3,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN_3,HIGH);
        // After setting up the button, setup debouncer
        debouncer_3.attach(BUTTON_PIN_3);
        debouncer_3.interval(5);
      }
      
      
      
      
      void loop() 
      {
      
        // Switch 1
        debouncer_1.update();
        // Get the update value
        int value_1 = debouncer_1.read();
        if (value_1 != oldValue_1) {
           // Send in the new value
           send(msg1.set(value_1==HIGH ? 1 : 0));
           oldValue_1 = value_1;
        }
        // Switch 2
        debouncer_2.update();
        // Get the update value
        int value_2 = debouncer_2.read();
        if (value_2 != oldValue_2) {
           // Send in the new value
           send(msg2.set(value_2==HIGH ? 1 : 0));
           oldValue_2 = value_2;
        }
        // Switch 3
        debouncer_3.update();
        // Get the update value
        int value_3 = debouncer_3.read();
        if (value_3 != oldValue_3) {
           // Send in the new value
           send(msg3.set(value_3==HIGH ? 1 : 0));
           oldValue_3 = value_3;
        }
      }
      
      
      posted in My Project
      Bryden
      Bryden
    • RE: By uploading the DHT 22 sketch, I get an error each time.

      @alowhum They seem to be not quite as easy for copy paste programming. I have had to do a heap of reading and learning to get it all down.

      Any the other one is you search the forums for soloutions before posting and half the solutions are pre 2.x and dont work either, I don't like noob posting basic stuff due to my lack of programming skill, but people here seem quite nice and willing to help 🙂

      Wait for my debouncing post later tonight if I cant work it out hahaha

      posted in Development
      Bryden
      Bryden
    • RE: By uploading the DHT 22 sketch, I get an error each time.

      This seems to be a common issue, maybe a change to highlight that the exact listed DHT library mentioned needs to be installed and no other lol

      posted in Development
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      I suppose I could remove the sleep / wait function all together seems as it's going to run off mains and not a battery, which is what I would assume people wanted a sleep function for altogether.

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      @AWI said in DHT22 verify issue.:

      @Bryden try to replace sleep() with wait(). I cannot get sleep to work well on an esp8266.

      Well @AWI thats just weird, Its working now, I'm not much of a programmer, But something as little as changing a sleep command to wait fixed the issue is weird as hell.

      Have you got any explanation or should I just blame the angry pixies getting in a huff.

      You have well earned your hero member status.

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      Its serial printing "Failed reading temperature from DHT" and "Failed reading humidity from DHT" as per the void loop in the sketch.

      I can run DHT_Test, and it works fine, serial printing OK 1.0 25.8 47.3 (or what ever the temp and humidity is) then immediately upload the mysensor sketch and get the failed reading returns.

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: Prevent Relay from triggering on power loss or broker reboot

      check to see if the output pins are having any voltage applied on initial boot as well.
      As mentioned I had an esp8266-01b on my desk here, and when power was applied I saw voltage on one of the gpio's intermittently.

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: Prevent Relay from triggering on power loss or broker reboot

      I noticed on my ESP8266-01b that it does power surge a voltage during initial power up as well, also bad for a high level relay

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: Prevent Relay from triggering on power loss or broker reboot

      What type of relay are you using?

      My guess is a LOW TRIGGER relay, which is bad for this task.

      If you are using a low trigger relay the fault is in the hardware not the code.

      The microcontroller takes time to reboot and enable a high to keep the relay open.

      When you loose power, your microcontroller is going to take time to reboot,
      But I bet your power supply is going to instantly give power to your relay board,
      hence there is a small period in time where there is a ground on your pin before the initial setup of the pin to high in the microcontroller, causing your relay to trigger.

      This is why I hate low trigger relays, they are useless when it comes to power interrupts and you're trusting your house security to them.

      My suggestions to test my theory, then you will know where your fault lies.

      throw an LED on your relay out to light up when switched high, Apply power to your microcontroller and see how long it takes for the relay to turn on.

      Why do people use low level relays?
      Output pins are generally 3.3v, that's not enough voltage to trigger most high level relays, using a low level trigger overcomes this.

      Use a high level relay, but you will need a transistor circuit to feed it 5v as the 3.3v generally wont trigger the relay with a high output.

      hopefully my rant helps

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      Ok so I got it all working, somewhat.

      Im running a NodeMCU with wifi to MQTT with the below sketch. (note removed the header of the code to protect private info, I have had the MQTT/ESP part working fine with other sensors/actuators)

      
      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      
      // DHT22
      #include <DHT.h>
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 4
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 60000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
        
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        
        metric = getControllerConfig().isMetric;
      }
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
      }
      
      
      void loop()      
      {  
        // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
        
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
          
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        // Sleep for a while to save energy
        sleep(UPDATE_INTERVAL); 
      }
      

      Basically a copy paste of what on the mysensors page, however this code fails reading the DHT22/am2302 sensor Im using.

      If I use the DHT_Test code supplied with the mysensors master library, everything works fine, same pin, not even re powering the device, flashed it many times, and I'm stuck.

      #include "DHT.h"
      
      DHT dht;
      
      void setup()
      {
        Serial.begin(9600);
        Serial.println();
        Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
      
        dht.setup(2); // data pin 2
      }
      
      void loop()
      {
        delay(dht.getMinimumSamplingPeriod());
      
        float humidity = dht.getHumidity();
        float temperature = dht.getTemperature();
      
        Serial.print(dht.getStatusString());
        Serial.print("\t");
        Serial.print(humidity, 1);
        Serial.print("\t\t");
        Serial.print(temperature, 1);
        Serial.print("\t\t");
        Serial.println(dht.toFahrenheit(temperature), 1);
      }
      
      posted in Troubleshooting
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      seems to be fixed after I deleted and reinstalled the DHT library several time.

      Thanks mfalkvidd

      posted in Troubleshooting
      Bryden
      Bryden
    • RE: DHT22 verify issue.

      I have the DHT sensor library installed under recommended libraries and can run the DHTtester code no problems.
      I have uploaded the sketch to my nodemcu and its working fine and can see the results via serial monitor

      as shown here

      #include <DHT.h>
      #include <DHT_U.h>
      
      // Example testing sketch for various DHT humidity/temperature sensors
      // Written by ladyada, public domain
      
      #include "DHT.h"
      
      #define DHTPIN 2     // what digital pin we're connected to
      
      // Uncomment whatever type you're using!
      //#define DHTTYPE DHT11   // DHT 11
      #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
      //#define DHTTYPE DHT21   // DHT 21 (AM2301)
      
      // Connect pin 1 (on the left) of the sensor to +5V
      // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
      // to 3.3V instead of 5V!
      // Connect pin 2 of the sensor to whatever your DHTPIN is
      // Connect pin 4 (on the right) of the sensor to GROUND
      // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
      
      // Initialize DHT sensor.
      // Note that older versions of this library took an optional third parameter to
      // tweak the timings for faster processors.  This parameter is no longer needed
      // as the current DHT reading algorithm adjusts itself to work on faster procs.
      DHT dht(DHTPIN, DHTTYPE);
      
      void setup() {
        Serial.begin(9600);
        Serial.println("DHTxx test!");
      
        dht.begin();
      }
      
      void loop() {
        // Wait a few seconds between measurements.
        delay(2000);
      
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        // Read temperature as Celsius (the default)
        float t = dht.readTemperature();
        // Read temperature as Fahrenheit (isFahrenheit = true)
        float f = dht.readTemperature(true);
      
        // Check if any reads failed and exit early (to try again).
        if (isnan(h) || isnan(t) || isnan(f)) {
          Serial.println("Failed to read from DHT sensor!");
          return;
        }
      
        // Compute heat index in Fahrenheit (the default)
        float hif = dht.computeHeatIndex(f, h);
        // Compute heat index in Celsius (isFahreheit = false)
        float hic = dht.computeHeatIndex(t, h, false);
      
        Serial.print("Humidity: ");
        Serial.print(h);
        Serial.print(" %\t");
        Serial.print("Temperature: ");
        Serial.print(t);
        Serial.print(" *C ");
        Serial.print(f);
        Serial.print(" *F\t");
        Serial.print("Heat index: ");
        Serial.print(hic);
        Serial.print(" *C ");
        Serial.print(hif);
        Serial.println(" *F");
      }
      

      Ill have a read through your recommended threads to see what else I can troubleshoot.
      I also tried looking at others projects and examples but didn't see much code

      posted in Troubleshooting
      Bryden
      Bryden
    • DHT22 verify issue.

      Using the raw code from the Mysensors example I'm getting errors trying to verify the code.

      Haven't changed a single bit of the raw code.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0: Henrik EKblad
       * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz)
       * 
       * DESCRIPTION
       * This sketch provides an example of how to implement a humidity/temperature
       * sensor using a DHT11/DHT-22.
       *  
       * For more information, please visit:
       * http://www.mysensors.org/build/humidity
       * 
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached 
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      //#define MY_RS485
       
      #include <SPI.h>
      #include <MySensors.h>  
      #include <DHT.h>
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 3
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 60000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      bool metric = true;
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      DHT dht;
      
      
      void presentation()  
      { 
        // Send the sketch version information to the gateway
        sendSketchInfo("TemperatureAndHumidity", "1.1");
        
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
        
        metric = getControllerConfig().isMetric;
      }
      
      
      void setup()
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
      }
      
      
      void loop()      
      {  
        // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
        
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
          
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        // Sleep for a while to save energy
        sleep(UPDATE_INTERVAL); 
      }
      
      

      Getting the following errors

      sketch_mar01a:73: error: no matching function for call to 'DHT::DHT()'
      DHT dht;

      Any help recommended?

      Thanks

      posted in Troubleshooting
      Bryden
      Bryden