<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt?]]></title><description><![CDATA[<p dir="auto">HI,</p>
<p dir="auto">I have a sleeping battery node, soil moisture sensor, to which I am adding a Rain tipping bucket sensor.<br />
The node sleeps for an hour, before waking, measuring soil, and reporting.<br />
I have added an interrupt to this to set a flag, to process counts, and report as necessary.<br />
The code however, due to I imagine the looping multiples of (probably) 8 sec WDT loops to enable a longer sleep function, simply goes back to sleep, untill either another interrupt, or the timeout of the sleep time, AFTER which the rest of the code executes as expected.<br />
So my question is this, is there a</p>
<p dir="auto"><strong>sleep(end);</strong></p>
<p dir="auto">type function? (can't find one)</p>
<p dir="auto">I can do this by externally to the mysensors core by looping n times, and sleeping for say 8 sec, check for the flag from the interrupt, and break the loop, but is there a mysensors way to do this?</p>
<p dir="auto">Kind Regards,<br />
Nigel</p>
]]></description><link>https://forum.mysensors.org/topic/11754/is-there-a-standard-way-to-terminate-a-sleep-time-after-waking-by-an-interrupt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 07:56:49 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/11754.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Jul 2021 09:16:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sun, 01 Aug 2021 21:38:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a><br />
Yes, that is what the sencebender gateway was for, so I could start with an easily swappable item, and the core of the network, however you might remember that I am having issues with sencebender gateway.. with no solution in sight.</p>
<p dir="auto"><a href="https://forum.mysensors.org/topic/11718/sensebender-still-same-problems-with-new-board-and-radio/6">link text</a></p>
]]></description><link>https://forum.mysensors.org/post/110694</link><guid isPermaLink="true">https://forum.mysensors.org/post/110694</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Sun, 01 Aug 2021 21:38:53 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sun, 01 Aug 2021 21:18:44 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn said in <a href="/post/110690">Is there a "standard" way to terminate a sleep time, after waking by an interrupt?</a>:</p>
<blockquote>
<p dir="auto">Please note that I am still on V 2.2.0</p>
</blockquote>
<p dir="auto">You should have started there. I fixed some nasty race conditions in the sleep code, that iirc, were not included until 2.3.0.<br />
Why don't you upgrade? These versions are on - air compatible anyway.</p>
]]></description><link>https://forum.mysensors.org/post/110692</link><guid isPermaLink="true">https://forum.mysensors.org/post/110692</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Sun, 01 Aug 2021 21:18:44 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sun, 01 Aug 2021 18:40:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a></p>
<p dir="auto">We seem to have been talking at a little crossed terminology.<br />
When I refer to the IRQ handler I mean to reference the FUNCTION which is handling the Interrupt, when the interrupt PIN is in the required state. That's why I couldn't understand why the reference to passing the handler to the sleep function was likely to work.</p>
<p dir="auto">This really brings us back to the point where I WAS using the MYSensors sleep with the interrupt pin, and interrogating as to the return (reason for waking), which in my case was "-1" even though it definitely had woken with the interrupt.<br />
This implementation ( and I didn't try a minimal sketch) wasn't working for me, as I couldn't determine why it had woken.</p>
<p dir="auto">This ultimately led me to my current solution, and calling in a loop, a 1000ms sleep, and breaking the loop if the interrupt had fired, having set a flag.</p>
<p dir="auto">I always use a WDT on my sketches, knowing that MYSensors, stores the state before sleeping, (needing as it does the hardware timer on avr) and restores it after waking (having read this elsewhere)</p>
<p dir="auto">this is the current and working sketch, , as I say I have tried using a "pure" mysensors solution, but I ONLY got "-1" for wakeupReason returned from the function.</p>
<pre><code>wakeupReason = sleep(digitalPinToInterrupt(INT_PIN), CHANGE, sleepTime);
</code></pre>
<p dir="auto">this is the current working code.</p>
<pre><code>// Enable debug prints
//#define MY_DEBUG
//#define MY_DEBUG_VERBOSE_SIGNING
//#define MY_SIGNING_SOFT
//#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
//#define MY_SIGNING_REQUEST_SIGNATURES
#define   MY_SPLASH_SCREEN_DISABLED
//#define   MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
#define MY_TRANSPORT_WAIT_READY_MS 10000
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RFM69_433MHZ // Set your frequency here
//#define MY_RFM69_MAX_POWER_LEVEL_DBM (13)   // max. TX power 10dBm = 10mW
#define   MY_RFM69_TX_POWER_DBM (13)
#define MY_IS_RFM69HW // Omit if your RFM is not "H"

#define MY_NODE_ID 32
#include &lt;MySensors.h&gt;
#include &lt;SPI.h&gt;
#include &lt;math.h&gt;
//#include &lt;TimeLib.h&gt;
#include &lt;avr/wdt.h&gt;
#include &lt;Vcc.h&gt;

#define CHILD_ID 32 // Id of the sensor child
#define VCC_MIN 3.1
#define VCC_MAX 4.16
Vcc vcc;

#define CHILD_ID_S_MOISTURE 1
//#define CHILD_ID_RELAYSTATUS 2
//#define CHILD_ID_SETPOINT 7
//#define CHILD_ID_WATERTIME 9
#define CHILD_ID_RX_RSSI 5
#define CHILD_ID_BATVCC 6
#define CHILD_ID_RAIN 11  // Indicates Tripped when rain detected
#define CHILD_ID_RAINREPORT 10  // Indicates Tripped when rain detected

// EEPROM LOCATIONS
int SetpointADD = 1;
int WaterTimeADD = 2;
int WatermmADD = 8;
// Pins
int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
int Soil_ip_pin = A1;
int SoilPowerPin = 6;
int RainPin = 3;
const int Debouncetime = 40;
int wakeupReason =0;

float fullCounter = 0.0f;
float bucketSize = 0.3f;//0.3mm rain per tip
volatile float Watermmtot = 0.0f;
float prevWatermmtot = 0.0f;
float rainratenow  = 0.0f;

unsigned long previousMillis, previousrelayMillis, previouprescence , SleepCnt , RemainSleep = 0;

volatile long currenttime = 0;
int ScaledMoisture = 20;
int oldBatteryPcnt = 0;
int SoilSetPoint = loadState(SetpointADD) ;
int WaterTime = loadState(WaterTimeADD) ;
int RawSoil = 0;

bool Slept = 0;
volatile bool RainInterrupt = 0;
bool ValidWaterCount = 0;

float batteryV  = 3.70f;
int batteryPcnt = 50;


unsigned long MYsleepTime , BaseMYsleepTime = 900000;//SLEEP_SEC*1000 * SLEEP_MINS * 60  ; //period_t is an enum type defined in the LowPower library (LowPower.h) 900000
unsigned long lastTipTime = 0;

// Initialize  message


MyMessage msgSoil(CHILD_ID_S_MOISTURE, V_LEVEL);
MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_LEVEL);
MyMessage msgVcc(CHILD_ID_BATVCC, V_VOLTAGE);
MyMessage msgRain(CHILD_ID_RAINREPORT, V_RAIN);
MyMessage lastCounterMsg(CHILD_ID_RAIN, V_TEXT);
MyMessage msgRainRate(CHILD_ID_RAINREPORT, V_RAINRATE);





// EEPROM
//This function will write a 4 byte (32bit) long to the eeprom at
//the specified address to address + 3.
void EEPROMWritelong(int address, long value)
{
  wdt_reset();
  //Decomposition from a long to 4 bytes by using bitshift.
  //One = Most significant -&gt; Four = Least significant byte
  byte four = (value &amp; 0xFF);
  byte three = ((value &gt;&gt; 8) &amp; 0xFF);
  byte two = ((value &gt;&gt; 16) &amp; 0xFF);
  byte one = ((value &gt;&gt; 24) &amp; 0xFF);

  //Write the 4 bytes into the eeprom memory.
  saveState(address, four);
  saveState(address + 1, three);
  saveState(address + 2, two);
  saveState(address + 3, one);
}// end eeprom write

long EEPROMReadlong(long address)// long eeprom read
{
  //Read the 4 bytes from the eeprom memory.
  long four = loadState(address);
  long three = loadState(address + 1);
  long two = loadState(address + 2);
  long one = loadState(address + 3);

  //Return the recomposed long by using bitshift.
  return ((four &lt;&lt; 0) &amp; 0xFF) + ((three &lt;&lt; 8) &amp; 0xFFFF) + ((two &lt;&lt; 16) &amp; 0xFFFFFF) + ((one &lt;&lt; 24) &amp; 0xFFFFFFFF);
}

// end EEPROM


void setup() {  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(SoilPowerPin, OUTPUT); // output
  pinMode(RainPin, INPUT_PULLUP);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1); // prevent initial trigger, clear interrupt
  wait(100);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1);
  attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);

  request( CHILD_ID_RAIN, V_TEXT); // readback count
  wait(4000);
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    request( CHILD_ID_RAIN, V_TEXT); // readback count
    wait(4000);
  }
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
    prevWatermmtot = Watermmtot;
  }

  // ReadEEprom();


  wdt_disable(); // Might be redundant as the bootloader should have done this already
  Serial.print("Rain &amp; Soil Sensor RES 1.1.2");

  // use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
  analogReference(INTERNAL1V1);
#else
  analogReference(INTERNAL);
#endif

  // ReadEEprom();

  wdt_enable(WDTO_8S);
}//end setup

void presentation() {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Soil Moisture_R", "1.1.2");


  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID_S_MOISTURE, S_MOISTURE, "Soil Moisture", false);
  wait(250);
  present(CHILD_ID_RX_RSSI, S_SOUND, "Soil &amp; Rain Transmitter RX RSSI", true);
  wait(250);
  present(CHILD_ID_BATVCC, S_MULTIMETER, "Battery V", false);
  wait(250);
  present(CHILD_ID_RAINREPORT, S_RAIN, "Rain", true);
  wait(250);
  present(CHILD_ID_RAIN, S_INFO, "TxTCount", true);

}//end presentation




void loop() { // put your main code here, to run repeatedly:
  
  wdt_reset();

if (RainInterrupt == 0) {
  

        getSoil();
        //unsigned long currentMillis = millis();
        // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
        analogReference(INTERNAL1V1);
      #else
        analogReference(INTERNAL);
      #endif
      
        for (int i = 0; i &lt;= 10; i++) {
          analogRead(BATTERY_SENSE_PIN);
          wait(5);
        }
      
      
        // get the battery Voltage
        int sensorValue = analogRead(BATTERY_SENSE_PIN);// * ((1e6 + 470e3) / 470e3);
      #ifdef MY_DEBUG
        Serial.print("sensorValue raw ");
        Serial.println(analogRead(BATTERY_SENSE_PIN));
        Serial.print("sensorValue V ");
        Serial.println(sensorValue);
      #endif
        wdt_reset();
        // 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+360e3)/360e3)*1.1 = Vmax = 4.15 Volts
        // 3.44/1023 = Volts per bit = 0.004062127
      
      
        //long batteryVt  = map(sensorValue, 0 , 1023, 0, 43000); // get the target positionsensorValue * 0.003363075;
        batteryV  = (sensorValue * (4.08 / 3.88)) * 0.004062127; // batteryVt/10000;
        batteryPcnt = ((batteryV - VCC_MIN) / (VCC_MAX - VCC_MIN)) * 100;// sensorValue / 10;
      
        send(msgSoil.set(ScaledMoisture, 0)); // send moisture
        wait(100);
      
        wdt_reset();
      
        //float volts = vcc.Read_Volts();
        send(msgVcc.set(batteryV, 1));
      
        //#ifdef MY_DEBUG
      
        Serial.print("Soil Moisture : ");
        Serial.print(ScaledMoisture);
        Serial.println(" cb");
      
        Serial.print("Battery Voltage count: ");
        Serial.print(sensorValue);
        Serial.println(" int");
      
        Serial.print("Battery Voltage: ");
        Serial.print(batteryV);
        Serial.println(" V");
      
        Serial.print("Battery percent: ");
        Serial.print(batteryPcnt);
        Serial.println(" %");
        //#endif
        wdt_reset();
      
        if (oldBatteryPcnt != batteryPcnt) {
          //  sendBatteryReport();
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
        }
      
        RX_SEND();
      
      
        if( Watermmtot == prevWatermmtot){
          rainratenow = 0.0;
        }
        else{
          rainratenow = ((Watermmtot - prevWatermmtot)*4) *100;
        }
      
            resend(lastCounterMsg.set(Watermmtot, 1) , true, 5);
            resend(msgRain.set(Watermmtot, 1) , true, 5);
            if(resend(msgRainRate.set(rainratenow,1) , true, 2)){
              prevWatermmtot = Watermmtot;
            }
   }// end if not rain interrupt   
        
        if (batteryPcnt &lt; 35) {
          //send(msgText.set("Sleep*10"), false);
          Serial.println("Sleep*10");
          MYsleepTime = (BaseMYsleepTime * 10);
          wdt_reset();
          //requestTime();// get time     
        }
        else if (batteryPcnt&lt;75 and batteryPcnt&gt;35) {
          //send(msgText.set("Sleep*3"), false);
          Serial.println("Sleep*3");
          wdt_reset();
          MYsleepTime = (BaseMYsleepTime * 3) ;
          //requestTime();// get time
        }
        else {
          Serial.println("Sleep :");
          wdt_reset();
          MYsleepTime = BaseMYsleepTime;
        }
    //    Serial.print("Sleepcount = ");Serial.println(SleepCnt);
     //   Serial.print("Sleeptime = ");Serial.println(MYsleepTime);  
        MYsleepTime = constrain((MYsleepTime - SleepCnt),1000,MYsleepTime);// calc how much left from last sleep
     //   Serial.print("RemainSleep = ");Serial.println(MYsleepTime);

        SleepCnt=0;
        RainInterrupt = 0;
          
// Sleeping 
 
            while((SleepCnt &lt; MYsleepTime) ){//or (wakeupReason != digitalPinToInterrupt(RainPin)) or (RainInterrupt != 1) 
              sleep(1000);
            
                  if(RainInterrupt == 1){
                    break;
                  }
                  else{
                    Slept = 1;
                    wdt_reset();
                  }
              SleepCnt=SleepCnt+1000; // count another 1000ms of sleep
              wdt_reset();
            
            }// end while
            
            if(SleepCnt&gt;=(MYsleepTime - 10000)){
              SleepCnt=0;
            }

          attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
          
          wdt_reset();

  
 wait(Debouncetime + 1);// need to wait otherwisee the debounce won't work because millis not updated in sleep

  if (RainInterrupt == 1) {// of woken due to rain bucket actions
    //  Serial.println(F("RainInterrupt=1"));

      resend(lastCounterMsg.set(Watermmtot, 1) , true, 5);
      if (resend(msgRain.set(Watermmtot, 1) , true, 5)) { // only reset if sending succeeded
        resend(msgRainRate.set(30) , true, 5);
        fullCounter = fullCounter - 1;
        //RainInterrupt = 0;
        EEPROMWritelong(WatermmADD, Watermmtot);
      }

  }

}// end loop



void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  wdt_reset();
  if (message.isAck()) {
#ifdef MY_DEBUG
    Serial.println("+Ack FMGW");
#endif
  }

#ifdef MY_DEBUG
  Serial.print("*InMsgty :");
  Serial.print(message.type);
  Serial.print(" MsgComd:");
  Serial.print(message.getCommand());
  Serial.print(" childID:");
  Serial.print(message.sensor);

  Serial.print(" Switch:");
  Serial.println(message.getFloat());
#endif


  if (message.type == V_STATUS || S_HEATER || V_LIGHT || V_TEXT || V_HVAC_SETPOINT_HEAT || V_PERCENTAGE || S_DIMMER) {


    if (message.getCommand() == 2) { // THIS PROCESSES THE CONTROLLERS EXPECTED STATE OF THE OUTPUT
      // put code here to be executed when the message is from a request
#ifdef MY_DEBUG
      Serial.print("REQ_Msg :");
      Serial.print(message.type);
      Serial.print(" MsgCmd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);
      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif

      switch (message.sensor) {// the child ID

        case 11:

          Watermmtot = message.getFloat();
          //#ifdef MY_DEBUG
          Serial.print(" Incoming Rain mm:");
          Serial.println(Watermmtot);
          //#endif
          if (Watermmtot &gt;= 0.3) {
            EEPROMWritelong(WatermmADD, Watermmtot);
          }
          else {
            Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
            ValidWaterCount = 1;
          }
          break;

      } // end switch




    }// end msg=2

    if (message.getCommand() == 1) { // THIS PROCESSES DIRECTED COMMANDS


#ifdef MY_DEBUG
      Serial.print("*InMsgty :");
      Serial.print(message.type);
      Serial.print(" MsgComd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);

      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif
      /*
            switch (message.sensor) {// the child ID

              case 2:
                TempRELAY = message.getBool();
                //#ifdef MY_DEBUG
                Serial.print(" Incoming rELAY:");
                Serial.println(TempRELAY);
                //#endif

                watering = TempRELAY;

                send(msgRelay.set(watering, 0)); // send relay state


                break;

            } // end switch

      */


    }// end if msg = 1


  }// end msg type function

}// end void loop



void RX_SEND()
{
  wdt_reset();
  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
  wdt_reset();
}


void sendBatteryReport() {
  wdt_reset();

  float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
  int batteryPcnt = static_cast&lt;int&gt;(p);
#ifdef MY_DEBUG
  Serial.print("Battery is: "); Serial.println(batteryPcnt);
#endif
  sendBatteryLevel(batteryPcnt);
}



void ReadEEprom() {
  wdt_reset();
  //if (EEPROMReadlong(SetpointADD) &gt; 0) SoilSetPoint = EEPROMReadlong(SetpointADD) ;
  //if (EEPROMReadlong(WaterTimeADD) &gt; 0) WaterTime = EEPROMReadlong(WaterTimeADD) ;

  if (loadState(SetpointADD) &gt; 0) SoilSetPoint = loadState(SetpointADD) ;
  if (loadState(WaterTimeADD) &gt; 0) WaterTime = loadState(WaterTimeADD) ;

}



void getSoil() {
  wdt_reset();

  analogReference(DEFAULT);
  for (int i = 0; i &lt;= 10; i++) {
    RawSoil = analogRead(Soil_ip_pin);
    wait(5);
  }

  int soilCount = 0;
  unsigned long soilAccum = 0;
  digitalWrite(SoilPowerPin, HIGH); // Power up sensor
  wait(1000);

  RawSoil = analogRead(Soil_ip_pin);
  soilAccum = RawSoil;
  while (soilCount &lt; 50) {
    wait(20);
    RawSoil = analogRead(Soil_ip_pin);
    if (RawSoil &gt; 0) {
      soilAccum = soilAccum + RawSoil;
    }
    soilCount++;
  }
  Serial.print("SCount ");
  Serial.println(soilCount);
  RawSoil = soilAccum / soilCount;
  Serial.print("RawSoil ");
  Serial.println(RawSoil);

  wait(1);
  ScaledMoisture = map(RawSoil, 600 , 0, 0, 100); // get the target position
  digitalWrite(SoilPowerPin, LOW); // Power down sensor

  Serial.print("Scaled Moisture CB ");
  Serial.println(ScaledMoisture);

}

void RainINT() {
  
  unsigned long thisTipTime = millis();
  if (thisTipTime - lastTipTime &gt; (Debouncetime)) {// debounce 20ms
    Watermmtot = Watermmtot + bucketSize;
    fullCounter = fullCounter + bucketSize;//Count so we send the counter for every 1mm
    RainInterrupt = 1;
    lastTipTime = thisTipTime;
  }
}


bool resend(MyMessage &amp; msg, bool ack, int repeats)
{
  wdt_reset();
  int repeat = 1;
  int repeatdelay = 0;
  boolean sendOK = false;

  while ((sendOK == false) and (repeat &lt; repeats)) {
    if (send(msg, ack)) {
      sendOK = true;
    } else {
      sendOK = false;
      Serial.print("TX Error ");
      Serial.println(repeat);
      repeatdelay += 200;
      if (repeatdelay &gt;= 500) {
        repeatdelay = 500;
      }
      wdt_reset();
    } repeat++; wait(repeatdelay);
  }
  return sendOK;
}
</code></pre>
<p dir="auto">For my own education, I will build a new note to test the sleep and interrupt, and see where /  how thing are not working, but that won't happen till later in the week.</p>
<p dir="auto">Please note that I am still on V 2.2.0</p>
]]></description><link>https://forum.mysensors.org/post/110690</link><guid isPermaLink="true">https://forum.mysensors.org/post/110690</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Sun, 01 Aug 2021 18:40:40 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sun, 01 Aug 2021 17:31:28 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn said in <a href="/post/110678">Is there a "standard" way to terminate a sleep time, after waking by an interrupt?</a>:</p>
<blockquote>
<p dir="auto">so if I just define the pin as INPUT_PULLUP, and not attach a interrupt, when I call sleep, passing the interrupt handler, it WILL call the handler?</p>
</blockquote>
<p dir="auto">You shall not pass the interrupt handler, but the interrupt <strong>number</strong> instead. Each pin that supports interrupts can trigger a certain interrupt. The interrupt number for a pin is returned when calling digitalPinToInterrupt(). You can read more on the topic <a href="https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/" rel="nofollow ugc">here</a>.<br />
During the execution of the sleep() function, a new interrupt handler will be installed that is used to handle the wake-from-interrupt. It is detached again, before returning from sleep().</p>
<p dir="auto">About the most minimalist implementation is the following, which compiles without errors:</p>
<pre><code>#include &lt;Arduino.h&gt;

#define MY_RADIO_RF24
#include &lt;MySensors.h&gt;

#define MY_PIN         (3)
#define CHILD_ID       (0)
#define SLEEP_TIME_MS  (60000)
#define SKETCH_NAME    F("Test")
#define SKETCH_VERSION F("1.0")

void presentation()
{
    sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
    present(CHILD_ID, S_RAIN, F("Rain"));
}

void setup()
{
    pinMode(CHILD_ID, INPUT_PULLUP);
}

void loop()
{
    auto result = sleep(digitalPinToInterrupt(MY_PIN), RISING, SLEEP_TIME_MS);
    Serial.println(result);
}
</code></pre>
<blockquote>
<p dir="auto">How is it possible to utilise an interrupt on a otherwise sleeping node, WHEN it is awake?</p>
</blockquote>
<p dir="auto">I did not relealize before that you wanted to install your own interrupt handler for the same pin when the node is awake.<br />
To achieve this, you can just attach your own handler after returning from sleep(), something like:</p>
<pre><code>// .. same code as above ..
void RainINT(void)
{
  // .. handle the interrupt ..
}

void loop()
{
    auto result = sleep(digitalPinToInterrupt(MY_PIN), RISING, SLEEP_TIME_MS);
    attachInterrupt(digitalPinToInterrupt(MY_PIN), RainINT, FALLING);
    Serial.println(result);
}
</code></pre>
<p dir="auto">Just be aware that the call to sleep() will overwrite your installed interrupt handler, so you need to reinstall it after returning from sleep().</p>
<blockquote>
<p dir="auto">separately, what is wrong with my watchdog implementation?</p>
</blockquote>
<p dir="auto">MySensors on AVR uses the watchdog to wake a sleeping node after a certain amount of time.<br />
To achieve this, it reprograms the watchdog just as it does with the interrupt handler.<br />
In most cases you will be just fine if you reprogram the watchdog settings when returning from sleep(), just as when reattaching the interrupt handler.</p>
<p dir="auto">However, as MySensors hides you from a lot of nastiness by taking over hardware specifics, you must understand its limitations.<br />
That's why I do not suggest most users to follow your solution but instead, don't use the watchdog or try to share interrupts.</p>
]]></description><link>https://forum.mysensors.org/post/110689</link><guid isPermaLink="true">https://forum.mysensors.org/post/110689</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Sun, 01 Aug 2021 17:31:28 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sat, 31 Jul 2021 22:18:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a><br />
Many thanks for coming back.<br />
Ok, so if I just define the pin as INPUT_PULLUP, and not attach a interrupt, when I call sleep, passing the interrupt handler, it WILL call the handler?</p>
<p dir="auto">the compiler outputs:</p>
<pre><code>N:\Home Automation\Arduino\MySensors\Solar_Soil_Sensor_and_Rain_Sensor\Solar_Soil_Sensor_and_Rain_Sensor.ino:298:40: warning: invalid conversion from 'void (*)()' to 'uint8_t {aka unsigned char}' [-fpermissive]
     sleep(RainINT, FALLING, MYsleepTime);


</code></pre>
<p dir="auto">when I invoke the sleep, passing the interrupt handler.</p>
<p dir="auto">How is it possible to utilise an interrupt on a otherwise sleeping node, WHEN it is awake?<br />
This is one of the "issues" I mentioned above by not using / invoking the attachment of the interrupt  at all, and why I tried to use the normal attachment of the interrupt, then detaching it, just prior to calling the sleep (albeit passing the pin, rather than the handler). devices that would suffer without being able to utilise interrupts when awake, would include among others, a rain sensor, a flow meter, even a pulse counter for say a water meter, if battery powered, and needing to sleep.</p>
<p dir="auto">separately, what is wrong with my watchdog implementation?</p>
<p dir="auto">many thanks and regards Nigel</p>
]]></description><link>https://forum.mysensors.org/post/110678</link><guid isPermaLink="true">https://forum.mysensors.org/post/110678</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Sat, 31 Jul 2021 22:18:05 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Sat, 31 Jul 2021 17:34:18 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn Good to see you how have a somewhat working solution.<br />
Just configuring the pin for input, and passing the corresponding interrupt (not the pin) to the sleep() fuction as in my example does work.<br />
I have many sleeping sensors that wake from either timer or interrupt and they all work correctly.</p>
<p dir="auto">Others, please don't use this as an example, as the manual watchdog and interrupt handling will likely interfere  with the MySensors AVR implementation.</p>
<p dir="auto">I can only help when the exact compiler error is known (not "the compiler complained (unsurprisingly I thought), as it is expecting a uint8_t"), and if you provide a minimal sketch that exhibits the compiler error.</p>
<p dir="auto">The hardware could also be a cause of errors; bouncing switches and sleeping nodes don't play together nicely, unless signals are debounced.</p>
]]></description><link>https://forum.mysensors.org/post/110677</link><guid isPermaLink="true">https://forum.mysensors.org/post/110677</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Sat, 31 Jul 2021 17:34:18 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Fri, 30 Jul 2021 11:51:16 GMT]]></title><description><![CDATA[<p dir="auto">Update.<br />
If I called the sleep, passing the interrupt, rather than the pin</p>
<pre><code>sleep(digitalPinToInterrupt(RainINT), FALLING, MYsleepTime);
</code></pre>
<p dir="auto">the compiler complained (unsurprisingly I thought), as it is expecting a uint8_t</p>
<p dir="auto">int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2,</p>
<p dir="auto">If I passed the pin, but utilised the return value as in</p>
<pre><code>wakeupReason = sleep(digitalPinToInterrupt(INT_PIN), CHANGE, sleepTime);
</code></pre>
<p dir="auto">ALL Iever got was "-1" as a return value, EVEN THOUGH the interrupt was firing (still having defined and attached the interrupt)</p>
<pre><code>pinMode(RainPin, INPUT_PULLUP);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1); // prevent initial trigger, clear interrupt
  wait(100);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1);
  attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
</code></pre>
<p dir="auto">If I detached the interrupt, before calling the sleep function with</p>
<pre><code>
  detachInterrupt(digitalPinToInterrupt(RainPin));
</code></pre>
<p dir="auto">then the Interrupt failed to execute, NOR did the return value from the sleep function deviate from -1<br />
I was calling this for 1000ms, in a loop, checking the return value and executing the original RainInt()  to do the counting/ incrementing.</p>
<p dir="auto">In the end I have gone with my own looping sleep, and checking at the end of each sleep, for the interrupt having fired.</p>
<pre><code>// Sleeping 
 
            while((SleepCnt &lt; MYsleepTime) ){
              sleep(1000);
            
                  if(RainInterrupt == 1){
                    break;
                  }
                  else{
                    Slept = 1;
                    wdt_reset();
                  }
              SleepCnt=SleepCnt+1000; // count another 1000ms of sleep
              wdt_reset();
            
            }// end while
</code></pre>
<p dir="auto">This works fine, including actioning the interrupt if it occurs during the rest of the loop.</p>
<p dir="auto">should anyone be interested, here is the whole sketch, no douby it can be much improved upon, but it is working.</p>
<pre><code>// Enable debug prints
//#define MY_DEBUG
//#define MY_DEBUG_VERBOSE_SIGNING
//#define MY_SIGNING_SOFT
//#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
//#define MY_SIGNING_REQUEST_SIGNATURES
#define   MY_SPLASH_SCREEN_DISABLED
//#define   MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
#define MY_TRANSPORT_WAIT_READY_MS 10000
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RFM69_433MHZ // Set your frequency here
//#define MY_RFM69_MAX_POWER_LEVEL_DBM (13)   // max. TX power 10dBm = 10mW
#define   MY_RFM69_TX_POWER_DBM (13)
#define MY_IS_RFM69HW // Omit if your RFM is not "H"

#define MY_NODE_ID 32
#include &lt;MySensors.h&gt;
#include &lt;SPI.h&gt;
#include &lt;math.h&gt;
//#include &lt;TimeLib.h&gt;
#include &lt;avr/wdt.h&gt;
#include &lt;Vcc.h&gt;

#define CHILD_ID 32 // Id of the sensor child
#define VCC_MIN 3.1
#define VCC_MAX 4.16
Vcc vcc;

#define CHILD_ID_S_MOISTURE 1
//#define CHILD_ID_RELAYSTATUS 2
//#define CHILD_ID_SETPOINT 7
//#define CHILD_ID_WATERTIME 9
#define CHILD_ID_RX_RSSI 5
#define CHILD_ID_BATVCC 6
#define CHILD_ID_RAIN 11  // Indicates Tripped when rain detected
#define CHILD_ID_RAINREPORT 10  // Indicates Tripped when rain detected

// EEPROM LOCATIONS
int SetpointADD = 1;
int WaterTimeADD = 2;
int WatermmADD = 8;
// Pins
int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
int Soil_ip_pin = A1;
int SoilPowerPin = 6;
int RainPin = 3;
const int Debouncetime = 40;
int wakeupReason =0;

float fullCounter = 0.0f;
float bucketSize = 0.3f;//0.3mm rain per tip
volatile float Watermmtot = 0.0f;
float prevWatermmtot = 0.0f;
float rainratenow  = 0.0f;

unsigned long previousMillis, previousrelayMillis, previouprescence , SleepCnt , RemainSleep = 0;

volatile long currenttime = 0;
int ScaledMoisture = 20;
int oldBatteryPcnt = 0;
int SoilSetPoint = loadState(SetpointADD) ;
int WaterTime = loadState(WaterTimeADD) ;
int RawSoil = 0;

bool Slept = 0;
volatile bool RainInterrupt = 0;
bool ValidWaterCount = 0;

float batteryV  = 3.70f;
int batteryPcnt = 50;


unsigned long MYsleepTime , BaseMYsleepTime = 900000;//SLEEP_SEC*1000 * SLEEP_MINS * 60  ; //period_t is an enum type defined in the LowPower library (LowPower.h) 900000
unsigned long lastTipTime = 0;

// Initialize  message


MyMessage msgSoil(CHILD_ID_S_MOISTURE, V_LEVEL);
MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_LEVEL);
MyMessage msgVcc(CHILD_ID_BATVCC, V_VOLTAGE);
MyMessage msgRain(CHILD_ID_RAINREPORT, V_RAIN);
MyMessage lastCounterMsg(CHILD_ID_RAIN, V_TEXT);
MyMessage msgRainRate(CHILD_ID_RAINREPORT, V_RAINRATE);





// EEPROM
//This function will write a 4 byte (32bit) long to the eeprom at
//the specified address to address + 3.
void EEPROMWritelong(int address, long value)
{
  wdt_reset();
  //Decomposition from a long to 4 bytes by using bitshift.
  //One = Most significant -&gt; Four = Least significant byte
  byte four = (value &amp; 0xFF);
  byte three = ((value &gt;&gt; 8) &amp; 0xFF);
  byte two = ((value &gt;&gt; 16) &amp; 0xFF);
  byte one = ((value &gt;&gt; 24) &amp; 0xFF);

  //Write the 4 bytes into the eeprom memory.
  saveState(address, four);
  saveState(address + 1, three);
  saveState(address + 2, two);
  saveState(address + 3, one);
}// end eeprom write

long EEPROMReadlong(long address)// long eeprom read
{
  //Read the 4 bytes from the eeprom memory.
  long four = loadState(address);
  long three = loadState(address + 1);
  long two = loadState(address + 2);
  long one = loadState(address + 3);

  //Return the recomposed long by using bitshift.
  return ((four &lt;&lt; 0) &amp; 0xFF) + ((three &lt;&lt; 8) &amp; 0xFFFF) + ((two &lt;&lt; 16) &amp; 0xFFFFFF) + ((one &lt;&lt; 24) &amp; 0xFFFFFFFF);
}

// end EEPROM


void setup() {  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(SoilPowerPin, OUTPUT); // output
  pinMode(RainPin, INPUT_PULLUP);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1); // prevent initial trigger, clear interrupt
  wait(100);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1);
  attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);

  request( CHILD_ID_RAIN, V_TEXT); // readback count
  wait(4000);
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    request( CHILD_ID_RAIN, V_TEXT); // readback count
    wait(4000);
  }
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
    prevWatermmtot = Watermmtot;
  }

  // ReadEEprom();


  wdt_disable(); // Might be redundant as the bootloader should have done this already
  Serial.print("Rain &amp; Soil Sensor RES 1.1.2");

  // use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
  analogReference(INTERNAL1V1);
#else
  analogReference(INTERNAL);
#endif

  // ReadEEprom();

  wdt_enable(WDTO_8S);
}//end setup

void presentation() {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Soil Moisture_R", "1.1.2");


  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID_S_MOISTURE, S_MOISTURE, "Soil Moisture", false);
  wait(250);
  present(CHILD_ID_RX_RSSI, S_SOUND, "Soil &amp; Rain Transmitter RX RSSI", true);
  wait(250);
  present(CHILD_ID_BATVCC, S_MULTIMETER, "Battery V", false);
  wait(250);
  present(CHILD_ID_RAINREPORT, S_RAIN, "Rain", true);
  wait(250);
  present(CHILD_ID_RAIN, S_INFO, "TxTCount", true);

}//end presentation




void loop() { // put your main code here, to run repeatedly:
  
  wdt_reset();

if (RainInterrupt == 0) {
  

        getSoil();
        //unsigned long currentMillis = millis();
        // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
        analogReference(INTERNAL1V1);
      #else
        analogReference(INTERNAL);
      #endif
      
        for (int i = 0; i &lt;= 10; i++) {
          analogRead(BATTERY_SENSE_PIN);
          wait(5);
        }
      
      
        // get the battery Voltage
        int sensorValue = analogRead(BATTERY_SENSE_PIN);// * ((1e6 + 470e3) / 470e3);
      #ifdef MY_DEBUG
        Serial.print("sensorValue raw ");
        Serial.println(analogRead(BATTERY_SENSE_PIN));
        Serial.print("sensorValue V ");
        Serial.println(sensorValue);
      #endif
        wdt_reset();
        // 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+360e3)/360e3)*1.1 = Vmax = 4.15 Volts
        // 3.44/1023 = Volts per bit = 0.004062127
      
      
        //long batteryVt  = map(sensorValue, 0 , 1023, 0, 43000); // get the target positionsensorValue * 0.003363075;
        batteryV  = (sensorValue * (4.08 / 3.88)) * 0.004062127; // batteryVt/10000;
        batteryPcnt = ((batteryV - VCC_MIN) / (VCC_MAX - VCC_MIN)) * 100;// sensorValue / 10;
      
        send(msgSoil.set(ScaledMoisture, 0)); // send moisture
        wait(100);
      
        wdt_reset();
      
        //float volts = vcc.Read_Volts();
        send(msgVcc.set(batteryV, 1));
      
        //#ifdef MY_DEBUG
      
        Serial.print("Soil Moisture : ");
        Serial.print(ScaledMoisture);
        Serial.println(" cb");
      
        Serial.print("Battery Voltage count: ");
        Serial.print(sensorValue);
        Serial.println(" int");
      
        Serial.print("Battery Voltage: ");
        Serial.print(batteryV);
        Serial.println(" V");
      
        Serial.print("Battery percent: ");
        Serial.print(batteryPcnt);
        Serial.println(" %");
        //#endif
        wdt_reset();
      
        if (oldBatteryPcnt != batteryPcnt) {
          //  sendBatteryReport();
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
        }
      
        RX_SEND();
      
      
        if( Watermmtot == prevWatermmtot){
          rainratenow = 0.0;
        }
        else{
          rainratenow = ((Watermmtot - prevWatermmtot)*4) *100;
        }
      
            resend(lastCounterMsg.set(Watermmtot, 1) , true, 5);
            resend(msgRain.set(Watermmtot, 1) , true, 5);
            if(resend(msgRainRate.set(rainratenow,1) , true, 2)){
              prevWatermmtot = Watermmtot;
            }
   }// end if not rain interrupt   
        
        if (batteryPcnt &lt; 35) {
          //send(msgText.set("Sleep*10"), false);
          Serial.println("Sleep*10");
          MYsleepTime = (BaseMYsleepTime * 10);
          wdt_reset();
          //requestTime();// get time     
        }
        else if (batteryPcnt&lt;75 and batteryPcnt&gt;35) {
          //send(msgText.set("Sleep*3"), false);
          Serial.println("Sleep*3");
          wdt_reset();
          MYsleepTime = (BaseMYsleepTime * 3) ;
          //requestTime();// get time
        }
        else {
          Serial.println("Sleep :");
          wdt_reset();
          MYsleepTime = BaseMYsleepTime;
        }
    //    Serial.print("Sleepcount = ");Serial.println(SleepCnt);
     //   Serial.print("Sleeptime = ");Serial.println(MYsleepTime);  
        MYsleepTime = constrain((MYsleepTime - SleepCnt),1000,MYsleepTime);// calc how much left from last sleep
     //   Serial.print("RemainSleep = ");Serial.println(MYsleepTime);

        SleepCnt=0;
        RainInterrupt = 0;
          
// Sleeping 
 
            while((SleepCnt &lt; MYsleepTime) ){//or (wakeupReason != digitalPinToInterrupt(RainPin)) or (RainInterrupt != 1) 
              sleep(1000);
            
                  if(RainInterrupt == 1){
                    break;
                  }
                  else{
                    Slept = 1;
                    wdt_reset();
                  }
              SleepCnt=SleepCnt+1000; // count another 1000ms of sleep
              wdt_reset();
            
            }// end while
            
            if(SleepCnt&gt;=(MYsleepTime - 10000)){
              SleepCnt=0;
            }

          attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
          
          wdt_reset();

  
 wait(Debouncetime + 1);// need to wait otherwisee the debounce won't work because millis not updated in sleep

  if (RainInterrupt == 1) {// of woken due to rain bucket actions
    //  Serial.println(F("RainInterrupt=1"));

      resend(lastCounterMsg.set(Watermmtot, 1) , true, 5);
      if (resend(msgRain.set(Watermmtot, 1) , true, 5)) { // only reset if sending succeeded
        resend(msgRainRate.set(30) , true, 5);
        fullCounter = fullCounter - 1;
        //RainInterrupt = 0;
        EEPROMWritelong(WatermmADD, Watermmtot);
      }

  }

}// end loop



void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  wdt_reset();
  if (message.isAck()) {
#ifdef MY_DEBUG
    Serial.println("+Ack FMGW");
#endif
  }

#ifdef MY_DEBUG
  Serial.print("*InMsgty :");
  Serial.print(message.type);
  Serial.print(" MsgComd:");
  Serial.print(message.getCommand());
  Serial.print(" childID:");
  Serial.print(message.sensor);

  Serial.print(" Switch:");
  Serial.println(message.getFloat());
#endif


  if (message.type == V_STATUS || S_HEATER || V_LIGHT || V_TEXT || V_HVAC_SETPOINT_HEAT || V_PERCENTAGE || S_DIMMER) {


    if (message.getCommand() == 2) { // THIS PROCESSES THE CONTROLLERS EXPECTED STATE OF THE OUTPUT
      // put code here to be executed when the message is from a request
#ifdef MY_DEBUG
      Serial.print("REQ_Msg :");
      Serial.print(message.type);
      Serial.print(" MsgCmd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);
      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif

      switch (message.sensor) {// the child ID

        case 11:

          Watermmtot = message.getFloat();
          //#ifdef MY_DEBUG
          Serial.print(" Incoming Rain mm:");
          Serial.println(Watermmtot);
          //#endif
          if (Watermmtot &gt;= 0.3) {
            EEPROMWritelong(WatermmADD, Watermmtot);
          }
          else {
            Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
            ValidWaterCount = 1;
          }
          break;

      } // end switch

    }// end msg=2

    if (message.getCommand() == 1) { // THIS PROCESSES DIRECTED COMMANDS


#ifdef MY_DEBUG
      Serial.print("*InMsgty :");
      Serial.print(message.type);
      Serial.print(" MsgComd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);

      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif
  
    }// end if msg = 1

  }// end msg type function

}// end void loop



void RX_SEND()
{
  wdt_reset();
  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
  wdt_reset();
}


void sendBatteryReport() {
  wdt_reset();

  float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
  int batteryPcnt = static_cast&lt;int&gt;(p);
#ifdef MY_DEBUG
  Serial.print("Battery is: "); Serial.println(batteryPcnt);
#endif
  sendBatteryLevel(batteryPcnt);
}



void ReadEEprom() {
  wdt_reset();
  //if (EEPROMReadlong(SetpointADD) &gt; 0) SoilSetPoint = EEPROMReadlong(SetpointADD) ;
  //if (EEPROMReadlong(WaterTimeADD) &gt; 0) WaterTime = EEPROMReadlong(WaterTimeADD) ;

  if (loadState(SetpointADD) &gt; 0) SoilSetPoint = loadState(SetpointADD) ;
  if (loadState(WaterTimeADD) &gt; 0) WaterTime = loadState(WaterTimeADD) ;

}



void getSoil() {
  wdt_reset();

  analogReference(DEFAULT);
  for (int i = 0; i &lt;= 10; i++) {
    RawSoil = analogRead(Soil_ip_pin);
    wait(5);
  }

  int soilCount = 0;
  unsigned long soilAccum = 0;
  digitalWrite(SoilPowerPin, HIGH); // Power up sensor
  wait(1000);

  RawSoil = analogRead(Soil_ip_pin);
  soilAccum = RawSoil;
  while (soilCount &lt; 50) {
    wait(20);
    RawSoil = analogRead(Soil_ip_pin);
    if (RawSoil &gt; 0) {
      soilAccum = soilAccum + RawSoil;
    }
    soilCount++;
  }
  Serial.print("SCount ");
  Serial.println(soilCount);
  RawSoil = soilAccum / soilCount;
  Serial.print("RawSoil ");
  Serial.println(RawSoil);

  wait(1);
  ScaledMoisture = map(RawSoil, 600 , 0, 0, 100); // get the target position
  digitalWrite(SoilPowerPin, LOW); // Power down sensor

  Serial.print("Scaled Moisture CB ");
  Serial.println(ScaledMoisture);

}

void RainINT() {
  
  unsigned long thisTipTime = millis();
  if (thisTipTime - lastTipTime &gt; (Debouncetime)) {// debounce 20ms
    Watermmtot = Watermmtot + bucketSize;
    fullCounter = fullCounter + bucketSize;//Count so we send the counter for every 1mm
    RainInterrupt = 1;
    lastTipTime = thisTipTime;
  }
}


bool resend(MyMessage &amp; msg, bool ack, int repeats)
{
  wdt_reset();
  int repeat = 1;
  int repeatdelay = 0;
  boolean sendOK = false;

  while ((sendOK == false) and (repeat &lt; repeats)) {
    if (send(msg, ack)) {
      sendOK = true;
    } else {
      sendOK = false;
      Serial.print("TX Error ");
      Serial.println(repeat);
      repeatdelay += 200;
      if (repeatdelay &gt;= 500) {
        repeatdelay = 500;
      }
      wdt_reset();
    } repeat++; wait(repeatdelay);
  }
  return sendOK;
}


</code></pre>
<p dir="auto">Many thanks for the input.</p>
<p dir="auto">Regards<br />
Nigel</p>
]]></description><link>https://forum.mysensors.org/post/110666</link><guid isPermaLink="true">https://forum.mysensors.org/post/110666</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Fri, 30 Jul 2021 11:51:16 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Thu, 29 Jul 2021 21:39:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a><br />
many thanks for the response.<br />
So if I understand correctly, you are saying (in my code above) that I should call</p>
<pre><code>sleep(digitalPinToInterrupt(RainINT), FALLING, MYsleepTime);

</code></pre>
<p dir="auto">that is passing the interrupt handler RATHER than the PIN?</p>
<p dir="auto">BUT still call</p>
<pre><code>pinMode(RainPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
</code></pre>
<p dir="auto">in the setup?</p>
<p dir="auto">From my reading of the code you reference above, any existing interrupt handler is disabled prior to the final sleeping, and re-attachment of the interrupt. However I don't see where it might reference the interrupt handler.<br />
I see that a value is returned after waking, which is either the pin, or "0" dependant on wake cause, and this is utilised in the example you quote above.</p>
<p dir="auto">Question, Is an existing interrupt handler re-instated anywhere after waking? or is it up to me to re-attech the IRQ handler? I ask, as if not then any "event" occurring whilst <strong>not</strong> sleeping will be missed. which in my case is quite likely during heavy rain.<br />
Sorry if I am being a little thick. Might it be better for me to use just a short timed sleep (say 1 sec), loop for n sec to provide my ultimate sleep time, subject to breaking the loop if a interrupt occurs, by setting a flag in the IRQ handler.<br />
I realise this is what is sort of being done in the example above, using Mysensors returned value from the sleep + interrupt function, but it won't (I think) address the case of an interrupt occuring whilst actioning the several seconds potentially utilised during the main loop, especially if there are re-transmit attempts.</p>
<p dir="auto">Once again many thanks for the help.</p>
<p dir="auto">regards Nigel</p>
]]></description><link>https://forum.mysensors.org/post/110665</link><guid isPermaLink="true">https://forum.mysensors.org/post/110665</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Thu, 29 Jul 2021 21:39:10 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 17:15:53 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn yes, the sleep() function which takes an interrupt will install an interrupt handler, enable interrupts for wakeup and then goes to sleep for the specified time, unless it wakes early from an interrupt.<br />
Its use and some example code is documented here: <a href="https://www.mysensors.org/download/sensor_api_20#sleeping" rel="nofollow ugc">https://www.mysensors.org/download/sensor_api_20#sleeping</a></p>
<p dir="auto">If you're into low-level coding you can find the heart of the underlying library implementation for AVR here <a href="https://github.com/mysensors/MySensors/blob/b9d9cc339659f724aa94d4108fc5289a720d1bcd/hal/architecture/AVR/MyHwAVR.cpp#L175" rel="nofollow ugc">https://github.com/mysensors/MySensors/blob/b9d9cc339659f724aa94d4108fc5289a720d1bcd/hal/architecture/AVR/MyHwAVR.cpp#L175</a><br />
It takes care of some tricky corner-cases involving interrupts and sleeping the CPU.</p>
<p dir="auto">Note that you should call sleep() as</p>
<pre><code>sleep(digitalPinToInterrupt(RainPin), FALLING, MYsleepTime);
</code></pre>
<p dir="auto">so pass it an interrupt instead of the pin number</p>
]]></description><link>https://forum.mysensors.org/post/110659</link><guid isPermaLink="true">https://forum.mysensors.org/post/110659</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Wed, 28 Jul 2021 17:15:53 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 13:19:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a><br />
Could you elaborate a little please on the declaration of the interrupt?<br />
Are you saying that the sleep function</p>
<pre><code>sleep(RainPin, FALLING, MYsleepTime);
</code></pre>
<p dir="auto">Sets an interrupt handler, the same as</p>
<pre><code>attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
</code></pre>
<p dir="auto">If that's the case, how does it know what routeen to call?<br />
If I do not declare the interrupt, as usual, then surely, when code is in the middle of executing in the loop, or another function, how would the event be captured?</p>
<p dir="auto">many thanks<br />
Nigel</p>
]]></description><link>https://forum.mysensors.org/post/110658</link><guid isPermaLink="true">https://forum.mysensors.org/post/110658</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Wed, 28 Jul 2021 13:19:50 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 11:00:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yveaux" aria-label="Profile: Yveaux">@<bdi>Yveaux</bdi></a></p>
<p dir="auto">Full sketch as requested. the sketch includes some serial.prints in the interrupt handler for debug purposes.<br />
the vast majority of the interrupt code, was in the main loop, I have moved it in order to get "on demand" transmissions, so I can test Domoticz / setup the device. I HAD to include somthing for the rainrate, else donoticz wouldnt create the device, even though it showed up in hardware OK.</p>
<pre><code>// Enable debug prints
//#define MY_DEBUG
//#define MY_DEBUG_VERBOSE_SIGNING
//#define MY_SIGNING_SOFT
//#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
//#define MY_SIGNING_REQUEST_SIGNATURES
#define   MY_SPLASH_SCREEN_DISABLED
//#define   MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
#define MY_TRANSPORT_WAIT_READY_MS 10000
#define MY_RADIO_RFM69
#define MY_RFM69_FREQUENCY RFM69_433MHZ // Set your frequency here
//#define MY_RFM69_MAX_POWER_LEVEL_DBM (13)   // max. TX power 10dBm = 10mW
#define   MY_RFM69_TX_POWER_DBM (13)
#define MY_IS_RFM69HW // Omit if your RFM is not "H"

#define MY_NODE_ID 32
#include &lt;MySensors.h&gt;
#include &lt;SPI.h&gt;
#include &lt;math.h&gt;
#include &lt;TimeLib.h&gt;
#include &lt;avr/wdt.h&gt;
#include &lt;Vcc.h&gt;

#define CHILD_ID 32 // Id of the sensor child
#define VCC_MIN 3.1
#define VCC_MAX 4.1
Vcc vcc;

#define CHILD_ID_S_MOISTURE 1
//#define CHILD_ID_RELAYSTATUS 2
//#define CHILD_ID_SETPOINT 7
//#define CHILD_ID_WATERTIME 9
#define CHILD_ID_RX_RSSI 5
#define CHILD_ID_BATVCC 6
#define CHILD_ID_RAIN 11  // Indicates Tripped when rain detected
#define CHILD_ID_RAINREPORT 10  // Indicates Tripped when rain detected

// EEPROM LOCATIONS
int SetpointADD = 1;
int WaterTimeADD = 2;
int WatermmADD = 8;
// Pins
int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
int Soil_ip_pin = A1;
int SoilPowerPin = 6;
int RainPin = 3;

float fullCounter = 0.0f;
float bucketSize = 0.3f;//0.3mm rain per tip
float Watermmtot = 0.0f;

unsigned long previousMillis, previousrelayMillis, previouprescence = 0;

volatile long currenttime = 0;
int ScaledMoisture = 20;
int oldBatteryPcnt = 0;
int SoilSetPoint = loadState(SetpointADD) ;
int WaterTime = loadState(WaterTimeADD) ;
int RawSoil = 0;

bool Slept = 0;
bool RainInterrupt = 0;
bool ValidWaterCount = 0;

unsigned long MYsleepTime = 3600000;//SLEEP_SEC*1000 * SLEEP_MINS * 60  ; //period_t is an enum type defined in the LowPower library (LowPower.h)
unsigned long lastTipTime = 0;

// Initialize  message


MyMessage msgSoil(CHILD_ID_S_MOISTURE, V_LEVEL);
MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_LEVEL);
MyMessage msgVcc(CHILD_ID_BATVCC, V_VOLTAGE);
MyMessage msgRain(CHILD_ID_RAINREPORT, V_RAIN);
MyMessage lastCounterMsg(CHILD_ID_RAIN, V_TEXT);
MyMessage msgRainRate(CHILD_ID_RAINREPORT, V_RAINRATE);





// EEPROM
//This function will write a 4 byte (32bit) long to the eeprom at
//the specified address to address + 3.
void EEPROMWritelong(int address, long value)
{
  wdt_reset();
  //Decomposition from a long to 4 bytes by using bitshift.
  //One = Most significant -&gt; Four = Least significant byte
  byte four = (value &amp; 0xFF);
  byte three = ((value &gt;&gt; 8) &amp; 0xFF);
  byte two = ((value &gt;&gt; 16) &amp; 0xFF);
  byte one = ((value &gt;&gt; 24) &amp; 0xFF);

  //Write the 4 bytes into the eeprom memory.
  saveState(address, four);
  saveState(address + 1, three);
  saveState(address + 2, two);
  saveState(address + 3, one);
}// end eeprom write

long EEPROMReadlong(long address)// long eeprom read
{
  //Read the 4 bytes from the eeprom memory.
  long four = loadState(address);
  long three = loadState(address + 1);
  long two = loadState(address + 2);
  long one = loadState(address + 3);

  //Return the recomposed long by using bitshift.
  return ((four &lt;&lt; 0) &amp; 0xFF) + ((three &lt;&lt; 8) &amp; 0xFFFF) + ((two &lt;&lt; 16) &amp; 0xFFFFFF) + ((one &lt;&lt; 24) &amp; 0xFFFFFFFF);
}

// end EEPROM


void setup() {  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(SoilPowerPin, OUTPUT); // output
  pinMode(RainPin, INPUT_PULLUP);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1); // prevent initial trigger, clear interrupt
  wait(100);
  EIFR = (1 &lt;&lt; INTF0) | (1 &lt;&lt; INTF1);
  attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);

  request( CHILD_ID_RAIN, V_TEXT); // readback count
  wait(4000);
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    request( CHILD_ID_RAIN, V_TEXT); // readback count
    wait(4000);
  }
  if (ValidWaterCount == 0 ) { // of did not receive valid count
    Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
  }

  // ReadEEprom();


  wdt_disable(); // Might be redundant as the bootloader should have done this already
  Serial.print("Rain &amp; Soil Sensor RES 1.1.1");

  // use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
  analogReference(INTERNAL1V1);
#else
  analogReference(INTERNAL);
#endif

  // ReadEEprom();

  wdt_enable(WDTO_8S);
}//end setup

void presentation() {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Soil Moisture_R", "1.1.1");


  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID_S_MOISTURE, S_MOISTURE, "Soil Moisture", false);
  wait(250);
  present(CHILD_ID_RX_RSSI, S_SOUND, "Soil &amp; Rain Transmitter RX RSSI", true);
  wait(250);
  present(CHILD_ID_BATVCC, S_MULTIMETER, "Battery V", false);
  wait(250);
  present(CHILD_ID_RAINREPORT, S_RAIN, "Rain", true);
  wait(250);
  present(CHILD_ID_RAIN, S_INFO, "TxTCount", true);

}//end presentation




void loop() { // put your main code here, to run repeatedly:
  wdt_reset();
  getSoil();
  //unsigned long currentMillis = millis();
  // use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
  analogReference(INTERNAL1V1);
#else
  analogReference(INTERNAL);
#endif

  for (int i = 0; i &lt;= 10; i++) {
    analogRead(BATTERY_SENSE_PIN);
    wait(5);
  }


  // get the battery Voltage
  int sensorValue = analogRead(BATTERY_SENSE_PIN);// * ((1e6 + 470e3) / 470e3);
#ifdef MY_DEBUG
  Serial.print("sensorValue raw ");
  Serial.println(analogRead(BATTERY_SENSE_PIN));
  Serial.print("sensorValue V ");
  Serial.println(sensorValue);
#endif
  wdt_reset();
  // 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+360e3)/360e3)*1.1 = Vmax = 4.15 Volts
  // 3.44/1023 = Volts per bit = 0.004062127


  //long batteryVt  = map(sensorValue, 0 , 1023, 0, 43000); // get the target positionsensorValue * 0.003363075;
  float batteryV  = (sensorValue * (4.08 / 3.88)) * 0.004062127; // batteryVt/10000;
  int batteryPcnt = ((batteryV - VCC_MIN) / (VCC_MAX - VCC_MIN)) * 100;// sensorValue / 10;

  send(msgSoil.set(ScaledMoisture, 0)); // send moisture
  wait(100);

  wdt_reset();

  //float volts = vcc.Read_Volts();
  send(msgVcc.set(batteryV, 1));

  //#ifdef MY_DEBUG

  Serial.print("Soil Moisture : ");
  Serial.print(ScaledMoisture);
  Serial.println(" cb");

  Serial.print("Battery Voltage count: ");
  Serial.print(sensorValue);
  Serial.println(" int");

  Serial.print("Battery Voltage: ");
  Serial.print(batteryV);
  Serial.println(" V");

  Serial.print("Battery percent: ");
  Serial.print(batteryPcnt);
  Serial.println(" %");
  //#endif
  wdt_reset();

  if (oldBatteryPcnt != batteryPcnt) {
    //  sendBatteryReport();
    sendBatteryLevel(batteryPcnt);
    oldBatteryPcnt = batteryPcnt;
  }

  RX_SEND();

  if (batteryPcnt &lt; 35) {
    //send(msgText.set("Sleep*10"), false);
    Serial.println("Sleep*10");
    wdt_reset();
    //sleep(MYsleepTime*5); // sleep(MYsleepTime);
    RainInterrupt = 0;
    sleep(RainPin, FALLING, MYsleepTime * 5);

    Slept = 1;
    wdt_reset();
    //requestTime();// get time

  }
  else if (batteryPcnt&lt;75 and batteryPcnt&gt;35) {
    //send(msgText.set("Sleep*3"), false);
    Serial.println("Sleep");
    wdt_reset();
    RainInterrupt = 0;
    //sleep(MYsleepTime*3); // sleep(MYsleepTime);
    sleep(RainPin, FALLING, MYsleepTime * 3);
    Slept = 1;
    wdt_reset();
    //requestTime();// get time
  }
  else {
    Serial.println("Sleep :");
    wdt_reset();
    RainInterrupt = 0;
    //sleep(MYsleepTime); // sleep(MYsleepTime)
    sleep(RainPin, FALLING, MYsleepTime);
    Slept = 1;
    wdt_reset();
  }
  wait(100);// need to wait otherwisee the debounce won't work




}// end loop



void receive(const MyMessage &amp;message) {
  // We only expect one type of message from controller. But we better check anyway.
  wdt_reset();
  if (message.isAck()) {
#ifdef MY_DEBUG
    Serial.println("+Ack FMGW");
#endif
  }

#ifdef MY_DEBUG
  Serial.print("*InMsgty :");
  Serial.print(message.type);
  Serial.print(" MsgComd:");
  Serial.print(message.getCommand());
  Serial.print(" childID:");
  Serial.print(message.sensor);

  Serial.print(" Switch:");
  Serial.println(message.getFloat());
#endif


  if (message.type == V_STATUS || S_HEATER || V_LIGHT || V_TEXT || V_HVAC_SETPOINT_HEAT || V_PERCENTAGE || S_DIMMER) {


    if (message.getCommand() == 2) { // THIS PROCESSES THE CONTROLLERS EXPECTED STATE OF THE OUTPUT
      // put code here to be executed when the message is from a request
#ifdef MY_DEBUG
      Serial.print("REQ_Msg :");
      Serial.print(message.type);
      Serial.print(" MsgCmd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);
      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif

      switch (message.sensor) {// the child ID

        case 11:

          Watermmtot = message.getFloat();
          //#ifdef MY_DEBUG
          Serial.print(" Incoming Rain mm:");
          Serial.println(Watermmtot);
          //#endif
          if (Watermmtot &gt;= 0.3) {
            EEPROMWritelong(WatermmADD, Watermmtot);
          }
          else {
            Watermmtot = EEPROMReadlong(WatermmADD); // long eeprom read
            ValidWaterCount = 1;
          }
          break;

      } // end switch




    }// end msg=2

    if (message.getCommand() == 1) { // THIS PROCESSES DIRECTED COMMANDS


#ifdef MY_DEBUG
      Serial.print("*InMsgty :");
      Serial.print(message.type);
      Serial.print(" MsgComd:");
      Serial.print(message.getCommand());
      Serial.print(" childID:");
      Serial.print(message.sensor);

      Serial.print(" Switch:");
      Serial.println(message.getBool());
#endif
      /*
            switch (message.sensor) {// the child ID

              case 2:
                TempRELAY = message.getBool();
                //#ifdef MY_DEBUG
                Serial.print(" Incoming rELAY:");
                Serial.println(TempRELAY);
                //#endif

                watering = TempRELAY;

                send(msgRelay.set(watering, 0)); // send relay state


                break;

            } // end switch

      */


    }// end if msg = 1


  }// end msg type function

}// end void loop



void RX_SEND()
{
  wdt_reset();
  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
  wdt_reset();
}


void sendBatteryReport() {
  wdt_reset();

  float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
  int batteryPcnt = static_cast&lt;int&gt;(p);
#ifdef MY_DEBUG
  Serial.print("Battery is: "); Serial.println(batteryPcnt);
#endif
  sendBatteryLevel(batteryPcnt);
}



void ReadEEprom() {
  wdt_reset();
  //if (EEPROMReadlong(SetpointADD) &gt; 0) SoilSetPoint = EEPROMReadlong(SetpointADD) ;
  //if (EEPROMReadlong(WaterTimeADD) &gt; 0) WaterTime = EEPROMReadlong(WaterTimeADD) ;

  if (loadState(SetpointADD) &gt; 0) SoilSetPoint = loadState(SetpointADD) ;
  if (loadState(WaterTimeADD) &gt; 0) WaterTime = loadState(WaterTimeADD) ;

}



void getSoil() {
  wdt_reset();

  analogReference(DEFAULT);
  for (int i = 0; i &lt;= 10; i++) {
    RawSoil = analogRead(Soil_ip_pin);
    wait(5);
  }

  int soilCount = 0;
  unsigned long soilAccum = 0;
  digitalWrite(SoilPowerPin, HIGH); // Power up sensor
  wait(1000);

  RawSoil = analogRead(Soil_ip_pin);
  soilAccum = RawSoil;
  while (soilCount &lt; 50) {
    wait(20);
    RawSoil = analogRead(Soil_ip_pin);
    if (RawSoil &gt; 0) {
      soilAccum = soilAccum + RawSoil;
    }
    soilCount++;
  }
  Serial.print("SCount ");
  Serial.println(soilCount);
  RawSoil = soilAccum / soilCount;
  Serial.print("RawSoil ");
  Serial.println(RawSoil);

  wait(1);
  ScaledMoisture = map(RawSoil, 600 , 0, 0, 100); // get the target position
  digitalWrite(SoilPowerPin, LOW); // Power down sensor

  Serial.print("Scaled Moisture CB ");
  Serial.println(ScaledMoisture);

}

void RainINT() {
  unsigned long thisTipTime = millis();
  Serial.println("int");
  if (thisTipTime - lastTipTime &gt; 20UL) {// debounce 100ms
    Watermmtot = Watermmtot + bucketSize;
    fullCounter = fullCounter + bucketSize;//Count so we send the counter for every 1mm
    Serial.println(Watermmtot);
    RainInterrupt = 1;
    lastTipTime = thisTipTime;
  }
  wait(21);// need to wait otherwisee the debounce won't work

  if (RainInterrupt == 1) {// of woken due to rain bucket actions

    Serial.print("Total Water = ");
    Serial.print(Watermmtot);
    Serial.println(" mm");

    if (fullCounter &gt;= 1) {
      resend(lastCounterMsg.set(Watermmtot, 1) , true, 5);
      if (resend(msgRain.set(Watermmtot, 1) , true, 5)) { // only reset if sending succeeded
        resend(msgRainRate.set(100) , true, 5);
        Serial.print("Total Water Transmitted = ");
        Serial.print(Watermmtot);
        Serial.println(" mm");
        fullCounter = fullCounter - 1;
        RainInterrupt = 0;
        EEPROMWritelong(WatermmADD, Watermmtot);
      }
    }
  }


}


bool resend(MyMessage &amp; msg, bool ack, int repeats)
{
  wdt_reset();
  int repeat = 1;
  int repeatdelay = 0;
  boolean sendOK = false;

  while ((sendOK == false) and (repeat &lt; repeats)) {
    if (send(msg, ack)) {
      sendOK = true;
    } else {
      sendOK = false;
      Serial.print("TX Error ");
      Serial.println(repeat);
      repeatdelay += 200;
      if (repeatdelay &gt;= 500) {
        repeatdelay = 500;
      }
      wdt_reset();
    } repeat++; wait(repeatdelay);
  }
  return sendOK;
}
</code></pre>
]]></description><link>https://forum.mysensors.org/post/110657</link><guid isPermaLink="true">https://forum.mysensors.org/post/110657</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Wed, 28 Jul 2021 11:00:57 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 10:47:52 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn post your full sketch please. You should not attach your own interrupt handler and let mysensors handle it instead.</p>
]]></description><link>https://forum.mysensors.org/post/110656</link><guid isPermaLink="true">https://forum.mysensors.org/post/110656</guid><dc:creator><![CDATA[Yveaux]]></dc:creator><pubDate>Wed, 28 Jul 2021 10:47:52 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 10:18:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a><br />
Yes, that is exactly what I am doing, however, as I hopefully explained, AFTER the interrupt, the node returns to sleep and does not action the rest of the main loop.</p>
<p dir="auto">I am Calling</p>
<pre><code>sleep(RainPin, FALLING, MYsleepTime*3); 
</code></pre>
<p dir="auto">having already defined the pin and interrupt handler etc.</p>
<pre><code>  pinMode(RainPin, INPUT_PULLUP);
    EIFR = (1&lt;&lt;INTF0) | (1&lt;&lt;INTF1);// prevent initial trigger, clear interrupt
    wait(100);
    EIFR = (1&lt;&lt;INTF0) | (1&lt;&lt;INTF1);
  attachInterrupt(digitalPinToInterrupt(RainPin), RainINT, FALLING);
</code></pre>
<p dir="auto">all works perfectly, in that the interrupt executes.<br />
What I am asking is . Is there a way of stopping the sleep from continuing for the rest of the time defined by MYsleepTime? ( actually MYsleepTime = 3600000)<br />
I can, and am for the moment, performing the calculations, and sending data to the controller in the interrupt, but that is very poor programming in principal. What I wish to do is simply set a flag, and then have the main loop execute, where I can decide what to do, and then return to sleep, after I have done all I wish.</p>
<p dir="auto">Many thanks<br />
Nigel</p>
]]></description><link>https://forum.mysensors.org/post/110655</link><guid isPermaLink="true">https://forum.mysensors.org/post/110655</guid><dc:creator><![CDATA[Nigel31]]></dc:creator><pubDate>Wed, 28 Jul 2021 10:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to Is there a &quot;standard&quot; way to terminate a sleep time, after waking by an interrupt? on Wed, 28 Jul 2021 10:01:54 GMT]]></title><description><![CDATA[<p dir="auto">@Njwyborn can't you use the MySensors sleep to waker from interrupt?</p>
]]></description><link>https://forum.mysensors.org/post/110654</link><guid isPermaLink="true">https://forum.mysensors.org/post/110654</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Wed, 28 Jul 2021 10:01:54 GMT</pubDate></item></channel></rss>