Controlling the relay via blynk with nRF24l01

Нужна ваша помощь, есть node mcu v3 управляю через приложение блинк, вопрос как прикрутить к своему скетчу управление и по nrf 24l01 для управления реле. спасибо


I need your help, there is node mcu v3 I manage through the application blink, the question is how to tie to my sketch control and on nrf 24l01 to control the relay.

Isso funciona pra mim.

#include <SPI.h>
#define BLYNK_PRINT Serial         
#define USE_SERIAL Serial          

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
//#include <ESP8266HTTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
//#include <BlynkSimpleEsp8266_SSL.h> // 8441 is SSL port and 8442 is TCP port
BlynkTimer timer;
//#define BLYNK_DEFAULT_FINGERPRINT "xx xx xx xx xx xx xx xx" // ensure no invisible characters in the fingerprint


#include <RF24Network.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <string.h> 
#include <Hash.h>   
RF24 radio(4, 5);    // Set up nRF24L01 radio on SPI bus plus pins 4 for CE and 15 for CSN

float h, t, f ;

int ti=0;

int pausa_receb_dados;
int pausa_APIget;
  
char ssid[]     = "xxxxxx";
char pass[]     = "xxxxxxx";
char server[]   = "xxxxxxxxxx";
char auth[]     =  "xxxxxxxxxx";

void setup(){

  ArduinoOTA.setPassword((const char *)"123");
  ArduinoOTA.begin();


  USE_SERIAL.setDebugOutput(true);  
  Serial.begin(115200);
 
  //Blynk.begin(auth, ssid, pass, server, 8441, BLYNK_DEFAULT_FINGERPRINT);
  //Blynk.begin(auth,wifi,ssid, pass,8442 );
  //Blynk.config(192.168.7.2,8442 );
  //Blynk.begin (auth, "xxxxxxxxxx",8441);
  //Blynk.begin(auth, wifi, ssid, pass,"xxxxxxxxxxxx");
  //Blynk.begin(auth, wifi,"xxxxxxxxxx","xxxxxxxxxxxx");
  
   
    Blynk.begin(auth, ssid, pass, IPAddress(xxx,xxx,xxx,xxx),8442);
    //Blynk.begin(auth, ssid, pass, server, 8441, BLYNK_DEFAULT_FINGERPRINT);

   
    radio.begin();                                                                         
    radio.setDataRate (RF24_250KBPS);    // (RF24_250KBPS, RF24_1MBPS, RF24_2MBPS), RF24_1MBPS - 1Мбит/сек
    radio.setPALevel(RF24_PA_LOW);   // (RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBm, RF24_PA_MAX=0dBm)
    radio.openReadingPipe (1, 0x1234567890LL);  // 0x1234567890 
    radio.startListening  ();

   pausa_receb_dados = timer.setInterval (2000L, recebe_tudo);
   //pausa_APIget = timer.setInterval (5000L, APIget);

}


BLYNK_WRITE(V15){
  
  String webhookdata = param.asStr();
  Serial.print("webhookdata: ");
  Serial.println(webhookdata);

  Serial.print("valores: ");
  Serial.println(f);

}

void recebe_tudo() {
  
 float data[3];   
 if(radio.available()){                                // Если в буфере имеются принятые данные
 radio.read(&data, sizeof(data));                  // Читаем данные в массив data и указываем сколько байт читать     
 h=data[0]; 
 t=data[1];
 f=data[2];     
  ti++;  
 Blynk.virtualWrite(V1, f);
   Serial.print("valores: ");
  Serial.println(f);
 
 }
}

void loop() {
    ArduinoOTA.handle();
    Blynk.run();
  //network.update();
    timer.run();
}

1 Like

Hi! Is that mean, that if some data enters the pipe, it will store somewhere into radio object? So we will be able to read this data after some time via BlynkTimer?
And another question: Buffer has unlimited size here? (I just want to understand what is the variable “ti” in this program and how does “radio” works when new data is entering it)
Is buffer clearing after we do
"radio.read(&data, sizeof(data));"
and why do we need to encrease ti in this case?
Thanks!

P.S. Maybe I shoud create a new topic with such questions?