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. General Discussion
  3. [SOLVED] Too frequent updates form DHT

[SOLVED] Too frequent updates form DHT

Scheduled Pinned Locked Moved General Discussion
14 Posts 2 Posters 2.4k 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.
  • archiijsA Offline
    archiijsA Offline
    archiijs
    wrote on last edited by
    #3

    @mfalkvidd said in Too frequent updates form DHT:

    because sleep is not supported on esp8266. Try using wait instead.

    Hi, and thanks for the response.
    Well, I'm not really interested in sleep, all my nodes are AC powered. Can you guide me to some example using wait, thanks in advance.

    mfalkviddM 1 Reply Last reply
    0
    • archiijsA archiijs

      @mfalkvidd said in Too frequent updates form DHT:

      because sleep is not supported on esp8266. Try using wait instead.

      Hi, and thanks for the response.
      Well, I'm not really interested in sleep, all my nodes are AC powered. Can you guide me to some example using wait, thanks in advance.

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #4

      @archiijs just replace the letters sleep with wait in your code.

      1 Reply Last reply
      1
      • archiijsA Offline
        archiijsA Offline
        archiijs
        wrote on last edited by
        #5

        @mfalkvidd said in Too frequent updates form DHT:

        wait

        That was easier than expected, thanks for your advice, seems to do the trick. Will apply this to all my nodes now and test.

        Thanks for your fast replays.

        mfalkviddM 1 Reply Last reply
        1
        • archiijsA archiijs

          @mfalkvidd said in Too frequent updates form DHT:

          wait

          That was easier than expected, thanks for your advice, seems to do the trick. Will apply this to all my nodes now and test.

          Thanks for your fast replays.

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #6

          @archiijs great! Thanks for reporting back.

          1 Reply Last reply
          0
          • archiijsA Offline
            archiijsA Offline
            archiijs
            wrote on last edited by archiijs
            #7

            @mfalkvidd
            Hi again.
            I got small problem that emerged after this change. When I try to use my wall switches nothing happens, I still can turn on/off all lights from controller without problems, only localy attached switches do not work and that is not an option.

            so the problem lies in this line, if I understand correctly

              // Sleep for a while to save energy
              sleep(UPDATE_INTERVAL); 
            

            if I change sleep to wait, so I'm back to the beginning now. Is there any way to fix this?

            mfalkviddM 1 Reply Last reply
            0
            • archiijsA archiijs

              @mfalkvidd
              Hi again.
              I got small problem that emerged after this change. When I try to use my wall switches nothing happens, I still can turn on/off all lights from controller without problems, only localy attached switches do not work and that is not an option.

              so the problem lies in this line, if I understand correctly

                // Sleep for a while to save energy
                sleep(UPDATE_INTERVAL); 
              

              if I change sleep to wait, so I'm back to the beginning now. Is there any way to fix this?

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #8

              @archiijs I would remove the wait/sleep and change

              else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS)
              

              to

              else if (temperature != lastTemp)
              

              That will cause the temperature to be sent whenever it has changed.

              There are several other ways to get a similar result. What is best depends on how you want the node to behave.

              1 Reply Last reply
              0
              • archiijsA Offline
                archiijsA Offline
                archiijs
                wrote on last edited by archiijs
                #9

                @mfalkvidd Thanks again for your response.
                I just changed else if functions as you suggested and uncommented wait/sleep(update_interval);
                Actually, I think that I had code like this couple days before...

                The result is kind of what is needed, I get new values as they change, BUT they change all the time. Like my temperature just changes true 21.7 to 21.6 to 21.7 to 21.8 an ower and ower again nonstop, same with humidity.

                EDIT: Just switched out DHT sensor for anorther and nothing has changed.

                mfalkviddM 1 Reply Last reply
                0
                • archiijsA archiijs

                  @mfalkvidd Thanks again for your response.
                  I just changed else if functions as you suggested and uncommented wait/sleep(update_interval);
                  Actually, I think that I had code like this couple days before...

                  The result is kind of what is needed, I get new values as they change, BUT they change all the time. Like my temperature just changes true 21.7 to 21.6 to 21.7 to 21.8 an ower and ower again nonstop, same with humidity.

                  EDIT: Just switched out DHT sensor for anorther and nothing has changed.

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #10

                  @archiijs you either need to add som hysteresis (only send update if the temperature has changed with X amount, for example 1 degree) or a time limit (never send updates unless X time has passed since last send, for example 5 minutes)

                  1 Reply Last reply
                  0
                  • archiijsA Offline
                    archiijsA Offline
                    archiijs
                    wrote on last edited by archiijs
                    #11

                    @mfalkvidd That sounds about right. But sadly I can not find any examples of such sensors and I'm not sure if I could figure this out by myself :/

                    mfalkviddM 1 Reply Last reply
                    0
                    • archiijsA archiijs

                      @mfalkvidd That sounds about right. But sadly I can not find any examples of such sensors and I'm not sure if I could figure this out by myself :/

                      mfalkviddM Offline
                      mfalkviddM Offline
                      mfalkvidd
                      Mod
                      wrote on last edited by
                      #12

                      Hysteresis: https://forum.mysensors.org/post/66870
                      Timer: https://forum.mysensors.org/post/70243

                      1 Reply Last reply
                      0
                      • archiijsA Offline
                        archiijsA Offline
                        archiijs
                        wrote on last edited by
                        #13

                        @mfalkvidd Superb, I will study your suggestions and report back. Thanks again for your patience with me.

                        1 Reply Last reply
                        1
                        • archiijsA Offline
                          archiijsA Offline
                          archiijs
                          wrote on last edited by
                          #14

                          Hi @mfalkvidd and others.

                          Yesterday after work I tried to get my head around code suggestions but somehow I cold not make them work so I did some google search and after some time I find something that I implemented in my nodes for testing.
                          Interestingly it works as expected for two of my nodes, but one still keeps jumping around, not that often, but that's still strange, I will compare code to other two to see what I've done wrong there.
                          So I used Hysteresis approach by doing this.

                          #define HYSTERISIS    0.5        // Hysteresis for sensor 
                          
                          ...
                          
                            float temperature = dht.getTemperature();
                            if (isnan(temperature)) {
                              Serial.println("Failed reading temperature from DHT!");
                            } else if (abs(temperature - lastTemp ) > HYSTERISIS) {
                              // 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);
                              }
                          
                          

                          And the same for humidity.

                          Still not sure that this will work as expected in long run, but will see.
                          But now it is way better than before. Thanks.

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


                          10

                          Online

                          11.7k

                          Users

                          11.2k

                          Topics

                          113.0k

                          Posts


                          Copyright 2019 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