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. My Project
  3. My Slim 2AA Battery Node

My Slim 2AA Battery Node

Scheduled Pinned Locked Moved My Project
498 Posts 71 Posters 342.6k Views 69 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
    #389

    If you reset either node or gateway, does it go back to work or what?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eawo
      wrote on last edited by
      #390

      No it doesn't only sometimes

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

        If it was the gateway you should stop receiving data from other sensors too, right?

        1 Reply Last reply
        0
        • AWIA AWI

          @rollercontainer Your sleep looks good. Did you remove this piece of code?

          // Activate internal pull-ups
          	digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
          	digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
          

          Take a look at this thread for a < 1 uA consumption...

          rollercontainerR Offline
          rollercontainerR Offline
          rollercontainer
          wrote on last edited by
          #392

          @AWI said in My Slim 2AA Battery Node:

          @rollercontainer Your sleep looks good. Did you remove this piece of code?

          // Activate internal pull-ups
          	digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
          	digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
          

          Take a look at this thread for a < 1 uA consumption...

          Hmm, I noticed, that I have to disable the internal pullups. But instead of removing the lines, I set them to LOW. I will test it without the lines and come back. Thank you @AWI.

          1 Reply Last reply
          0
          • siodS Offline
            siodS Offline
            siod
            wrote on last edited by siod
            #393

            Ok, just want to give you an update:

            I have 3 sensors running in the moment, initially I planned to run a lot more, but I still have problems with freezing of the sensors. The Sensors ran 2 months now until they were not coummunicating anymore, 1 is still working. I restarted 1 of the freezed sensors and it just came back up and works fine again, I leave the other one "freezed" just to see if it would come up again...

            It´s sad that they are not very reliable but I don´t get what makes them freeze after working quiet good for such a long time (they are reporting every 15 minutes 24/7 and whenever a window is opened/closed).

            I don´t think it´s a temp thing, also power should be no problem, batteries are still about 80 % loaded...

            still learning...

            1 Reply Last reply
            0
            • rollercontainerR Offline
              rollercontainerR Offline
              rollercontainer
              wrote on last edited by
              #394

              Maybe there is something like a counter (variable++) which causes a overflow after two month?

              1 Reply Last reply
              0
              • siodS Offline
                siodS Offline
                siod
                wrote on last edited by
                #395

                No, not really, but if you want to you can check my code:

                // Sensor Node Schlafzimmer mit HTU21D Temp/Hum Sensor, Fensterkontakte an Interrupt PINS Digital 5&6. Sleep Time 15 Minutwn, wake up wenn Fenster geöffnet/geschlossen wird.
                #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen
                // Define Node ID
                #define MY_NODE_ID 1
                #define MY_PARENT_NODE_ID 0
                #define MY_PARENT_NODE_IS_STATIC
                
                //Batterysensor
                int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                int oldBatteryPcnt = 0;
                #define CHILD_ID_BATT 7
                
                //Kontaktschalter
                //#include <Bounce2.h>
                #define CHILD1_ID 1 // Kontaktschalter 1
                #define CHILD2_ID 2 // Kontaktschalter 2
                #define BUTTON1_PIN  2  // Kontaktschalter 1
                #define BUTTON2_PIN  3  // Kontaktschalter 2
                int oldValueReed1=-1;
                int oldValueReed2=-1;
                
                //Tempsensor
                #include <SparkFunHTU21D.h>
                #include <Wire.h>
                #define CHILD_ID_HUM 3
                #define CHILD_ID_TEMP 4
                unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
                
                #include <MySensors.h>
                #include <SPI.h>
                
                //tempsensor
                HTU21D myHumidity;
                float lastTemp;
                float lastHum;
                //boolean metric = true; 
                
                //Messages
                //Battery
                MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE);
                // Kontaktschalter
                MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
                MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
                //TempMessage
                MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                
                //Presentation; present sensors to gateway!
                void presentation(){
                  // Send the sketch version information to the gateway and Controller
                  sendSketchInfo("Schlafzimmer Messstation", "2.0");
                    
                  // Register binary input sensor to gw (they will be created as child devices)
                  // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                  // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                  present(CHILD1_ID, S_DOOR); 
                  present(CHILD2_ID, S_DOOR); 
                    
                  //Tempsensor
                  present(CHILD_ID_HUM, S_HUM);
                  present(CHILD_ID_TEMP, S_TEMP); 
                  //metric = getConfig().isMetric;
                
                  //Battery
                  present(CHILD_ID_BATT,V_VOLTAGE);
                }
                
                //Setup
                void setup()  
                {  
                  //Serial.begin(9600);
                  Serial.println("Hello!");
                  //Batterysensor
                     // use the 1.1 V internal reference
                #if defined(__AVR_ATmega2560__)
                   analogReference(INTERNAL1V1);
                #else
                   analogReference(INTERNAL);
                #endif
                
                //Tempsensor
                  Serial.println("Setting up TempSensor...");
                  myHumidity.begin();
                  Serial.println("...done!");
                
                // Setup Kontaktschalter 1
                  pinMode(BUTTON1_PIN,INPUT);
                    // Activate internal pull-up
                  digitalWrite(BUTTON1_PIN,HIGH);
                // Setup Kontaktschalter 2
                  pinMode(BUTTON2_PIN,INPUT);
                  // Activate internal pull-up
                  digitalWrite(BUTTON2_PIN,HIGH);
                }
                
                //Starte den Loop
                void loop() 
                {
                  //Batterysensor
                  // get the battery Voltage
                  delay(1000);
                   int sensorValue = analogRead(BATTERY_SENSE_PIN);
                   #ifdef DEBUG
                   #endif
                   
                   // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                   // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                   // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                   // 3.44/1023 = Volts per bit = 0.003363075
                   float batteryV  = sensorValue * 0.003363075;
                   int batteryPcnt = sensorValue / 10;
                
                   #ifdef DEBUG
                   Serial.print("Battery Voltage: ");
                   Serial.print(batteryV);
                   Serial.println(" V");
                
                   Serial.print("Battery percent: ");
                   Serial.print(batteryPcnt);
                   Serial.println(" %");
                   #endif
                
                   if (oldBatteryPcnt != batteryPcnt) {
                     // Power up radio after sleep
                     sendBatteryLevel(batteryPcnt);
                     send(msgbatt.set(batteryPcnt));
                     oldBatteryPcnt = batteryPcnt;
                   }
                   
                  //Kontakstschalter 1
                   // Short delay to allow buttons to properly settle
                  wait(10);
                  // Get the update value
                  int valueReed1 = digitalRead(BUTTON1_PIN);
                 
                  if (valueReed1 != oldValueReed1) {
                     // Send in the new value
                     send(msgReed1.set(valueReed1==HIGH ? 1 : 0));
                     Serial.println("Button 1 geschaltet");
                     oldValueReed1 = valueReed1;
                  }
                  //Kontakstschalter 2
                  // Get the update value
                  int valueReed2 = digitalRead(BUTTON2_PIN);
                 
                  if (valueReed2 != oldValueReed2) {
                     // Send in the new value
                     send(msgReed2.set(valueReed2==HIGH ? 1 : 0));
                     Serial.println("Button 2 geschaltet");
                     oldValueReed2 = valueReed2;
                  }
                 
                 //Tempsensor
                Serial.println("Starte Messung...");
                  
                    float temp = myHumidity.readTemperature();
                
                  if (isnan(temp)) {
                      Serial.println("Failed reading temperature from DHT");
                  } else if (temp != lastTemp) {
                    lastTemp = temp;
                    send(msgTemp.set(temp, 1));
                    Serial.print("T: ");
                    Serial.println(temp);
                  }
                  
                 float humd = myHumidity.readHumidity();
                  if (isnan(humd)) {
                      Serial.println("Failed reading humidity from DHT");
                  } else if (humd != lastHum) {
                      lastHum = humd;
                      send(msgHum.set(humd, 1));
                      Serial.print("H: ");
                      Serial.println(humd);
                  }
                
                 Serial.println("Sleep...");
                 sleep(BUTTON1_PIN - 2, CHANGE, BUTTON2_PIN - 2, CHANGE, SLEEP_TIME); //sleep a bit 
                  
                } 
                
                

                still learning...

                m26872M 1 Reply Last reply
                0
                • AWIA AWI

                  @rollercontainer Your sleep looks good. Did you remove this piece of code?

                  // Activate internal pull-ups
                  	digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
                  	digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
                  

                  Take a look at this thread for a < 1 uA consumption...

                  Tim AbelsT Offline
                  Tim AbelsT Offline
                  Tim Abels
                  wrote on last edited by
                  #396

                  @AWI: I am down to 1,3 µA :+1:

                  my code:

                  //#define MY_DEBUG
                  #define MY_RADIO_NRF24
                  #define MY_NODE_ID 66
                  #define MY_PARENT_NODE_ID 0
                  #define MY_PARENT_NODE_IS_STATIC
                  
                  #include <MySensors.h>
                  #include "Vcc.h"
                  
                  #define SKETCH_NAME "MySlim2aaBatteryNode"
                  
                  #define PRIMARY_CHILD_ID 3
                  #define PRIMARY_BUTTON_PIN 3
                  
                  MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                  
                  const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
                  const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
                  const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
                  
                  const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
                  
                  Vcc vcc(VccCorrection);
                  
                  #ifdef MY_DEBUG
                  void before(){
                      Serial.begin(9600);
                  }
                  #endif
                  
                  void setup()
                  {
                      pinMode(PRIMARY_BUTTON_PIN, INPUT);
                  }
                  
                  void presentation()
                  {
                      sendSketchInfo(SKETCH_NAME, __DATE__);
                      present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
                  }
                  
                  void loop()
                  {
                      int32_t timestamp = millis();
                  
                      uint8_t reedState;
                      static uint8_t lastReedState = 2;
                      static int32_t lastBatteryReport = -report_interval; // for inital report
                      sleep(5); // Short delay to allow buttons to properly settle
                  
                      reedState = digitalRead(PRIMARY_BUTTON_PIN);
                  
                      if ( (timestamp-lastBatteryReport) >= report_interval ) {
                        uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
                        sendBatteryLevel(batteryPercent);
                        lastBatteryReport = timestamp;
                      }
                  
                      if (reedState != lastReedState) {
                          // Value has changed from last transmission, send the updated reedState
                          send(msg.set(reedState==HIGH));
                          lastReedState = reedState;
                      }
                  
                      sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
                  }
                  
                  
                  AWIA m26872M 2 Replies Last reply
                  0
                  • siodS siod

                    No, not really, but if you want to you can check my code:

                    // Sensor Node Schlafzimmer mit HTU21D Temp/Hum Sensor, Fensterkontakte an Interrupt PINS Digital 5&6. Sleep Time 15 Minutwn, wake up wenn Fenster geöffnet/geschlossen wird.
                    #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen
                    // Define Node ID
                    #define MY_NODE_ID 1
                    #define MY_PARENT_NODE_ID 0
                    #define MY_PARENT_NODE_IS_STATIC
                    
                    //Batterysensor
                    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                    int oldBatteryPcnt = 0;
                    #define CHILD_ID_BATT 7
                    
                    //Kontaktschalter
                    //#include <Bounce2.h>
                    #define CHILD1_ID 1 // Kontaktschalter 1
                    #define CHILD2_ID 2 // Kontaktschalter 2
                    #define BUTTON1_PIN  2  // Kontaktschalter 1
                    #define BUTTON2_PIN  3  // Kontaktschalter 2
                    int oldValueReed1=-1;
                    int oldValueReed2=-1;
                    
                    //Tempsensor
                    #include <SparkFunHTU21D.h>
                    #include <Wire.h>
                    #define CHILD_ID_HUM 3
                    #define CHILD_ID_TEMP 4
                    unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
                    
                    #include <MySensors.h>
                    #include <SPI.h>
                    
                    //tempsensor
                    HTU21D myHumidity;
                    float lastTemp;
                    float lastHum;
                    //boolean metric = true; 
                    
                    //Messages
                    //Battery
                    MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE);
                    // Kontaktschalter
                    MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
                    MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
                    //TempMessage
                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                    
                    //Presentation; present sensors to gateway!
                    void presentation(){
                      // Send the sketch version information to the gateway and Controller
                      sendSketchInfo("Schlafzimmer Messstation", "2.0");
                        
                      // Register binary input sensor to gw (they will be created as child devices)
                      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                      present(CHILD1_ID, S_DOOR); 
                      present(CHILD2_ID, S_DOOR); 
                        
                      //Tempsensor
                      present(CHILD_ID_HUM, S_HUM);
                      present(CHILD_ID_TEMP, S_TEMP); 
                      //metric = getConfig().isMetric;
                    
                      //Battery
                      present(CHILD_ID_BATT,V_VOLTAGE);
                    }
                    
                    //Setup
                    void setup()  
                    {  
                      //Serial.begin(9600);
                      Serial.println("Hello!");
                      //Batterysensor
                         // use the 1.1 V internal reference
                    #if defined(__AVR_ATmega2560__)
                       analogReference(INTERNAL1V1);
                    #else
                       analogReference(INTERNAL);
                    #endif
                    
                    //Tempsensor
                      Serial.println("Setting up TempSensor...");
                      myHumidity.begin();
                      Serial.println("...done!");
                    
                    // Setup Kontaktschalter 1
                      pinMode(BUTTON1_PIN,INPUT);
                        // Activate internal pull-up
                      digitalWrite(BUTTON1_PIN,HIGH);
                    // Setup Kontaktschalter 2
                      pinMode(BUTTON2_PIN,INPUT);
                      // Activate internal pull-up
                      digitalWrite(BUTTON2_PIN,HIGH);
                    }
                    
                    //Starte den Loop
                    void loop() 
                    {
                      //Batterysensor
                      // get the battery Voltage
                      delay(1000);
                       int sensorValue = analogRead(BATTERY_SENSE_PIN);
                       #ifdef DEBUG
                       #endif
                       
                       // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                       // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                       // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                       // 3.44/1023 = Volts per bit = 0.003363075
                       float batteryV  = sensorValue * 0.003363075;
                       int batteryPcnt = sensorValue / 10;
                    
                       #ifdef DEBUG
                       Serial.print("Battery Voltage: ");
                       Serial.print(batteryV);
                       Serial.println(" V");
                    
                       Serial.print("Battery percent: ");
                       Serial.print(batteryPcnt);
                       Serial.println(" %");
                       #endif
                    
                       if (oldBatteryPcnt != batteryPcnt) {
                         // Power up radio after sleep
                         sendBatteryLevel(batteryPcnt);
                         send(msgbatt.set(batteryPcnt));
                         oldBatteryPcnt = batteryPcnt;
                       }
                       
                      //Kontakstschalter 1
                       // Short delay to allow buttons to properly settle
                      wait(10);
                      // Get the update value
                      int valueReed1 = digitalRead(BUTTON1_PIN);
                     
                      if (valueReed1 != oldValueReed1) {
                         // Send in the new value
                         send(msgReed1.set(valueReed1==HIGH ? 1 : 0));
                         Serial.println("Button 1 geschaltet");
                         oldValueReed1 = valueReed1;
                      }
                      //Kontakstschalter 2
                      // Get the update value
                      int valueReed2 = digitalRead(BUTTON2_PIN);
                     
                      if (valueReed2 != oldValueReed2) {
                         // Send in the new value
                         send(msgReed2.set(valueReed2==HIGH ? 1 : 0));
                         Serial.println("Button 2 geschaltet");
                         oldValueReed2 = valueReed2;
                      }
                     
                     //Tempsensor
                    Serial.println("Starte Messung...");
                      
                        float temp = myHumidity.readTemperature();
                    
                      if (isnan(temp)) {
                          Serial.println("Failed reading temperature from DHT");
                      } else if (temp != lastTemp) {
                        lastTemp = temp;
                        send(msgTemp.set(temp, 1));
                        Serial.print("T: ");
                        Serial.println(temp);
                      }
                      
                     float humd = myHumidity.readHumidity();
                      if (isnan(humd)) {
                          Serial.println("Failed reading humidity from DHT");
                      } else if (humd != lastHum) {
                          lastHum = humd;
                          send(msgHum.set(humd, 1));
                          Serial.print("H: ");
                          Serial.println(humd);
                      }
                    
                     Serial.println("Sleep...");
                     sleep(BUTTON1_PIN - 2, CHANGE, BUTTON2_PIN - 2, CHANGE, SLEEP_TIME); //sleep a bit 
                      
                    } 
                    
                    
                    m26872M Offline
                    m26872M Offline
                    m26872
                    Hardware Contributor
                    wrote on last edited by
                    #397

                    @siod
                    Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                    What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                    siodS 1 Reply Last reply
                    0
                    • Tim AbelsT Tim Abels

                      @AWI: I am down to 1,3 µA :+1:

                      my code:

                      //#define MY_DEBUG
                      #define MY_RADIO_NRF24
                      #define MY_NODE_ID 66
                      #define MY_PARENT_NODE_ID 0
                      #define MY_PARENT_NODE_IS_STATIC
                      
                      #include <MySensors.h>
                      #include "Vcc.h"
                      
                      #define SKETCH_NAME "MySlim2aaBatteryNode"
                      
                      #define PRIMARY_CHILD_ID 3
                      #define PRIMARY_BUTTON_PIN 3
                      
                      MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                      
                      const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
                      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
                      const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
                      
                      const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
                      
                      Vcc vcc(VccCorrection);
                      
                      #ifdef MY_DEBUG
                      void before(){
                          Serial.begin(9600);
                      }
                      #endif
                      
                      void setup()
                      {
                          pinMode(PRIMARY_BUTTON_PIN, INPUT);
                      }
                      
                      void presentation()
                      {
                          sendSketchInfo(SKETCH_NAME, __DATE__);
                          present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
                      }
                      
                      void loop()
                      {
                          int32_t timestamp = millis();
                      
                          uint8_t reedState;
                          static uint8_t lastReedState = 2;
                          static int32_t lastBatteryReport = -report_interval; // for inital report
                          sleep(5); // Short delay to allow buttons to properly settle
                      
                          reedState = digitalRead(PRIMARY_BUTTON_PIN);
                      
                          if ( (timestamp-lastBatteryReport) >= report_interval ) {
                            uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
                            sendBatteryLevel(batteryPercent);
                            lastBatteryReport = timestamp;
                          }
                      
                          if (reedState != lastReedState) {
                              // Value has changed from last transmission, send the updated reedState
                              send(msg.set(reedState==HIGH));
                              lastReedState = reedState;
                          }
                      
                          sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
                      }
                      
                      
                      AWIA Offline
                      AWIA Offline
                      AWI
                      Hero Member
                      wrote on last edited by AWI
                      #398

                      @Tim-Abels :+1: that is how you do it

                      Be aware that the timer (millis()) is not running during sleep.

                      rollercontainerR 1 Reply Last reply
                      1
                      • Tim AbelsT Tim Abels

                        @AWI: I am down to 1,3 µA :+1:

                        my code:

                        //#define MY_DEBUG
                        #define MY_RADIO_NRF24
                        #define MY_NODE_ID 66
                        #define MY_PARENT_NODE_ID 0
                        #define MY_PARENT_NODE_IS_STATIC
                        
                        #include <MySensors.h>
                        #include "Vcc.h"
                        
                        #define SKETCH_NAME "MySlim2aaBatteryNode"
                        
                        #define PRIMARY_CHILD_ID 3
                        #define PRIMARY_BUTTON_PIN 3
                        
                        MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
                        
                        const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
                        const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
                        const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
                        
                        const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
                        
                        Vcc vcc(VccCorrection);
                        
                        #ifdef MY_DEBUG
                        void before(){
                            Serial.begin(9600);
                        }
                        #endif
                        
                        void setup()
                        {
                            pinMode(PRIMARY_BUTTON_PIN, INPUT);
                        }
                        
                        void presentation()
                        {
                            sendSketchInfo(SKETCH_NAME, __DATE__);
                            present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
                        }
                        
                        void loop()
                        {
                            int32_t timestamp = millis();
                        
                            uint8_t reedState;
                            static uint8_t lastReedState = 2;
                            static int32_t lastBatteryReport = -report_interval; // for inital report
                            sleep(5); // Short delay to allow buttons to properly settle
                        
                            reedState = digitalRead(PRIMARY_BUTTON_PIN);
                        
                            if ( (timestamp-lastBatteryReport) >= report_interval ) {
                              uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
                              sendBatteryLevel(batteryPercent);
                              lastBatteryReport = timestamp;
                            }
                        
                            if (reedState != lastReedState) {
                                // Value has changed from last transmission, send the updated reedState
                                send(msg.set(reedState==HIGH));
                                lastReedState = reedState;
                            }
                        
                            sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
                        }
                        
                        
                        m26872M Offline
                        m26872M Offline
                        m26872
                        Hardware Contributor
                        wrote on last edited by m26872
                        #399

                        @Tim-Abels
                        1.3uA is nice!
                        A question about your sketch: Is millis() working because it's an interrupt-only sleep() or have I missed something else? As I recall it millis() stops working when using sleep().
                        Edit: Haha. @AWI got it before me! :smile:

                        1 Reply Last reply
                        1
                        • AWIA AWI

                          @Tim-Abels :+1: that is how you do it

                          Be aware that the timer (millis()) is not running during sleep.

                          rollercontainerR Offline
                          rollercontainerR Offline
                          rollercontainer
                          wrote on last edited by
                          #400

                          @AWI one step forward, two steps back... Thanks for the hint.

                          I guess, I should send battery percentage every 10 interrupts or so. Even if the contact doesn't trigger for a while, I can force it by showing my neighbours my ocd on doors ^^ (knock, knock, knock - Penny!)

                          What do you think?

                          AWIA 1 Reply Last reply
                          1
                          • rollercontainerR Offline
                            rollercontainerR Offline
                            rollercontainer
                            wrote on last edited by
                            #401

                            Just noticed, that I use another login at home. So, the Tim-Abels is the rollercontainer... Sorry for that.

                            1 Reply Last reply
                            0
                            • rollercontainerR rollercontainer

                              @AWI one step forward, two steps back... Thanks for the hint.

                              I guess, I should send battery percentage every 10 interrupts or so. Even if the contact doesn't trigger for a while, I can force it by showing my neighbours my ocd on doors ^^ (knock, knock, knock - Penny!)

                              What do you think?

                              AWIA Offline
                              AWIA Offline
                              AWI
                              Hero Member
                              wrote on last edited by
                              #402

                              @rollercontainer alias @Tim-Abels ;-) Sounds good, although with 1.3uA the battery won't show much variation..

                              This is a similar on running on a coin cell (not calibrated). The voltage drop is caused mainly by the bad radio connection (many retries for sending > 10 mA)

                              0_1487319381911_upload-02a06ce9-126d-49f2-bbcb-dd01c3cea3d4

                              1 Reply Last reply
                              0
                              • rollercontainerR Offline
                                rollercontainerR Offline
                                rollercontainer
                                wrote on last edited by rollercontainer
                                #403

                                Maybe its better to measure the voltage every 10 or 100 loops and only send one custom message/alert when its dropped below a threshold. I am using the MQTTClientGateway and Node-Red. In case of a battery-low message, node-red could send me an email with the node name. I will give it a try...

                                From https://www.mysensors.org/download/serial_api_20:

                                V_TEXT          47 	Text message to display on LCD or controller device 	S_INFO
                                V_CUSTOM 	48 	Custom messages used for controller/inter node specific commands, preferably using S_CUSTOM device type. 	S_CUSTOM```
                                1 Reply Last reply
                                0
                                • rollercontainerR Offline
                                  rollercontainerR Offline
                                  rollercontainer
                                  wrote on last edited by
                                  #404

                                  Did you considered a tiny solar cell like enocean does?
                                  https://www.enocean.com/en/enocean_modules/stm-320/
                                  That would be perfect...

                                  1 Reply Last reply
                                  1
                                  • rollercontainerR Offline
                                    rollercontainerR Offline
                                    rollercontainer
                                    wrote on last edited by
                                    #405

                                    searched a bit and found that @ceech already made a harvester with a coin cell.

                                    http://www.ebay.de/itm/BQ25570-thermal-solar-energy-harvester-/332071662285

                                    still too big and too expensive in comparison with dozens of alkaline batteries which will run for years, but that is the way to go sometime.

                                    1 Reply Last reply
                                    0
                                    • m26872M m26872

                                      @siod
                                      Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                                      What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                                      siodS Offline
                                      siodS Offline
                                      siod
                                      wrote on last edited by
                                      #406

                                      @m26872 said in My Slim 2AA Battery Node:

                                      @siod
                                      Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                                      What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                                      @m26872
                                      Gateway seems to work fine as the 3rd and still working sensor is still communicating. Also the freezed sensors start communicating after I restarted the sensor, not the GW. So I don´t see a problem with the GW.
                                      "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?
                                      I have not attached a heartbeat LED yet, but that´s sth. I could do as a next step...
                                      The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...
                                      You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                                      Thanks so far!!

                                      still learning...

                                      m26872M 1 Reply Last reply
                                      0
                                      • siodS siod

                                        @m26872 said in My Slim 2AA Battery Node:

                                        @siod
                                        Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                                        What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                                        @m26872
                                        Gateway seems to work fine as the 3rd and still working sensor is still communicating. Also the freezed sensors start communicating after I restarted the sensor, not the GW. So I don´t see a problem with the GW.
                                        "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?
                                        I have not attached a heartbeat LED yet, but that´s sth. I could do as a next step...
                                        The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...
                                        You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                                        Thanks so far!!

                                        m26872M Offline
                                        m26872M Offline
                                        m26872
                                        Hardware Contributor
                                        wrote on last edited by m26872
                                        #407

                                        @siod said in My Slim 2AA Battery Node:

                                        "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?

                                        I meant the https://www.mysensors.org/controller/sniffer, but I think it's easier to equip sensors with Radio Traffic LEDs and/or your own heartbeat/error LEDs.

                                        The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...

                                        I suggest you start with deleting or replacing this delay. It could be it.

                                        You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                                        I think you had pull-up inputs. Then it's just to replace the CHANGE with LOW in your call to sleep().

                                        Thanks so far!!

                                        My personal troubleshooting method in cases like these (and too many others) is just exhaustive use of the good old substitution method. Hw, Sw, entire systems or whatever you can do. :grimacing:

                                        1 Reply Last reply
                                        0
                                        • siodS Offline
                                          siodS Offline
                                          siod
                                          wrote on last edited by siod
                                          #408

                                          deleted - it´s working now, I must have made a mistake... :blush:

                                          edit:

                                          one strange thing: The sensor should report every 15 minutes (900000 milisecs), but it reports only every 18 minutes. Don´t know why.

                                          still learning...

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


                                          20

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular