nRF24/RF24

Can RF24 library be used with WiFi?

Tech500 opened this issue · 4 comments

Trying to send a Asyncwebserver request, variable to RF24 radio.write(&variable, sizeof(variable). Variable leaves RF24 sender; never shows up RF24 receiver. Sender code; I see "Gets here 1" and "Gets here 2" without seeing "!Transmit failed". Tried disabling WiFi; did not seem to help or I have WiFi disabling wrong.

Is there an example of RF24 being used with WiFi?

My application is for a low demand, videofeed camera battery; that needs to be switch on/off remotely, when a web request is received.

RF24 Sender loop code:

  WiFi.enableSTA(true);

  radio.stopListening();  //This sets the module as transmitter 

  //data = 1;  variable trying to send
  
  if(data == 1)
  { 
    WiFi.enableSTA(false);
    delay(1000);
    radio.write(&data, sizeof(data));  //Reading the data
    if(!radio.write(&data, sizeof(data))){
      Serial.println("!Transmit Failed\n");
    }
    Serial.println("Gets Here data = 1");
    Serial.println("\nnRF24L01 powered up");
    Serial.println("ESP32 waking from Deep Sleep");
    Serial.println("Your Battery Switch is ON\n");
    delay(10);       
  } 
  
  if(data == 2)
  {
    WiFi.enableSTA(false);
    delay(1000);
    radio.write(&data, sizeof(data));  //Reading the data
    Serial.println("Gets Here data = 2");
    Serial.println("\nBattery power switched OFF"); 
    Serial.println("nRF24L01 powered down");
    Serial.println("ESP32 going to Deep Sleep\n");
    delay(10);      
  }

RF24 Receiver loop code:

void loop() {

  if (radio.available())  //Looking for the data.
  {
    Serial.print("radio.available():  "); Serial.println(radio.available());
    delay(1000);    

    radio.read(&data, sizeof(data));  //Reading the data
    delay(10);
    if (data == 1) {
      radio.powerUp();
      Serial.println("nRF24L01 powered up");
      digitalWrite(relayPin, HIGH);
      Serial.println("Battery power switched ON");
      Serial.println("ESP32 wake from Deep Sleep\n\n");
      delay(10);
    }

    if (data == 2) {
      digitalWrite(relayPin, LOW);
      Serial.println("Battery power switched OFF");
      Serial.println("nRF24L01 powered down");
      Serial.println("ESP32 going to Deep Sleep\n\n");
      radio.powerDown();
      goToDeepSleep();
    }
  }
  delay(10);
}
2bndy5 commented

Is there an example of RF24 being used with WiFi?

See #936 (comment)

If you are trying to ask, "Can RF24 lib be used alongside WiFi lib?"
The answer is yes, but the WiFi radio will not talk with the nRF24L radio. Care should be taken when choosing what channel the nRF24L uses because WiFi radios do operate in the same spectrum of wireless frequencies.

TMRh20 commented

RF24 should have no impact on WiFi usage.

  if (radio.available())  //Looking for the data.
  {
    Serial.print("radio.available():  "); Serial.println(radio.available());
    delay(1000);    

    radio.read(&data, sizeof(data));  //Reading the data
    delay(10);
    if (data == 1) {
      radio.powerUp();
      Serial.println("nRF24L01 powered up");
      digitalWrite(relayPin, HIGH);
      Serial.println("Battery power switched ON");
      Serial.println("ESP32 wake from Deep Sleep\n\n");
      delay(10);
    }

Maybe I'm misunderstanding what it is you are doing, but you cannot receive data when the radio is powered down. You need the radio to be in active RX mode, and you can put the MCU to sleep, waking on an interrupt from the radio.

Soldered 100 uf 16 Volt Tantalum Capacitors to both nRF24L01+ transceivers.

Have a working Webserver with a nRF24L01 controlling a remote battery switch.

Prepared a under two minute video of processing web request for “Camera View.” Asyncwebserver request turns on switch by triggering a 60 second countdown timer and sends data = 1 to the first nRF24L01. Second nRF24L01 recevies data = 1; powers up the 2nd NRF24L0, turns on switch, wakes ESP32 from Deep Sleep (using External 0, RTC_GPIO wakeup pin). Process is reversed when 2nd nRF24L01 receives data = 2 from webserver's expired countdown timer.

nRF24L01 Webserver with Remote Switch

Thanks for your support.