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. Best practice for sending data from sensors.....?

Best practice for sending data from sensors.....?

Scheduled Pinned Locked Moved General Discussion
11 Posts 6 Posters 2.2k Views 6 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.
  • skywatchS Offline
    skywatchS Offline
    skywatch
    wrote on last edited by skywatch
    #1

    Just wondering if this is the best way to send data within mys node.
    Currently this node has 2 sensors, both with temp and hum. This is how I am using it.....

    #define CHILD_ID_FGEHUM 0
    #define CHILD_ID_FGETEMP 2
    #define CHILD_ID_FZRHUM 1
    #define CHILD_ID_FZRTEMP 3
    
    
    MyMessage msgFgeHum (CHILD_ID_FGEHUM,  V_HUM);
    MyMessage msgFgeTemp(CHILD_ID_FGETEMP, V_TEMP);
    MyMessage msgFzrHum (CHILD_ID_FZRHUM,  V_HUM);
    MyMessage msgFzrTemp(CHILD_ID_FZRTEMP, V_TEMP);
    
    
    void presentation()  
    { 
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_FGEHUM, S_HUM, "Fridge Hum");
      present(CHILD_ID_FZRHUM, S_HUM, "Freezer Hum");
      present(CHILD_ID_FGETEMP, S_TEMP, "Fridge Temp");
      present(CHILD_ID_FZRTEMP, S_TEMP, "Freezer Temp");
    }
    
     
    
    void loop(){
      // distracting stuff removed !!!
        send(msgFgeHum.set(fgehum));
        send(msgFzrHum.set(fzrhum));
        send(msgFgeTemp.set(fgetemp, 1));
        send(msgFzrTemp.set(fzrtemp, 1));
        }
    

    I wonder if this is considered the 'normal' or 'best' way to do this or if it can be made simpler?

    mfalkviddM 1 Reply Last reply
    0
    • skywatchS skywatch

      Just wondering if this is the best way to send data within mys node.
      Currently this node has 2 sensors, both with temp and hum. This is how I am using it.....

      #define CHILD_ID_FGEHUM 0
      #define CHILD_ID_FGETEMP 2
      #define CHILD_ID_FZRHUM 1
      #define CHILD_ID_FZRTEMP 3
      
      
      MyMessage msgFgeHum (CHILD_ID_FGEHUM,  V_HUM);
      MyMessage msgFgeTemp(CHILD_ID_FGETEMP, V_TEMP);
      MyMessage msgFzrHum (CHILD_ID_FZRHUM,  V_HUM);
      MyMessage msgFzrTemp(CHILD_ID_FZRTEMP, V_TEMP);
      
      
      void presentation()  
      { 
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_FGEHUM, S_HUM, "Fridge Hum");
        present(CHILD_ID_FZRHUM, S_HUM, "Freezer Hum");
        present(CHILD_ID_FGETEMP, S_TEMP, "Fridge Temp");
        present(CHILD_ID_FZRTEMP, S_TEMP, "Freezer Temp");
      }
      
       
      
      void loop(){
        // distracting stuff removed !!!
          send(msgFgeHum.set(fgehum));
          send(msgFzrHum.set(fzrhum));
          send(msgFgeTemp.set(fgetemp, 1));
          send(msgFzrTemp.set(fzrtemp, 1));
          }
      

      I wonder if this is considered the 'normal' or 'best' way to do this or if it can be made simpler?

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

      @skywatch yes this is the normal way

      M 1 Reply Last reply
      0
      • skywatchS Offline
        skywatchS Offline
        skywatch
        wrote on last edited by
        #3

        @mfalkvidd

        Thanks, I was getting in a bit of a muddle as I am only sending 2 types of data (temp and hum) and wondered if could I save memory by doing it differently? Perhaps not! :)

        mfalkviddM YveauxY 2 Replies Last reply
        0
        • skywatchS skywatch

          @mfalkvidd

          Thanks, I was getting in a bit of a muddle as I am only sending 2 types of data (temp and hum) and wondered if could I save memory by doing it differently? Perhaps not! :)

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

          @skywatch yes you probably could. But why?

          1 Reply Last reply
          0
          • skywatchS skywatch

            @mfalkvidd

            Thanks, I was getting in a bit of a muddle as I am only sending 2 types of data (temp and hum) and wondered if could I save memory by doing it differently? Perhaps not! :)

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

            @skywatch You could remove the MyMessage declarations at the top and rewrite the loop() to:

            void loop(){
              send( MyMessage(CHILD_ID_FGEHUM,  V_HUM ).set(fgehum) );
              send( MyMessage(CHILD_ID_FGETEMP, V_TEMP).set(fzrhum) );
              send( MyMessage(CHILD_ID_FZRHUM,  V_HUM ).set(fgetemp, 1) );
              send( MyMessage(CHILD_ID_FZRTEMP, V_TEMP).set(fzrtemp, 1) );
            }
            

            This frees RAM as the mymessage structures are declared temporarily on the stack for each invocation of send().

            http://yveaux.blogspot.nl

            O 1 Reply Last reply
            0
            • YveauxY Yveaux

              @skywatch You could remove the MyMessage declarations at the top and rewrite the loop() to:

              void loop(){
                send( MyMessage(CHILD_ID_FGEHUM,  V_HUM ).set(fgehum) );
                send( MyMessage(CHILD_ID_FGETEMP, V_TEMP).set(fzrhum) );
                send( MyMessage(CHILD_ID_FZRHUM,  V_HUM ).set(fgetemp, 1) );
                send( MyMessage(CHILD_ID_FZRTEMP, V_TEMP).set(fzrtemp, 1) );
              }
              

              This frees RAM as the mymessage structures are declared temporarily on the stack for each invocation of send().

              O Offline
              O Offline
              oneyb
              wrote on last edited by
              #6

              @yveaux

              nice tip; I am still getting into the proper mindset for memory conservation.

              To be clear, do you mean the following?

              void loop(){
                // for example
                float fgehum = myHumidity.readHumidity()
                send( MyMessage(CHILD_ID_FGEHUM,  V_HUM ).set(fgehum) );
              ...
              }
              

              Also, @mfalkvidd, why would you prefer to declare a MyMessage object instead of on the fly? I guess that there's overhead for creation of the object anew everytime. So there would be powersavings due to having a single and MyMessage object and then reusing it. Am I in the ballpark?

              YveauxY 1 Reply Last reply
              0
              • O oneyb

                @yveaux

                nice tip; I am still getting into the proper mindset for memory conservation.

                To be clear, do you mean the following?

                void loop(){
                  // for example
                  float fgehum = myHumidity.readHumidity()
                  send( MyMessage(CHILD_ID_FGEHUM,  V_HUM ).set(fgehum) );
                ...
                }
                

                Also, @mfalkvidd, why would you prefer to declare a MyMessage object instead of on the fly? I guess that there's overhead for creation of the object anew everytime. So there would be powersavings due to having a single and MyMessage object and then reusing it. Am I in the ballpark?

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

                @oneyb said in Best practice for sending data from sensors.....?:

                To be clear, do you mean the following?

                Yes!

                Also, @mfalkvidd, why would you prefer to declare a MyMessage object instead of on the fly? I guess that there's overhead for creation of the object anew everytime. So there would be powersavings due to having a single and MyMessage object and then reusing it. Am I in the ballpark?

                Yes, you could save some cpu power (and energy) by preallocating and configuring the mymessage instances. It all depends on your requirements ;-)

                http://yveaux.blogspot.nl

                mfalkviddM 1 Reply Last reply
                0
                • YveauxY Yveaux

                  @oneyb said in Best practice for sending data from sensors.....?:

                  To be clear, do you mean the following?

                  Yes!

                  Also, @mfalkvidd, why would you prefer to declare a MyMessage object instead of on the fly? I guess that there's overhead for creation of the object anew everytime. So there would be powersavings due to having a single and MyMessage object and then reusing it. Am I in the ballpark?

                  Yes, you could save some cpu power (and energy) by preallocating and configuring the mymessage instances. It all depends on your requirements ;-)

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

                  @yveaux said in Best practice for sending data from sensors.....?:

                  Yes, you could save some cpu power (and energy) by preallocating and configuring the mymessage instances. It all depends on your requirements ;-)

                  This is my reason for asking "why". There are a lot of trade-offs. Cpu/energy usage, ram usage, flash usage, code readability, code maintainability...

                  1 Reply Last reply
                  0
                  • mfalkviddM mfalkvidd

                    @skywatch yes this is the normal way

                    M Offline
                    M Offline
                    mljbr4
                    wrote on last edited by
                    #9

                    @mfalkvidd I would think ‘best practice’ for a temperature (and humidity) sensor is to “send only if changed”.
                    I have many Dallas 1-wire temperature sensors on one Arduino and I have an array to store last value sent
                    I also sleep for a second after a polling loop. And every minute I send the temperatures regardless of whether they have changed or not.
                    I have not done this but for truly best practice I would add ‘anti-flapping’ logic to prevent constant updates when a thermometer is reading ‘between’ two values.

                    1 Reply Last reply
                    0
                    • bjacobseB Offline
                      bjacobseB Offline
                      bjacobse
                      wrote on last edited by
                      #10

                      Domoticz have a sensor timout, and makes the icon red if the timeout appears, so regardless it's required to occasionally (1 or 2 times per day) to send a "heartbeat"/alive message. I know this timeout in Domoticz can be changed, but it's a nice feature.

                      1 Reply Last reply
                      0
                      • skywatchS Offline
                        skywatchS Offline
                        skywatch
                        wrote on last edited by
                        #11

                        Thanks for some interesting info!

                        The reason is 1. To save memory for adding more sensors, signing etc and 2. To save battery energy on battery nodes. So there is likely more than one solution to this problem.

                        Also, I have used 'for' loops as well and wonder how this affects memory and battery drain?

                        Thanks

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


                        23

                        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