Skip to content
  • 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
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

💬 Temperature Sensor

Scheduled Pinned Locked Moved Announcements
171 Posts 40 Posters 54.7k 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.
  • DickD Dick

    @mfalkvidd I chaned the Sleep into Wait but the same log in both Domoticz and on my Arduino. I thought it was an easy go but it appear not to be.

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

    @Dick Did you change it at both places ( sleep(conversionTime);)?

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

    DickD 1 Reply Last reply
    0
    • rejoe2R rejoe2

      @Dick Did you change it at both places ( sleep(conversionTime);)?

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

      @rejoe2 Yes on both location I replaced the sleep into a wait

      1 Reply Last reply
      0
      • mfalkviddM mfalkvidd

        @Dick this part

        2201 !MCO:SLP:REP
        

        of the initial log you posted says that the node cannot sleep because it is a repeater.

        This part of the sketch:

          // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
          sleep(conversionTime);
        

        explains that if the node is a repeater, the sleep call must be replaced by wait. If it is not replaced, the temperature sensors will not be ready when getTemp... is called, so the node will not send any values. Domoticz only lists sensors that have sent a value.

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

        @mfalkvidd In the Arduino log he Sleep error is not i anymore so that is solved but still no new device in Domoticz

        1 Reply Last reply
        0
        • DickD Dick

          @mfalkvidd I chaned the Sleep into Wait but the same log in both Domoticz and on my Arduino. I thought it was an easy go but it appear not to be.

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

          @Dick if you get the same log on the Arduino as before changing to wait, the sketch upload must have failed. Perhaps your Arduino is broken?
          Edit: Sorry, didn't see your last reply.

          What does the node log say now?

          DickD 1 Reply Last reply
          0
          • mfalkviddM mfalkvidd

            @Dick if you get the same log on the Arduino as before changing to wait, the sketch upload must have failed. Perhaps your Arduino is broken?
            Edit: Sorry, didn't see your last reply.

            What does the node log say now?

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

            @mfalkvidd Ths is what the log says
            0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
            3 MCO:BGN:BFR
            6 TSM:INIT
            7 TSF:WUR:MS=0
            14 TSM:INIT:TSP OK
            16 TSF:SID:OK,ID=12
            18 TSM:FPAR
            59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
            1016 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
            1021 TSF:MSG:FPAR OK,ID=0,D=1
            1804 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
            1851 TSF:MSG:READ,4-4-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
            2067 TSM:FPAR:OK
            2068 TSM:ID
            2069 TSM:ID:OK
            2071 TSM:UPL
            2075 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
            2087 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
            2093 TSF:MSG:PONG RECV,HP=1
            2095 TSM:UPL:OK
            2097 TSM:READY:ID=12,PAR=0,DIS=1
            2102 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
            2111 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
            2119 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
            2128 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
            2144 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
            2152 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
            2163 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
            2169 MCO:REG:REQ
            2173 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
            2183 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
            2188 MCO:PIM:NODE REG=1
            2190 MCO:BGN:STP
            2192 MCO:BGN:INIT OK,TSP=1

            mfalkviddM 1 Reply Last reply
            0
            • DickD Dick

              @mfalkvidd Ths is what the log says
              0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
              3 MCO:BGN:BFR
              6 TSM:INIT
              7 TSF:WUR:MS=0
              14 TSM:INIT:TSP OK
              16 TSF:SID:OK,ID=12
              18 TSM:FPAR
              59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
              1016 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
              1021 TSF:MSG:FPAR OK,ID=0,D=1
              1804 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
              1851 TSF:MSG:READ,4-4-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
              2067 TSM:FPAR:OK
              2068 TSM:ID
              2069 TSM:ID:OK
              2071 TSM:UPL
              2075 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
              2087 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
              2093 TSF:MSG:PONG RECV,HP=1
              2095 TSM:UPL:OK
              2097 TSM:READY:ID=12,PAR=0,DIS=1
              2102 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
              2111 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
              2119 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
              2128 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
              2144 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
              2152 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
              2163 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
              2169 MCO:REG:REQ
              2173 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
              2183 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
              2188 MCO:PIM:NODE REG=1
              2190 MCO:BGN:STP
              2192 MCO:BGN:INIT OK,TSP=1

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

              @Dick thanks. The node still doesn't send any values so that's why it does not show up in Domoticz.

              My next step would be to manually add serial debug prints at end of setup(), presentation(), and almost everywhere in loop(), to see why it doesn't attempt to send.

              DickD 1 Reply Last reply
              0
              • rejoe2R Offline
                rejoe2R Offline
                rejoe2
                wrote on last edited by
                #107

                Very strange.
                I just mad the test and copied the code (out of your post above) to my IDE, compiled and uploaded: No problem, worked fine. Node gets registered by FHEM, sends ID once and Temp regularly as expected. For testing, I used just one DS18B20, but that shouldn't make any difference. (And MySensors lib version 2.2-beta, but that also shouldn't be an issue).

                Btw: what kind of a GW you are using?
                Recently, I came across a situation with a WiFi-GW that absolutely refused to accept new nodes. Using a serial one, everything was fine... Strange thing, too. (The GW itself was ok, there were several other nodes working without any communication problems. the new HW was also ok. Last, the channel was also correct, as all the existing nodes just switched over to the serial GW.... Reflashing that nasty thing also was no solution.)

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

                1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  @Dick thanks. The node still doesn't send any values so that's why it does not show up in Domoticz.

                  My next step would be to manually add serial debug prints at end of setup(), presentation(), and almost everywhere in loop(), to see why it doesn't attempt to send.

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

                  I put some deug lines i it and after uploadig the sketch it stops here (wait conversationtime.)
                  setup done.
                  2191 MCO:BGN:INIT OK,TSP=1
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.
                  fetch sensors.
                  wait conversationtime.

                  mfalkviddM 1 Reply Last reply
                  0
                  • DickD Dick

                    I put some deug lines i it and after uploadig the sketch it stops here (wait conversationtime.)
                    setup done.
                    2191 MCO:BGN:INIT OK,TSP=1
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.
                    fetch sensors.
                    wait conversationtime.

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

                    @Dick could you try printing the value of numSensors in presentation()? (or in loop, it should have the same value there)

                    DickD 1 Reply Last reply
                    0
                    • mfalkviddM mfalkvidd

                      @Dick could you try printing the value of numSensors in presentation()? (or in loop, it should have the same value there)

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

                      @mfalkvidd how can I manage that? sorr for the perhaps stupid qestion?

                      mfalkviddM 1 Reply Last reply
                      0
                      • DickD Dick

                        @mfalkvidd how can I manage that? sorr for the perhaps stupid qestion?

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

                        @Dick

                        Serial.print("Number of attached sensors found by the DallasTemperature library: ");
                        Serial.println(numSensors);
                        
                        rejoe2R DickD 2 Replies Last reply
                        0
                        • mfalkviddM mfalkvidd

                          @Dick

                          Serial.print("Number of attached sensors found by the DallasTemperature library: ");
                          Serial.println(numSensors);
                          
                          rejoe2R Offline
                          rejoe2R Offline
                          rejoe2
                          wrote on last edited by
                          #112

                          @Dick best place would be after numSensors = ... in presentation()

                          Just to mention that: The Arduino I used already had a node ID (I usually assign it manually). But your problem seems to be something completely different.

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

                          1 Reply Last reply
                          0
                          • mfalkviddM mfalkvidd

                            @Dick

                            Serial.print("Number of attached sensors found by the DallasTemperature library: ");
                            Serial.println(numSensors);
                            
                            DickD Offline
                            DickD Offline
                            Dick
                            wrote on last edited by
                            #113

                            @mfalkvidd I tried it in Presentation() and in Loop() inboth no results in the log (copied it as you advised me how to do. so no result bisible). it is getting complex I think!
                            6 TSM:INIT
                            7 TSF:WUR:MS=0
                            14 TSM:INIT:TSP OK
                            16 TSF:SID:OK,ID=12
                            17 TSM:FPAR
                            59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
                            452 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
                            457 TSF:MSG:FPAR OK,ID=0,D=1
                            561 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
                            2066 TSM:FPAR:OK
                            2067 TSM:ID
                            2068 TSM:ID:OK
                            2070 TSM:UPL
                            2074 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
                            2086 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
                            2092 TSF:MSG:PONG RECV,HP=1
                            2094 TSM:UPL:OK
                            2096 TSM:READY:ID=12,PAR=0,DIS=1
                            2101 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
                            2110 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                            2118 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
                            2127 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
                            2142 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
                            2151 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
                            2161 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
                            2168 MCO:REG:REQ
                            2172 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
                            2181 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
                            2186 MCO:PIM:NODE REG=1
                            2189 MCO:BGN:STP
                            setup done.
                            2190 MCO:BGN:INIT OK,TSP=1
                            fetch sensors.
                            wait conversationtime.
                            fetch sensors.
                            wait conversationtime.
                            fetch sensors.
                            wait conversationtime.

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

                              How are your sensors wired? Parasitic or 3 wires?
                              Sounds like a broken sensor, wrong wiring or a lot of sensors (to much for the pullup used).

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

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

                                Ok. I give up. If the node isn't executing the serial prints I know no way of troubleshooting.

                                DickD 1 Reply Last reply
                                0
                                • mfalkviddM mfalkvidd

                                  Ok. I give up. If the node isn't executing the serial prints I know no way of troubleshooting.

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

                                  @mfalkvidd I ony can tell "thanksfo the support ad you time" . Have a nice wekend!!!

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

                                    I have been frustrated with this for weeks now. Today I notice that void loop is not closed with a curly brace and if I add one it does not compile.
                                    So what black magic is going on here?

                                    I have been trying to get sensor readings every 2 mins and battery every half hour. But whatever I try it still gives temp every minute and battery at once a minute too. No wonder my batteries are draining so fast.

                                    mfalkviddM 1 Reply Last reply
                                    0
                                    • skywatchS skywatch

                                      I have been frustrated with this for weeks now. Today I notice that void loop is not closed with a curly brace and if I add one it does not compile.
                                      So what black magic is going on here?

                                      I have been trying to get sensor readings every 2 mins and battery every half hour. But whatever I try it still gives temp every minute and battery at once a minute too. No wonder my batteries are draining so fast.

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

                                      @skywatch the curly braces were discussed and explained earlier in this thread.

                                      Could you post your sketch and the debug output of your node?

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

                                        @mfalkvidd

                                        Thanks for fast reply! See code below. If you don't see problem there I will debug tomorrow. The battery time is set for 90sec to test, but is taking 18mins between sends!

                                        
                                        
                                        // Enable debug prints to serial monitor
                                        //#define MY_DEBUG
                                        
                                        // Enable and select radio type attached
                                        #define MY_RADIO_NRF24
                                        //#define MY_RADIO_RFM69
                                        #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
                                        #define MY_RF24_PA_LEVEL (RF24_PA_LOW)
                                        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                        #define MAX_ATTACHED_DS18B20 3
                                        #include <SPI.h>
                                        #include <MySensors.h>
                                        #include <DallasTemperature.h>
                                        #include <OneWire.h>
                                        int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                        int batteryPcnt = 0;
                                        unsigned long SLEEP_TIME = 117000; // 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;
                                        const long interval = 90000;
                                        unsigned long previousMillis = 0;
                                        bool receivedConfig = false;
                                        bool metric = true;
                                        // Initialize temperature message
                                        MyMessage msg(0, V_TEMP);
                                        
                                        void before()
                                        {
                                          // Startup up the OneWire library
                                          sensors.begin();
                                        }
                                        
                                        void setup()
                                        {
                                          // requestTemperatures() will not block current thread
                                          sensors.setWaitForConversion(false);
                                          analogReference(INTERNAL);
                                        }
                                        
                                        void presentation() {
                                          // Send the sketch version information to the gateway and Controller
                                          sendSketchInfo("HW/CH", "0.4");
                                        
                                          // 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++) {
                                            present(i, S_TEMP);
                                          }
                                        }
                                        
                                        void loop()
                                        {
                                          // get the battery Voltage
                                          unsigned long currentMillis = millis();
                                        
                                          if (currentMillis - previousMillis >= interval) {
                                            previousMillis = currentMillis;
                                            int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                            batteryPcnt = sensorValue / 10;
                                            sendBatteryLevel(batteryPcnt);
                                          }
                                        
                                          // Fetch temperatures from Dallas sensors
                                          sensors.requestTemperatures();
                                        
                                          // query conversion time and sleep until conversion completed
                                          int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                          // 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>((getControllerConfig().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
                                              send(msg.setSensor(i).set(temperature, 1));
                                              // Save new temperatures for next compare
                                              lastTemperature[i] = temperature;
                                            }
                                          }
                                        
                                          int8_t sleep(1, FALLING, SLEEP_TIME);
                                        }```
                                        mfalkviddM 1 Reply Last reply
                                        0
                                        • skywatchS skywatch

                                          @mfalkvidd

                                          Thanks for fast reply! See code below. If you don't see problem there I will debug tomorrow. The battery time is set for 90sec to test, but is taking 18mins between sends!

                                          
                                          
                                          // Enable debug prints to serial monitor
                                          //#define MY_DEBUG
                                          
                                          // Enable and select radio type attached
                                          #define MY_RADIO_NRF24
                                          //#define MY_RADIO_RFM69
                                          #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
                                          #define MY_RF24_PA_LEVEL (RF24_PA_LOW)
                                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                          #define MAX_ATTACHED_DS18B20 3
                                          #include <SPI.h>
                                          #include <MySensors.h>
                                          #include <DallasTemperature.h>
                                          #include <OneWire.h>
                                          int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                          int batteryPcnt = 0;
                                          unsigned long SLEEP_TIME = 117000; // 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;
                                          const long interval = 90000;
                                          unsigned long previousMillis = 0;
                                          bool receivedConfig = false;
                                          bool metric = true;
                                          // Initialize temperature message
                                          MyMessage msg(0, V_TEMP);
                                          
                                          void before()
                                          {
                                            // Startup up the OneWire library
                                            sensors.begin();
                                          }
                                          
                                          void setup()
                                          {
                                            // requestTemperatures() will not block current thread
                                            sensors.setWaitForConversion(false);
                                            analogReference(INTERNAL);
                                          }
                                          
                                          void presentation() {
                                            // Send the sketch version information to the gateway and Controller
                                            sendSketchInfo("HW/CH", "0.4");
                                          
                                            // 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++) {
                                              present(i, S_TEMP);
                                            }
                                          }
                                          
                                          void loop()
                                          {
                                            // get the battery Voltage
                                            unsigned long currentMillis = millis();
                                          
                                            if (currentMillis - previousMillis >= interval) {
                                              previousMillis = currentMillis;
                                              int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                              batteryPcnt = sensorValue / 10;
                                              sendBatteryLevel(batteryPcnt);
                                            }
                                          
                                            // Fetch temperatures from Dallas sensors
                                            sensors.requestTemperatures();
                                          
                                            // query conversion time and sleep until conversion completed
                                            int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                            // 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>((getControllerConfig().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
                                                send(msg.setSensor(i).set(temperature, 1));
                                                // Save new temperatures for next compare
                                                lastTemperature[i] = temperature;
                                              }
                                            }
                                          
                                            int8_t sleep(1, FALLING, SLEEP_TIME);
                                          }```
                                          mfalkviddM Offline
                                          mfalkviddM Offline
                                          mfalkvidd
                                          Mod
                                          wrote on last edited by mfalkvidd
                                          #120

                                          @skywatch doing what you want is a bit hard since millis won't update while the node is in power save mode (sleeping). But this should do it:
                                          set SLEEP_TIME = 2 * 60 * 1000 // 2 minutes
                                          and change

                                          void loop()
                                          {
                                            // get the battery Voltage
                                            unsigned long currentMillis = millis();
                                          
                                            if (currentMillis - previousMillis >= interval) {
                                              previousMillis = currentMillis;
                                              int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                              batteryPcnt = sensorValue / 10;
                                              sendBatteryLevel(batteryPcnt);
                                            }
                                          ...
                                          

                                          to

                                          unsigned int batteryReportFactor = 30*60*1000ul/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values)
                                          unsigned int timesSlept = 0;
                                          void loop()
                                          {
                                            if (timesSlept < batteryReportFactor) {
                                              timesSlept++;
                                            } else {
                                              // get the battery Voltage
                                              timesSlept = 0;
                                              int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                              batteryPcnt = sensorValue / 10;
                                              sendBatteryLevel(batteryPcnt);
                                            }
                                          ...
                                          

                                          I don't understand why you're using interrupt to sleep though.

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


                                          14

                                          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
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular