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. Feature Requests
  3. Example code - DallasTemperatureSensor.ino

Example code - DallasTemperatureSensor.ino

Scheduled Pinned Locked Moved Feature Requests
8 Posts 3 Posters 2.9k Views 3 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.
  • F Offline
    F Offline
    flopp
    wrote on last edited by
    #1

    below is copied from the example sketch.

    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    
    void loop()     
    {     
         // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
     
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
     
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
      }
      gw.sleep(SLEEP_TIME);
    }
    
    

    If I have COMPARE_TEMP = 1 it will check if the new value is new and then send it to GW, if not new it will not send to GW.

    I want data even if the temperature is same so I have COMPARE_TEMP = 0.

    With my choose it will not test if the temperature is -127.00 or 85.00, this is something I want to do all the time even if I compare or not.

    1 Reply Last reply
    0
    • tlpeterT Offline
      tlpeterT Offline
      tlpeter
      wrote on last edited by
      #2

      I think you just have to comment out that part of the code (the 5 lines of code)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        flopp
        wrote on last edited by flopp
        #3

        I have done that in my sketch.

        But my request is that the example should always check for -127 and 85, even if the user want to compare old value with new

        1 Reply Last reply
        0
        • tlpeterT Offline
          tlpeterT Offline
          tlpeter
          wrote on last edited by
          #4

          In the 2.0 sketch this is mentioned:

          #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
          So 0 should keep everything working and sens info even when not changed.

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

            As tlpeter mentioned, the MySensors 2.0 example checks for -127 and 85 even if COMPARE_TEMP is not set to 1. See https://github.com/mysensors/MySensorsArduinoExamples/blob/e31eb10311be071d376d55d0e23133b611a565ef/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino#L96

            1 Reply Last reply
            1
            • F Offline
              F Offline
              flopp
              wrote on last edited by flopp
              #6

              I am sorry, I have low knowledge of the # sign.

              I have read about it and @tlpeter is right.

              Can you confirm that my knowledge is correct.

              #if COMPARE_TEMP == 1
              if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
              #else
              if (temperature != -127.00 && temperature != 85.00) {
              #endif
              

              if I have COMPARE_TEMP = 1, this will be compiled

              if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
              

              otherwise this will be compiled

              if (temperature != -127.00 && temperature != 85.00) {
              

              Sorry once again :no_mouth:

              mfalkviddM 1 Reply Last reply
              0
              • F flopp

                I am sorry, I have low knowledge of the # sign.

                I have read about it and @tlpeter is right.

                Can you confirm that my knowledge is correct.

                #if COMPARE_TEMP == 1
                if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                #else
                if (temperature != -127.00 && temperature != 85.00) {
                #endif
                

                if I have COMPARE_TEMP = 1, this will be compiled

                if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                

                otherwise this will be compiled

                if (temperature != -127.00 && temperature != 85.00) {
                

                Sorry once again :no_mouth:

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

                yes @flopp you got it right :)

                F 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  yes @flopp you got it right :)

                  F Offline
                  F Offline
                  flopp
                  wrote on last edited by
                  #8

                  @mfalkvidd
                  :dancer:

                  1 Reply Last reply
                  1

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  14

                  Online

                  12.0k

                  Users

                  11.2k

                  Topics

                  113.4k

                  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