MySensor collides with LowPower's SLEEP_ enum



  • I am trying to PowerDown my node and I want the nRF24L01+ to wake up my Arduino when data comes in (INTR goes LOW).
    As I could not find any way to use a MySensors function to sleep on the Arduino, I wanted to use LowPower lib's functionality for this.

    MyHwATMega328.h:82:6: error: multiple definition of 'enum period_t'
    LowPower.h:4:6: error: previous definition here
    

    Both of your header files contain the exact same enum:

    enum period_t
    {
    	SLEEP_15Ms,
    	SLEEP_30MS,
    	SLEEP_60MS,
    	SLEEP_120MS,
    	SLEEP_250MS,
    	SLEEP_500MS,
    	SLEEP_1S,
    	SLEEP_2S,
    	SLEEP_4S,
    	SLEEP_8S,
    	SLEEP_FOREVER
    };
    

    My simple code is:

    	attachInterrupt(digitalPinToInterrupt(2), interrupt, LOW);
    	LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
    	detachInterrupt(digitalPinToInterrupt(2));
    
    	gw.process();
    

    This opens up two questions for me:

    • Is there a MySensors function to PowerDown the node without powering down the radio?
    • Is there a way to force to use the LowPower enum. Tried it with (LowPower::period_t)SLEEP_FOREVER cast but it was not accepted as namespace.

    Thanks in advance


  • Contest Winner

    @SiLeX

    have you checked out the API?



  • @BulldogLowell Of course.

    sleep() including all overloads always put the Arduino and the radio to sleep, which is not desired. I only want to sleep the Arduino and have it wake up when INTR goes LOW.


  • Hero Member

    Adding my two cents, if you keep radio always on and only sleep arduino, at the end of day you didn't save too much, as the radio is usually the most power consuming in the equation...

    If you plan to run on batteries definitely sleep radio if you want to extend runtime. You might wake up both arduino+radio from time to time and use gw.request() to retrieve the latest status of anything you might need.



  • @rvendrame said:

    Adding my two cents, if you keep radio always on and only sleep arduino, at the end of day you didn't save too much, as the radio is usually the most power consuming in the equation...

    Thanks for you answer. I am receiving IR commands over MySensors and need to react on them (with IRLib) in realtime. This is a big, 5V Arduino Uno. Interestingly it saves a lot of power if I PowerDown the Arduino. I did this with the RF24Network library in the past and it saved a lot.

    Maybe the temporary way could be waking up and requesting every 2 seconds or so. But I would really like to use the LowPower lib again.



  • I do not know if this is related, but I get the same error - "error: multiple definition of 'enum period_t'" when I try to compile the LowPower and MySensor library.

    I have not yet been able to get a sensor going using the sleep mode. Is this a known problem? Is there a fix to this problem?

    Br
    Lemme



  • Hm.. How much Power actually Safe this? Numbers would bei interesting.
    My 2cents: afaik the low Power lib is included in the mysensors lib. This results in the Double decleration of the enum. Try to Use the already included low Power lib.



  • Arhh - that explains it, thanks. I will try to play with it when I come home.
    Wondering if it is still limited to 8 seconds. Or if I have to do some sort of loop/counting to make it sleep for several minutes or more.



  • @Lemme said:

    Wondering if it is still limited to 8 seconds. Or if I have to do some sort of loop/counting to make it sleep for several minutes or more

    If you need longer intervals, you should use SLEEP_FOREVER and attach a Timer interrupt beforehand. Pseudocode would look like this:

    loop(){
    ...
    attachInterrupt(Timer1, 600000, dummy_function) // wake up every 10 minutes
    gw.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF)
    detachInterrupt(Timer1) // disable so we don't interrupt ourselves
    
    .... do things, send data, and so on ......
    
    }
    
    void dummy_function(){
    // this does nothing, but interrupt need something to call, so we make a dummy function
    // this will return immediately to the loop() again
    }
    

    This is best-practise for things that are not real-time-based (like encoder wheels). Using the normal loop makes it possible to use all the millis() and other time-based functions you wouldn't be able to use withing interrupt calls.

    By the way - in YOUR case, when you don't want to receive anything on the sensor node while sleeping, using the MySensors Sleep function is perfectly fine. This thread focuses on using it with other interrupts than Timers.



  • Just what I need - many thanks!


 

280
Online

8.8k
Users

9.6k
Topics

100.3k
Posts