Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
T

Terence Faul

@Terence Faul
About
Posts
48
Topics
23
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 💬 Door, Window and Push-button Sensor
    T Terence Faul

    Hi I notice that there is not sleep in this sketch. Is it not required for this build

    Announcements

  • Understanding the Serial Monitor?
    T Terence Faul

    Hi

    These are messages received at my gateway by a temp/hum/door node powered y battery.

    299665 TSF:MSG:READ,1-1-0,s=1,c=1,t=0,pt=7,l=5,sg=0:20.0
    299676 TSF:MSG:READ,1-1-0,s=0,c=1,t=1,pt=7,l=5,sg=0:31.0
    299686 TSF:MSG:READ,1-1-0,s=3,c=1,t=16,pt=2,l=2,sg=0:1
    

    Should there not be a message formatted by ; also going to the gateway?

    Troubleshooting

  • Repeater node
    T Terence Faul

    Hi

    I have a repeater node setup along side a motion sketch.
    As soon as I power it up I get the following lines constantly run on my gateway serial monitor.

    It looks to me like something is wrong, I was under the impression that the repeater will only repeat messages that it receives from other nodes

    TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3087 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3095 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3102 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3110 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3119 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3127 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3134 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3142 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3150 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3159 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3166 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3174 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3182 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3190 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    
    3197 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3206 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3214 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3222 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3229 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3237 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3248 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3256 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3263 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3271 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3279 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3288 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3295 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0
    3303 TSF:MSG:READ,4-4-0,s=1,c=1,t=16,pt=0,l=1,sg=0:0```
    Troubleshooting

  • bootloaders
    T Terence Faul

    Yep that's why I was asking.

    Anyone able to assist in getting this board into platformio?

    General Discussion

  • bootloaders
    T Terence Faul

    Hi

    Can someone assist.

    is mysensors/MySensorsBootloaderRF24 the same as MYSbootloader?

    General Discussion

  • Interupt not waking sensor
    T Terence Faul

    Is it possible the reed switch is causing a wake up, but not detecting a change in the state of the reed switch and that is why the value is not changing?

    My Project

  • Interupt not waking sensor
    T Terence Faul

    @mfalkvidd said in Interupt not waking sensor:

    Serial.println(value);

    It looks as if the Interupt is waking the sensor correctly, but not changing the value.
    If I wait for UPDATE_INTERVAL to expire though then the value is updated?

    when the Interupt is called does that invoke the loop from the beginning?
    What do you think?

    0
    6565 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    6572 TSF:TDI:TSL
    6574 MCO:SLP:WUP=1
    6576 TSF:TRI:TSB
    Vbat 3.36       Perc 100
    0
    6658 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    6662 TSF:TDI:TSL
    6664 MCO:SLP:WUP=1
    6666 TSF:TRI:TSB
    Vbat 3.35       Perc 100
    0
    6748 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    6752 TSF:TDI:TSL
    
    6754 MCO:SLP:WUP=1
    6756 TSF:TRI:TSB
    Vbat 3.36       Perc 100
    6789 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:22.0
    T: 22.00
    0
    6848 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    6852 TSF:TDI:TSL```
    My Project

  • Interupt not waking sensor
    T Terence Faul

    so I have the intercuts working now, but when I activate the interrupt the sensor wakes up and reports everything except the reed switch. What am I missing, surly when the interput triggers the void loop runs from start to finnish again?

    If I remove the Interupt then the reed switch reports but only when the sensor wakes up

    /**
     * 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 REPORT_BATTERY_LEVEL to measure battery level and send changes to gateway
    #define REPORT_BATTERY_LEVEL
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 4
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #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;
    
    Bounce debouncer = Bounce();
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    #ifdef REPORT_BATTERY_LEVEL
    #include <Vcc.h>
    static uint8_t oldBatteryPcnt = 200;  // Initialize to 200 to assure first time value will be sent.
    const float VccMin        = 1.8;      // Minimum expected Vcc level, in Volts: Brownout at 1.8V    -> 0%
    const float VccMax        = 2.0*1.6;  // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100%
    const float VccCorrection = 1.0;      // Measured Vcc by multimeter divided by reported Vcc
    static Vcc vcc(VccCorrection);
    #endif
    
    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 the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("DHT&Door", "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;
    
      // 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, S_DOOR);
    }
    
    
    void loop()
    {
      #ifdef REPORT_BATTERY_LEVEL
      const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax));
    
    #ifdef MY_DEBUG
      Serial.print(F("Vbat "));
      Serial.print(vcc.Read_Volts());
      Serial.print(F("\tPerc "));
      Serial.println(batteryPcnt);
    #endif
    
      // Battery readout should only go down. So report only when new value is smaller than previous one.
      if ( batteryPcnt < oldBatteryPcnt )
      {
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
      }
    #endif
    
      // 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;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        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++;
      }
    
       debouncer.update();
        // Get the update value
       int value = debouncer.read();
    
       if (value != oldValue) {
          // Send in the new value
          send(msg.set(value==HIGH ? 1 : 0));
          oldValue = value;
        }
    
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      sleep(digitalPinToInterrupt(BUTTON_PIN), CHANGE, UPDATE_INTERVAL);
      // Sleep for a while to save energy
      //sleep(UPDATE_INTERVAL);
    
    }
    

    When I close the reed switch

    Vbat 3.35       Perc 100
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    4765 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    4775 TSF:TDI:TSL
    4777 MCO:SLP:WUP=1
    4780 TSF:TRI:TSB
    Vbat 3.35       Perc 100
    4812 TSF:MSG:SEND,1-1-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:34.0
    H: 34.00
    4820 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    4827 TSF:TDI:TSL
    4827 MCO:SLP:WUP=1
    4829 TSF:TRI:TSB
    Vbat 3.35       Perc 100
    
    4861 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:22.0
    T: 22.00
    4870 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    4876 TSF:TDI:TSL
    4878 MCO:SLP:WUP=1
    4880 TSF:TRI:TSB
    Vbat 3.35       Perc 100
    4911 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    4915 TSF:TDI:TSL
    4917 MCO:SLP:WUP=1
    4919 TSF:TRI:TSB
    Vbat 3.35       Perc 100
    4950 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    4956 TSF:TDI:TSL```
    My Project

  • Multiple Gateways
    T Terence Faul

    Thanks that was really useful, I think the only way would be to define the node ID.
    Would that require that the node have its EEPROM cleaned first?

    General Discussion

  • Interupt not waking sensor
    T Terence Faul

    That would make alot of sense, sorry NOOB. I imagine then it is only reporting when the sensor wakes up from sleep.

    how do I go about including this. I was under the impression that this was automatic for pin 2 and 3

    My Project

  • Interupt not waking sensor
    T Terence Faul

    Hi

    For some reason the innterput is not waking my sensor, can you please see if you spot something in the sketch

    /**
     * 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 REPORT_BATTERY_LEVEL to measure battery level and send changes to gateway
    #define REPORT_BATTERY_LEVEL
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 4
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #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;
    
    Bounce debouncer = Bounce();
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    #ifdef REPORT_BATTERY_LEVEL
    #include <Vcc.h>
    static uint8_t oldBatteryPcnt = 200;  // Initialize to 200 to assure first time value will be sent.
    const float VccMin        = 1.8;      // Minimum expected Vcc level, in Volts: Brownout at 1.8V    -> 0%
    const float VccMax        = 2.0*1.6;  // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100%
    const float VccCorrection = 1.0;      // Measured Vcc by multimeter divided by reported Vcc
    static Vcc vcc(VccCorrection);
    #endif
    
    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 the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("DHT&Door", "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;
    
      // 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, S_DOOR);
    }
    
    
    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;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        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++;
      }
    
       debouncer.update();
        // Get the update value
       int value = debouncer.read();
    
       if (value != oldValue) {
          // Send in the new value
          send(msg.set(value==HIGH ? 1 : 0));
          oldValue = value;
        }
    
      #ifdef REPORT_BATTERY_LEVEL
      const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax));
    
    #ifdef MY_DEBUG
      Serial.print(F("Vbat "));
      Serial.print(vcc.Read_Volts());
      Serial.print(F("\tPerc "));
      Serial.println(batteryPcnt);
    #endif
    
      // Battery readout should only go down. So report only when new value is smaller than previous one.
      if ( batteryPcnt < oldBatteryPcnt )
      {
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
      }
    #endif
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL);
    
    }
    
    My Project

  • Multiple Gateways
    T Terence Faul

    Hi

    I live on a high property and as such. have more than one gateway. I have not changed the channel of these gateways as they are not in wireless range of each other. and I want to have the nodes be interchangeable between gateways without the need to have to upload a new sketch each time they are moved between gateways.

    What are the implications of this setup, will each gateway remember the node if the nodes are move from one gateways range to the other, or does the gateway allocate a node id automatically each time the node presents itself to the gateway.

    How will this impact the controller (Home Assistant) will the controller be confused

    General Discussion

  • Ethernet gateway
    T Terence Faul

    Hi hope someone can assist

    I have a gateway with wiznet 5100 shield.
    I haver the sketch loaded and I get a IP address assigned

    Here is the sketch and I use Home assistant as a controller. The error is slow and just loops and loops

    /*
     * 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-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     * Contribution by a-lurker and Anticimex
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or receive crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_HOSTNAME "MySensorsEth"
    //#define MY_DEBUG_VERBOSE_RF24
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable UDP communication
    //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,168,92
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,168,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Arduino examples use  "DEAD BEEF FEED" for the MAC address.
    //#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    void setup()
    {
        // Setup locally attached sensors
    }
    
    void presentation()
    {
        // Present locally attached sensors here
    }
    
    void loop()
    {
        // Send locally attached sensors data here
    }
    

    Looping error

    pio device monitor --port /dev/cu.usbserial-14320 --baud 115200
    Tmac:Gateway terencefaul$ pio device monitor --port /dev/cu.usbserial-14320 --baud 115200
    --- Miniterm on /dev/cu.usbserial-14320  115200,8,N,1 ---
    --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
    0 MCO:BGN:INIT GW,CP=RNNGA---,REL=255,VER=2.3.1
    4 TSM:INIT
    5 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:INIT:GW MODE
    15 TSM:READY:ID=0,PAR=0,DIS=0
    17 MCO:REG:NOT NEEDED
    4706 GWT:TIN:IP=192.168.1.92
    5709 MCO:BGN:STP
    5711 MCO:BGN:INIT OK,TSP=1
    5713 GWT:TSA:ETH OK
    
    5716 !GWT:TSA:ETH FAIL
    5719 TSM:READY:NWD REQ
    5755 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    5762 GWT:TSA:ETH OK
    5765 !GWT:TSA:ETH FAIL
    5767 GWT:TSA:ETH OK
    5770 !GWT:TSA:ETH FAIL
    5772 GWT:TSA:ETH OK
    5775 !GWT:TSA:ETH FAIL
    5777 GWT:TSA:ETH OK```
    My Project

  • DHT and DOOR sensor
    T Terence Faul

    Thanks so much for the help, what is the next step then? create two sensors?

    My Project

  • DHT and DOOR sensor
    T Terence Faul
    /**
     * 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 4
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #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;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        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);
    }
    
    My Project

  • DHT and DOOR sensor
    T Terence Faul

    Will give that a go. But if I load the DHT only sketch on the same node it reads fine.

    Could you check my sketch I’m a bit of a noob with code

    My Project

  • DHT and DOOR sensor
    T Terence Faul

    Hi

    I have sorted the pins and library problems, but now I get failed to read errors

    Updated Sketch

    /**
     * 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
    
    #define MY_RX_MESSAGE_BUFFER_FEATURE
    #define MY_RF24_IRQ_PIN 2
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 4
    
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #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 3
    #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;
    
    Bounce debouncer = Bounce();
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("Door/DHT", "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);
    
    	// 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, S_DOOR);
    
      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());
    	// Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);
    
    // After setting up the button, setup debouncer
    debouncer.attach(BUTTON_PIN);
    debouncer.interval(5);
    }
    
    
    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;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        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++;
    
    		debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
    
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL);
    }}
    
    

    and error snippet

    3534 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    3545 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    3553 TSF:TDI:TSL
    3555 MCO:SLP:WUP=1
    3557 TSF:TRI:TSB
    1
    3584 TSF:MSG:SEND,1-1-0-0,s=2,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
    Failed reading temperature from DHT!
    Failed reading humidity from DHT
    3592 MCO:SLP:MS=60000,SMS=0,I1=1,M1=1,I2=255,M2=255
    3602 TSF:TDI:TSL
    3604 MCO:SLP:WUP=1
    3606 TSF:TRI:TSB
    
    My Project

  • DHT and DOOR sensor
    T Terence Faul

    Hi

    Please assist, I am trying to combine the default straight from the examples, but the DHT give an error on compile

    /**
     * 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_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 3
    
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #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 3
    #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;
    
    Bounce debouncer = Bounce();
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    
    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);
    
    	// 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, S_DOOR);
    
      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());
    	// Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);
    
    // After setting up the button, setup debouncer
    debouncer.attach(BUTTON_PIN);
    debouncer.interval(5);
    }
    
    
    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;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        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++;
    
    		debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
    
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL);
    }
    
    

    The error is below

    /Users/terencefaul/Documents/PlatformIO/Projects/Mysensors DHT and Door/src/BinarySwitchSleepSensor.ino.ino: In function 'void loop()':
    /Users/terencefaul/Documents/PlatformIO/Projects/Mysensors DHT and Door/src/BinarySwitchSleepSensor.ino.ino:129:22: error: no matching function for call to 
    'DHT::readSensor(bool)'
    dht.readSensor(true);```
    My Project

  • Battery reporting
    T Terence Faul

    Hi

    is it possible to implement battery reporting as in

    https://github.com/mysensors/MySensorsArduinoExamples/blob/master/examples/Si7021TemperatureAndHumiditySensor/Si7021TemperatureAndHumiditySensor.ino

    in other sketches so one does not need the resisters as in the battery reporting section

    General Discussion

  • MQTT Gateway
    T Terence Faul

    That is great thanks

    Last question, will it also function as a normal ethernet gateway. I currently use that with Domoticz

    Hardware
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular