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
  1. Home
  2. My Project
  3. 2 channel relais with 2 buttons sending strange values for on:off

2 channel relais with 2 buttons sending strange values for on:off

Scheduled Pinned Locked Moved My Project
18 Posts 5 Posters 7.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AndurilA Offline
    AndurilA Offline
    Anduril
    wrote on last edited by
    #3

    @mfalkvidd thank you very much. I use a ESP as gateway and was following this thread, but must have missed that problem in the 200+ posts. I will try to use newest development branch and see if problem still exists.

    1 Reply Last reply
    0
    • AndurilA Offline
      AndurilA Offline
      Anduril
      wrote on last edited by
      #4

      ok tested that again, installed a fresh mysensors lib (stable master, downloaded 11.01.16) and first test ran fine. Relay gives 1 or 0 as status, worked even for hours.
      But after powering another node it starts again. Sad that I have no third one here at the moment to test if its a general problem with more than one node or specific to this one. I also reflashed the problematic node (with dht and switch), but nothing changed. Is it possible that a message from the DHT-node brings the ESP to a special mode/error state that makes it misinterprete 0 and 1 readings to 1107296257?

      1 Reply Last reply
      0
      • AndurilA Offline
        AndurilA Offline
        Anduril
        wrote on last edited by
        #5

        Did some further tests. As it seems to be related with the ESP gateway maybe @Yveaux has a hint for me.
        When starting the relay node it works fine, until the first message of the DHT node is received. After that it starts to get strange. I already tried to recompile all sketches with newest MS 1.5.1 and cleared all eeproms (except the gw, is that neccesary?)

        MYSController.png

        just for completeness the sketch of my DHT node. If someone finds something strange in there please let me know.

        
        #include <MySensor.h>
        #include <SPI.h>
        #include <Bounce2.h>
        #include <DHT.h>  
        
        #define CHILD_ID 3
        #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
        #define CHILD_ID_HUM 1
        #define CHILD_ID_TEMP 2
        #define HUMIDITY_SENSOR_DIGITAL_PIN 5
        unsigned long SLEEP_TIME = 1000; // Sleep time between reads of switch (in milliseconds)
        
        unsigned int debounce_nr = 10; // No of cycles doing button test
        unsigned int cycle_min = 10; // No of cycles min for DHT read
        unsigned int cycle_max = 60; // No of cycles max for DHT read (must be cycle_min*n)
        float Temp_dif =0.3; // change in Temp to trigger send
        float Hum_dif =3; // change in Hum to trigger send
        
        MySensor gw;
        DHT dht;
        float lastTemp;
        float lastHum;
        boolean sendNow = true;
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        Bounce debouncer = Bounce(); 
        int oldValue=-1;
        unsigned int debouncecycle=0;
        unsigned int cycle=0;
        unsigned int cycle_multiplier = 1;
        float temperature;
        float humidity;
        
        // Change to V_LIGHT if you use S_LIGHT in presentation below
        MyMessage msg(CHILD_ID,V_TRIPPED);
        
        void setup()  
        {  
          gw.begin();
          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
          
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("DHT with Switch", "1.0");
          
         // 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);
          
          // 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.
          gw.present(CHILD_ID, S_DOOR);
          delay(10);  
          gw.present(CHILD_ID_HUM, S_HUM);
          delay(10);
          gw.present(CHILD_ID_TEMP, S_TEMP);
          
        
        }
        
        
        //  Check if digital input has changed and send in new value
        void loop() 
        {
          debouncer.update();
          // Get the update value
          int value = debouncer.read();
        
          if (value != oldValue) {
             // Send in the new value
             gw.send(msg.set(value==HIGH ? 1 : 0));
             oldValue = value;
             }
          if (cycle >= cycle_min * cycle_multiplier) {
          cycle_multiplier=cycle_multiplier+1;
            delay(dht.getMinimumSamplingPeriod());
        
          temperature = dht.getTemperature();
          //Serial.print("Temp: ");
          //Serial.print(temperature);
          //Serial.print("LastTemp: ");
          //Serial.println(lastTemp);
          if (isnan(temperature)) {
              Serial.println("Failed reading temperature from DHT");
          } else if ((temperature < lastTemp - Temp_dif) or (temperature > lastTemp + Temp_dif)) {
            sendNow=true;
            Serial.println("SendNow set by Temp");
            
          }
          
          humidity = dht.getHumidity();
          //Serial.print("Hum: ");
          //Serial.print(humidity);
          //Serial.print("LastHum: ");
          //Serial.println(lastHum);
          if (isnan(humidity)) {
              Serial.println("Failed reading humidity from DHT");
          } else if ((humidity < lastHum - Hum_dif) or (humidity > lastHum + Hum_dif)) {
              sendNow=true;
              Serial.println("SendNow set by Hum");
              
          }
          if (cycle >= cycle_max){
            sendNow=true;
            Serial.println("SendNow set by cycle_max");
          }
          }
          if (debouncecycle>debounce_nr){
          gw.sleep(SLEEP_TIME); //sleep a bit
          debouncecycle=0;
          cycle=cycle+1;
          //Serial.print("Anzahl Zyklen: ");
          Serial.println(cycle);
          }
          debouncecycle=debouncecycle+1;
          Serial.print(debouncecycle);
          if (sendNow){
            sendNow = false;
            cycle=0;
            cycle_multiplier=1;
            Serial.println("Zyklen zurueckgesetzt, Daten gesendet.");
            Serial.println(cycle);
            gw.send(msgTemp.set(temperature, 1));
            lastTemp = temperature;
            gw.send(msgHum.set(humidity, 1));
            lastHum = humidity;
            
          }
          
        } 
        
        
        YveauxY 1 Reply Last reply
        0
        • AndurilA Anduril

          Did some further tests. As it seems to be related with the ESP gateway maybe @Yveaux has a hint for me.
          When starting the relay node it works fine, until the first message of the DHT node is received. After that it starts to get strange. I already tried to recompile all sketches with newest MS 1.5.1 and cleared all eeproms (except the gw, is that neccesary?)

          MYSController.png

          just for completeness the sketch of my DHT node. If someone finds something strange in there please let me know.

          
          #include <MySensor.h>
          #include <SPI.h>
          #include <Bounce2.h>
          #include <DHT.h>  
          
          #define CHILD_ID 3
          #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
          #define CHILD_ID_HUM 1
          #define CHILD_ID_TEMP 2
          #define HUMIDITY_SENSOR_DIGITAL_PIN 5
          unsigned long SLEEP_TIME = 1000; // Sleep time between reads of switch (in milliseconds)
          
          unsigned int debounce_nr = 10; // No of cycles doing button test
          unsigned int cycle_min = 10; // No of cycles min for DHT read
          unsigned int cycle_max = 60; // No of cycles max for DHT read (must be cycle_min*n)
          float Temp_dif =0.3; // change in Temp to trigger send
          float Hum_dif =3; // change in Hum to trigger send
          
          MySensor gw;
          DHT dht;
          float lastTemp;
          float lastHum;
          boolean sendNow = true;
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          Bounce debouncer = Bounce(); 
          int oldValue=-1;
          unsigned int debouncecycle=0;
          unsigned int cycle=0;
          unsigned int cycle_multiplier = 1;
          float temperature;
          float humidity;
          
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg(CHILD_ID,V_TRIPPED);
          
          void setup()  
          {  
            gw.begin();
            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
            
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("DHT with Switch", "1.0");
            
           // 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);
            
            // 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.
            gw.present(CHILD_ID, S_DOOR);
            delay(10);  
            gw.present(CHILD_ID_HUM, S_HUM);
            delay(10);
            gw.present(CHILD_ID_TEMP, S_TEMP);
            
          
          }
          
          
          //  Check if digital input has changed and send in new value
          void loop() 
          {
            debouncer.update();
            // Get the update value
            int value = debouncer.read();
          
            if (value != oldValue) {
               // Send in the new value
               gw.send(msg.set(value==HIGH ? 1 : 0));
               oldValue = value;
               }
            if (cycle >= cycle_min * cycle_multiplier) {
            cycle_multiplier=cycle_multiplier+1;
              delay(dht.getMinimumSamplingPeriod());
          
            temperature = dht.getTemperature();
            //Serial.print("Temp: ");
            //Serial.print(temperature);
            //Serial.print("LastTemp: ");
            //Serial.println(lastTemp);
            if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT");
            } else if ((temperature < lastTemp - Temp_dif) or (temperature > lastTemp + Temp_dif)) {
              sendNow=true;
              Serial.println("SendNow set by Temp");
              
            }
            
            humidity = dht.getHumidity();
            //Serial.print("Hum: ");
            //Serial.print(humidity);
            //Serial.print("LastHum: ");
            //Serial.println(lastHum);
            if (isnan(humidity)) {
                Serial.println("Failed reading humidity from DHT");
            } else if ((humidity < lastHum - Hum_dif) or (humidity > lastHum + Hum_dif)) {
                sendNow=true;
                Serial.println("SendNow set by Hum");
                
            }
            if (cycle >= cycle_max){
              sendNow=true;
              Serial.println("SendNow set by cycle_max");
            }
            }
            if (debouncecycle>debounce_nr){
            gw.sleep(SLEEP_TIME); //sleep a bit
            debouncecycle=0;
            cycle=cycle+1;
            //Serial.print("Anzahl Zyklen: ");
            Serial.println(cycle);
            }
            debouncecycle=debouncecycle+1;
            Serial.print(debouncecycle);
            if (sendNow){
              sendNow = false;
              cycle=0;
              cycle_multiplier=1;
              Serial.println("Zyklen zurueckgesetzt, Daten gesendet.");
              Serial.println(cycle);
              gw.send(msgTemp.set(temperature, 1));
              lastTemp = temperature;
              gw.send(msgHum.set(humidity, 1));
              lastHum = humidity;
              
            }
            
          } 
          
          
          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #6

          @Anduril is the second node running the same MySensors version as the other node and gateway?
          What Arduino core version are you using for ESP support?

          http://yveaux.blogspot.nl

          AndurilA 1 Reply Last reply
          0
          • V Offline
            V Offline
            vampircik
            wrote on last edited by
            #7

            Used: C:\Users\vampircik\Documents\Arduino\libraries\Bounce2
            Not used: C:\arduino-1.6.3\libraries\Bounce2

            I tried to upload a sketch, an error says no such library

            1 Reply Last reply
            0
            • YveauxY Yveaux

              @Anduril is the second node running the same MySensors version as the other node and gateway?
              What Arduino core version are you using for ESP support?

              AndurilA Offline
              AndurilA Offline
              Anduril
              wrote on last edited by
              #8

              @Yveaux yeah I compiled all 2 nodes and the gw just yesterday with the same MySensors version. With Arduino core version you mean the version of Arduino IDE? 1.6.6
              Is it necessary/usefull/possible to do a eeprom reset on the gw?
              Btw sometimes MYSController does not recognice all presentation messages. Is that somehow a problem? I don't know why this happens as all my nrf are equiped with 4.7µF (node in question also tried with 2 caps).

              1 Reply Last reply
              0
              • mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #9

                This is how to check esp core version http://forum.mysensors.org/topic/2708/soft-wdt-reset-on-esp8266/13

                1 Reply Last reply
                0
                • AndurilA Offline
                  AndurilA Offline
                  Anduril
                  wrote on last edited by
                  #10

                  ESP.PNG

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vampircik
                    wrote on last edited by
                    #11

                    these relays your sketch works well, but is not displayed correctly in the controller
                    http://ru.aliexpress.com/item/2-channel-New-2-channel-relay-module-relay-expansion-board-5V-low-level-triggered-2-way/1617727658.html
                    and with these relay failures. why is that? although "RelayWithButtonActuator" in truth it works with one group
                    http://ru.aliexpress.com/item/10PCS-LOT-New-original-solid-state-relay-G3MB-202P-DC-AC-PCB-SSR-In-5VDC-Out/32339505849.html

                    1 Reply Last reply
                    0
                    • AndurilA Offline
                      AndurilA Offline
                      Anduril
                      wrote on last edited by
                      #12

                      @vampircik I don't realy understand what you tried to say. At the moment I have no real relays connected but simply LEDs for testing purposes.
                      @Yveaux I updated the ESP8266 definitions to ver 2.0.0. But now I can't upload a sketch. I get this message:

                      warning: espcomm_sync failed
                      error: espcomm_open failed
                      

                      Do you know what that means?

                      YveauxY 1 Reply Last reply
                      0
                      • AndurilA Anduril

                        @vampircik I don't realy understand what you tried to say. At the moment I have no real relays connected but simply LEDs for testing purposes.
                        @Yveaux I updated the ESP8266 definitions to ver 2.0.0. But now I can't upload a sketch. I get this message:

                        warning: espcomm_sync failed
                        error: espcomm_open failed
                        

                        Do you know what that means?

                        YveauxY Offline
                        YveauxY Offline
                        Yveaux
                        Mod
                        wrote on last edited by
                        #13

                        @Anduril said:

                        warning: espcomm_sync failed
                        error: espcomm_open failed

                        Did you select the right target board & settings? They did make some changes there with 2.0.0

                        http://yveaux.blogspot.nl

                        1 Reply Last reply
                        0
                        • AndurilA Offline
                          AndurilA Offline
                          Anduril
                          wrote on last edited by
                          #14

                          I just left them on standard as before...
                          just found one option named " reset mothode" which was ck and now I set it to nodemcu (only option that seems reasonable to me by it's name). Just worked to upload the sketch. I will do further tests and report back.

                          1 Reply Last reply
                          0
                          • AndurilA Offline
                            AndurilA Offline
                            Anduril
                            wrote on last edited by
                            #15

                            Still getting those strange numbers for relay status on or off. I will build another node to test this new constellation.

                            1 Reply Last reply
                            0
                            • AndurilA Offline
                              AndurilA Offline
                              Anduril
                              wrote on last edited by
                              #16

                              Now I tested with a third node the check. Also after node 3 sending data my 0 and 1 from the relay node become large numbers. One thing that seems strange to me is the behavior during reboot of the temp/hum node. First this node is active and sending temp and hum data. Readings from relay are strange as usual. When rebooting the relay signals turn to be 0 and 1 after the temp/hum node has presented itself to the gateway. But after sending the first data for temp/hum it is again receiving those large numbers. Does this make any sense for you @Yveaux?

                              1 Reply Last reply
                              0
                              • AndurilA Offline
                                AndurilA Offline
                                Anduril
                                wrote on last edited by
                                #17

                                I updated my gateway to newest dev version and now my nodes are communicating correctly (not updated, still 1.5.3). So the problem seems to be gone in 2.0, but I think it would still be nice to know what caused it for those not willing to upgrade to dev branch.
                                For @netram and @kr0815 (and maybe others) who had similiar problems: dev branch fixes this issue.

                                1 Reply Last reply
                                1
                                • N Offline
                                  N Offline
                                  netram
                                  wrote on last edited by
                                  #18

                                  Sweet! Thanks for the feedback @Anduril .

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  24

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  Posts


                                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                  • Login

                                  • Don't have an account? Register

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