Wake up NRF24 from sleeping



  • Hello Guys,

    how can i wake up the NRF24 from sleeping mode without sending a message?


  • Admin

    Pin Interrupt or timer.



  • Thats my sketch:

    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    
    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    unsigned long AWAKE_TIME = 20000; // Sleep time (in milliseconds)
    unsigned long SLEEP_TIME = 7000; // Sleep time (in milliseconds)
    
    void setup()  
    {   
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relay", "1.0");
      
      // Fetch relay status
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        gw.present(sensor, S_LIGHT);
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    
    void loop() 
    {
      // Alway process incoming messages whenever possible
      gw.process();
      Serial.print(" Awake for "); Serial.print(AWAKE_TIME); Serial.print(" ms");
      delay(AWAKE_TIME);
      Serial.print(" Sleeping for "); Serial.print(SLEEP_TIME); Serial.print(" ms");
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         gw.saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }``````
    

    In my eyes the NRF24 doesn't wake up, because i can't send messages to the node.

    It also just uses 3,8 mA, when it's awoken.


  • Admin

    Please read about the sleep function in the API on the main site.



  • I already did, but i can't find the mistake. 😞

    It's for an LED candle.

    Is the mistake in here?

    gw.sleep(SLEEP_TIME); //sleep a bit
    


  • This post is deleted!

  • Mod

    As hek says, read the API documentation.

    "Waiting using the Arduino delay() command is not a good idea. It halts all MySensors processing and should be avoided. Instead you should use the provided wait function which calls process() while waiting."

    Exchange delay with gw.wait and you should be fine


Log in to reply
 

Suggested Topics

  • 3
  • 3
  • 4
  • 2
  • 24
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts