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. Announcements
  3. 💬 Temperature Sensor

💬 Temperature Sensor

Scheduled Pinned Locked Moved Announcements
171 Posts 40 Posters 54.8k Views 36 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.
  • gohanG Offline
    gohanG Offline
    gohan
    Mod
    wrote on last edited by
    #67

    It will present different sensros according to the #define MAX_ATTACHED_DS18B20 16

    1 Reply Last reply
    0
    • DigdoggerD Offline
      DigdoggerD Offline
      Digdogger
      wrote on last edited by
      #68

      Hi,
      I have only one sensor on the mini pro and I have this in the logs:
      2017-07-30 14:41:28.492 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.497 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.501 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.506 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.510 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.515 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.521 (Mysensor) Temp (Congélateur)
      2017-07-30 14:41:28.526 (Mysensor) Temp (Congélateur)

      Sleep time is set to 60000ms, why the time between 2 messages is around 5ms???

      mfalkviddM 1 Reply Last reply
      0
      • DigdoggerD Digdogger

        Hi,
        I have only one sensor on the mini pro and I have this in the logs:
        2017-07-30 14:41:28.492 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.497 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.501 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.506 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.510 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.515 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.521 (Mysensor) Temp (Congélateur)
        2017-07-30 14:41:28.526 (Mysensor) Temp (Congélateur)

        Sleep time is set to 60000ms, why the time between 2 messages is around 5ms???

        mfalkviddM Online
        mfalkviddM Online
        mfalkvidd
        Mod
        wrote on last edited by mfalkvidd
        #69

        @Digdogger it can depend on a lot of things. The best way to know is to look at the debug logs from the node and the gateway from the time when it happened. There could be a problem with the communication, with the radios, with the power supply, with the sketch, etc.

        It could also be that you're using a microcontroller that doesn't support MySensors sleep, such as the esp8266. But it is just a guess. The information that's usually needed to troubleshoot is listed in https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/

        1 Reply Last reply
        0
        • DigdoggerD Offline
          DigdoggerD Offline
          Digdogger
          wrote on last edited by
          #70

          OK thanks mfalkvidd

          1 Reply Last reply
          1
          • ben999B Offline
            ben999B Offline
            ben999
            wrote on last edited by
            #71

            Slightly off-topic here... but related to this particular sketch

            If you look close enough (and copy-paste the sketch into your IDE) you'll witness that one curly-bracket is technically missing at the end of loop()...

            But as I added it to the sketch I got error

            Sketch compiles fine "with" the missing curly-bracket... ???

            Any comment to that (in my sense) funny behavior ?

            mfalkviddM 1 Reply Last reply
            0
            • ben999B ben999

              Slightly off-topic here... but related to this particular sketch

              If you look close enough (and copy-paste the sketch into your IDE) you'll witness that one curly-bracket is technically missing at the end of loop()...

              But as I added it to the sketch I got error

              Sketch compiles fine "with" the missing curly-bracket... ???

              Any comment to that (in my sense) funny behavior ?

              mfalkviddM Online
              mfalkviddM Online
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #72

              @ben999 the simple answer is probably that the backet isn't missing :)

              Can you show why you think it is missing?

              1 Reply Last reply
              0
              • ben999B Offline
                ben999B Offline
                ben999
                wrote on last edited by ben999
                #73

                @mfalkvidd

                I must have gone mad then :ghost:

                Check the loop()
                The last closing curly--bracket is for

                for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                

                So which one closes

                void loop()     {  
                

                If i add one more to "make it right" then hell brakes loose...

                sketch_jul31a:110: error: expected declaration before '}' token
                 }
                 ^
                exit status 1
                expected declaration before '}' token
                

                1-That's the only sketch behaving this way
                2-Even the "IDE-automatic-opening-bracket-finder" (shows which bracket is open when placing cursor on closing bracket) can NOT find the right bracket for loop()...

                :scream:

                1 Reply Last reply
                0
                • mfalkviddM Online
                  mfalkviddM Online
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #74

                  Interesting observation @ben999

                  This is caused by the preprocessing directives.

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

                  Only one of these if statements will be active. The Arduino IDE probably doesn't evaluate preprocessing directives, so it sees two if statements and therefore thinks it should see two end braces. A way to "fix" this could be to move the starting curly brace to after the preprocessing directives:

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

                  This allows the Arduino IDE to parse the code correctly, and correctly match the braces.

                  ben999B 1 Reply Last reply
                  1
                  • gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by
                    #75

                    It's time to move to a better IDE 😁

                    1 Reply Last reply
                    0
                    • mfalkviddM mfalkvidd

                      Interesting observation @ben999

                      This is caused by the preprocessing directives.

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

                      Only one of these if statements will be active. The Arduino IDE probably doesn't evaluate preprocessing directives, so it sees two if statements and therefore thinks it should see two end braces. A way to "fix" this could be to move the starting curly brace to after the preprocessing directives:

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

                      This allows the Arduino IDE to parse the code correctly, and correctly match the braces.

                      ben999B Offline
                      ben999B Offline
                      ben999
                      wrote on last edited by
                      #76

                      @mfalkvidd
                      Gosh you're a genius ! And you share your knowledge with style and simple explanation ! But i can only upvote you once :D

                      @gohan
                      No way :D IDE is nice and simple for nice and simple people like me :rabbit:

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        chaeron
                        wrote on last edited by
                        #77

                        I just upgraded to the MYS 2.1.1 version.

                        My OneWire temperature sensors were not detected!

                        I moved the sensors.begin() from setup() to before(), and that seems to have fixed things, and my temp sensors are being detected and read now.

                        Anyone know why the OneWire library has to be initialized before MySensors setup?

                        Thanks!

                        rejoe2R 1 Reply Last reply
                        0
                        • C chaeron

                          I just upgraded to the MYS 2.1.1 version.

                          My OneWire temperature sensors were not detected!

                          I moved the sensors.begin() from setup() to before(), and that seems to have fixed things, and my temp sensors are being detected and read now.

                          Anyone know why the OneWire library has to be initialized before MySensors setup?

                          Thanks!

                          rejoe2R Offline
                          rejoe2R Offline
                          rejoe2
                          wrote on last edited by
                          #78

                          @chaeron I assume, you used an old version of the sketch.

                          Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
                          setup()=>presentation()
                          to
                          before()=>presentation()=>setup().

                          So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).

                          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                          C 1 Reply Last reply
                          0
                          • rejoe2R rejoe2

                            @chaeron I assume, you used an old version of the sketch.

                            Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
                            setup()=>presentation()
                            to
                            before()=>presentation()=>setup().

                            So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).

                            C Offline
                            C Offline
                            chaeron
                            wrote on last edited by
                            #79

                            @rejoe2 said in 💬 Temperature Sensor:

                            @chaeron I assume, you used an old version of the sketch.

                            That is correct....the original code was written over a year ago. Trying to run it under 2.1.1 caused it to fail.

                            Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
                            setup()=>presentation()
                            to
                            before()=>presentation()=>setup().

                            So where was this rather major change documented? It would probably have broken any 1-Wire examples, including the temperature one.

                            So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).

                            So I figured out....I went looking for documentation on this rather significant change and was not able to find it noted anywhere.

                            rejoe2R 1 Reply Last reply
                            0
                            • C chaeron

                              @rejoe2 said in 💬 Temperature Sensor:

                              @chaeron I assume, you used an old version of the sketch.

                              That is correct....the original code was written over a year ago. Trying to run it under 2.1.1 caused it to fail.

                              Your question most likely is related to a change in the order of the initialisation. This has changed in Version 2.2: from
                              setup()=>presentation()
                              to
                              before()=>presentation()=>setup().

                              So where was this rather major change documented? It would probably have broken any 1-Wire examples, including the temperature one.

                              So also the initialisation of sensors had to be reviewed accordingly (eg. to get the number of devices).

                              So I figured out....I went looking for documentation on this rather significant change and was not able to find it noted anywhere.

                              rejoe2R Offline
                              rejoe2R Offline
                              rejoe2
                              wrote on last edited by
                              #80

                              There was a rather small note in the 2.0.0 changelog about the introduction of before().

                              Btw: Another functional routine (preHwInit() (?)) may have been introduced also with 2.1.1 (?). But until now, all of my sketches and tests got along without this preHwInit() functionality. But imo the new structure is pretty good: before() is helpfull to initialise SPI devices on same bus as nRF24 and to collect relevant info like the number of DS18x20, setup() is now also good to send info you only need once (e.g. the Dallas-Chip-ID).

                              The rest is - at least afaik - not really documented well, but most examples (if you use the updated ones) will work (apart from the DS18x20 example, where other - external - code changes made some parts tricky to use.

                              I made some working sketches for the Dallas Sensors some time ago based on some ideas I found here in the MySensors forum; they mostly should still work (exept for the change of getConfig() to getControllerConfig()). If you are interested: here .

                              Kind regards

                              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                              rejoe2R 1 Reply Last reply
                              2
                              • rejoe2R Offline
                                rejoe2R Offline
                                rejoe2
                                wrote on last edited by rejoe2
                                #81

                                If anyone is interested:

                                The sketches in my repo have been updated yesterday for complete compability with the new structure and syntax. They compile fine and should work, but I didn't have the time to make functional tests also.
                                If anyone is interested, I could also add a multibus example with several Sensors at each bus and different timings for each bus. One of my nodes is working on this concept for several days now (Heizung, RS485 version), so I'm pretty confident this will reliably work for longer periods. But it's rather special:grinning: .

                                Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

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

                                  @rejoe2
                                  Where do we find your repo then?

                                  1 Reply Last reply
                                  0
                                  • rejoe2R rejoe2

                                    There was a rather small note in the 2.0.0 changelog about the introduction of before().

                                    Btw: Another functional routine (preHwInit() (?)) may have been introduced also with 2.1.1 (?). But until now, all of my sketches and tests got along without this preHwInit() functionality. But imo the new structure is pretty good: before() is helpfull to initialise SPI devices on same bus as nRF24 and to collect relevant info like the number of DS18x20, setup() is now also good to send info you only need once (e.g. the Dallas-Chip-ID).

                                    The rest is - at least afaik - not really documented well, but most examples (if you use the updated ones) will work (apart from the DS18x20 example, where other - external - code changes made some parts tricky to use.

                                    I made some working sketches for the Dallas Sensors some time ago based on some ideas I found here in the MySensors forum; they mostly should still work (exept for the change of getConfig() to getControllerConfig()). If you are interested: here .

                                    Kind regards

                                    rejoe2R Offline
                                    rejoe2R Offline
                                    rejoe2
                                    wrote on last edited by
                                    #83

                                    @chaeron
                                    Thx for asking.

                                    Repo-link was mentioned above, @rejoe2 said in 💬 Temperature Sensor:

                                    If you are interested: here .

                                    Btw: the sketches have been updated and compile now also with MySensors 2.2.0-beta. But to be honest, I didn't test them with hardware until now. So feedback is appreciated :simple_smile:.

                                    Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                                    1 Reply Last reply
                                    1
                                    • rejoe2R Offline
                                      rejoe2R Offline
                                      rejoe2
                                      wrote on last edited by
                                      #84

                                      Additionally: There is also a multibus version included that uses different timings for reading each of the buses.
                                      For using this sketch, I'm not sure wheter some changes in the DallasTemperature-lib also is required (it is based on an very recent example of the maintainer's guthub version; should be linked in the Arduino Library Manager; I myself applied some changes wrt. this in my local libs).
                                      I may aslo post this in case anyone's interested (and these mods are necessary).

                                      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                                      DickD 1 Reply Last reply
                                      0
                                      • rejoe2R rejoe2

                                        Additionally: There is also a multibus version included that uses different timings for reading each of the buses.
                                        For using this sketch, I'm not sure wheter some changes in the DallasTemperature-lib also is required (it is based on an very recent example of the maintainer's guthub version; should be linked in the Arduino Library Manager; I myself applied some changes wrt. this in my local libs).
                                        I may aslo post this in case anyone's interested (and these mods are necessary).

                                        DickD Offline
                                        DickD Offline
                                        Dick
                                        wrote on last edited by Dick
                                        #85

                                        @rejoe2 Any idea why the DallasTemperatureSimple from your GitHub not presenting in Domoticz?

                                        /**
                                           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.
                                        
                                         *******************************
                                        
                                           DESCRIPTION
                                        
                                           Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                           http://www.mysensors.org/build/temp
                                           Enhanced Version also sending the Dallas-ROM-ID, MySensors Version >=2.1.0
                                        */
                                        
                                        // Enable debug prints to serial monitor
                                        #define MY_DEBUG
                                        
                                        // Enable and select radio type attached
                                        #define MY_RADIO_NRF24
                                        //#define MY_RADIO_RFM69
                                        
                                        #include <SPI.h>
                                        #include <MySensors.h>
                                        #include <DallasTemperature.h>
                                        #include <OneWire.h>
                                        
                                        #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
                                        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                        #define MAX_ATTACHED_DS18B20 16
                                        uint8_t DS_First_Child_ID = 7; //First Child-ID to be used by Dallas Bus; set this to be higher than other Child-ID's who need EEPROM storage to avoid conflicts
                                        unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                                        OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                        DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
                                        float lastTemperature[MAX_ATTACHED_DS18B20];
                                        int numSensors = 0;
                                        bool receivedConfig = false;
                                        bool metric = true;
                                        DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
                                        int resolution = 12; // precision: 12 bits = 0.0625°C, 11 bits = 0.125°C, 10 bits = 0.25°C, 9 bits = 0.5°C
                                        int conversionTime = 0;
                                        // Initialize temperature message
                                        MyMessage msgTemp(0, V_TEMP);
                                        MyMessage msgId(0, V_ID);
                                        
                                        char* charAddr = "Check for faults";
                                        #define SEND_ID
                                        
                                        void before()
                                        {
                                          // 12 bits = 750 ms, 11 bits = 375ms, 10 bits = 187.5ms, 9 bits = 93.75ms
                                          conversionTime = 750 / (1 << (12 - resolution));
                                          // Startup up the OneWire library
                                          sensors.begin();
                                        }
                                        
                                        void presentation() {
                                          // Send the sketch version information to the gateway and Controller
                                          sendSketchInfo("Temperature Sensor", "1.2");
                                        
                                          // Fetch the number of attached temperature sensors
                                          numSensors = sensors.getDeviceCount();
                                        
                                          // Present all sensors to controller
                                          for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                            sensors.getAddress(tempDeviceAddress, i);
                                            charAddr = addrToChar(tempDeviceAddress);
                                            present(i + DS_First_Child_ID, S_TEMP, charAddr);
                                        #ifdef MY_DEBUG
                                            Serial.println(charAddr);
                                        #endif
                                          }
                                        }
                                        
                                        void setup()
                                        {
                                          // requestTemperatures() will not block current thread
                                          sensors.setWaitForConversion(false);
                                        
                                          for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                            sensors.getAddress(tempDeviceAddress, i);
                                        #ifdef SEND_ID
                                            // 8 will assure a length of 16 of the sent ROM-ID
                                            send(msgId.setSensor(i + DS_First_Child_ID).set(tempDeviceAddress, 8));
                                        #endif
                                            sensors.setResolution(tempDeviceAddress, resolution);
                                            metric = getControllerConfig().isMetric;
                                          }
                                        }
                                        
                                        
                                        void loop()
                                        {
                                          // Fetch temperatures from Dallas sensors
                                          sensors.requestTemperatures();
                                        
                                          // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                          sleep(conversionTime);
                                        
                                          // Read temperatures and send them to controller
                                          for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                        
                                            // Fetch and round temperature to one decimal
                                            float temperature = static_cast<float>(static_cast<int>((metric ? 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
                                              send(msgTemp.setSensor(i + DS_First_Child_ID).set(temperature, 1));
                                              wait(20);
                                              // Save new temperatures for next compare
                                              lastTemperature[i] = temperature;
                                            }
                                          }
                                        
                                          // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                          sleep(SLEEP_TIME);
                                        }
                                        
                                        char* addrToChar(uint8_t* data) {
                                          String strAddr = String(data[0], HEX); //Chip Version; should be higher than 16
                                          byte first ;
                                          int j = 0;
                                          for (uint8_t i = 1; i < 8; i++) {
                                            if (data[i] < 16) strAddr = strAddr + 0;
                                            strAddr = strAddr + String(data[i], HEX);
                                            strAddr.toUpperCase();
                                          }
                                          for (int j = 0; j < 16; j++) {
                                            charAddr[j] = strAddr[j];
                                          }
                                          return charAddr;
                                        }
                                        
                                        
                                        gohanG 1 Reply Last reply
                                        0
                                        • DickD Dick

                                          @rejoe2 Any idea why the DallasTemperatureSimple from your GitHub not presenting in Domoticz?

                                          /**
                                             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.
                                          
                                           *******************************
                                          
                                             DESCRIPTION
                                          
                                             Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                             http://www.mysensors.org/build/temp
                                             Enhanced Version also sending the Dallas-ROM-ID, MySensors Version >=2.1.0
                                          */
                                          
                                          // Enable debug prints to serial monitor
                                          #define MY_DEBUG
                                          
                                          // Enable and select radio type attached
                                          #define MY_RADIO_NRF24
                                          //#define MY_RADIO_RFM69
                                          
                                          #include <SPI.h>
                                          #include <MySensors.h>
                                          #include <DallasTemperature.h>
                                          #include <OneWire.h>
                                          
                                          #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
                                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                          #define MAX_ATTACHED_DS18B20 16
                                          uint8_t DS_First_Child_ID = 7; //First Child-ID to be used by Dallas Bus; set this to be higher than other Child-ID's who need EEPROM storage to avoid conflicts
                                          unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                                          OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                          DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
                                          float lastTemperature[MAX_ATTACHED_DS18B20];
                                          int numSensors = 0;
                                          bool receivedConfig = false;
                                          bool metric = true;
                                          DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
                                          int resolution = 12; // precision: 12 bits = 0.0625°C, 11 bits = 0.125°C, 10 bits = 0.25°C, 9 bits = 0.5°C
                                          int conversionTime = 0;
                                          // Initialize temperature message
                                          MyMessage msgTemp(0, V_TEMP);
                                          MyMessage msgId(0, V_ID);
                                          
                                          char* charAddr = "Check for faults";
                                          #define SEND_ID
                                          
                                          void before()
                                          {
                                            // 12 bits = 750 ms, 11 bits = 375ms, 10 bits = 187.5ms, 9 bits = 93.75ms
                                            conversionTime = 750 / (1 << (12 - resolution));
                                            // Startup up the OneWire library
                                            sensors.begin();
                                          }
                                          
                                          void presentation() {
                                            // Send the sketch version information to the gateway and Controller
                                            sendSketchInfo("Temperature Sensor", "1.2");
                                          
                                            // Fetch the number of attached temperature sensors
                                            numSensors = sensors.getDeviceCount();
                                          
                                            // Present all sensors to controller
                                            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                              sensors.getAddress(tempDeviceAddress, i);
                                              charAddr = addrToChar(tempDeviceAddress);
                                              present(i + DS_First_Child_ID, S_TEMP, charAddr);
                                          #ifdef MY_DEBUG
                                              Serial.println(charAddr);
                                          #endif
                                            }
                                          }
                                          
                                          void setup()
                                          {
                                            // requestTemperatures() will not block current thread
                                            sensors.setWaitForConversion(false);
                                          
                                            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                              sensors.getAddress(tempDeviceAddress, i);
                                          #ifdef SEND_ID
                                              // 8 will assure a length of 16 of the sent ROM-ID
                                              send(msgId.setSensor(i + DS_First_Child_ID).set(tempDeviceAddress, 8));
                                          #endif
                                              sensors.setResolution(tempDeviceAddress, resolution);
                                              metric = getControllerConfig().isMetric;
                                            }
                                          }
                                          
                                          
                                          void loop()
                                          {
                                            // Fetch temperatures from Dallas sensors
                                            sensors.requestTemperatures();
                                          
                                            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                            sleep(conversionTime);
                                          
                                            // Read temperatures and send them to controller
                                            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
                                          
                                              // Fetch and round temperature to one decimal
                                              float temperature = static_cast<float>(static_cast<int>((metric ? 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
                                                send(msgTemp.setSensor(i + DS_First_Child_ID).set(temperature, 1));
                                                wait(20);
                                                // Save new temperatures for next compare
                                                lastTemperature[i] = temperature;
                                              }
                                            }
                                          
                                            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                            sleep(SLEEP_TIME);
                                          }
                                          
                                          char* addrToChar(uint8_t* data) {
                                            String strAddr = String(data[0], HEX); //Chip Version; should be higher than 16
                                            byte first ;
                                            int j = 0;
                                            for (uint8_t i = 1; i < 8; i++) {
                                              if (data[i] < 16) strAddr = strAddr + 0;
                                              strAddr = strAddr + String(data[i], HEX);
                                              strAddr.toUpperCase();
                                            }
                                            for (int j = 0; j < 16; j++) {
                                              charAddr[j] = strAddr[j];
                                            }
                                            return charAddr;
                                          }
                                          
                                          
                                          gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #86

                                          @Dick you are missing

                                          #define MY_NODE_ID x

                                          where x is the unique sensor ID you want to assign to node. If look in the gateway or node log you will see the node asking for an ID

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


                                          26

                                          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