NRF24 to blynk

After you get through some fixing, post it here if you still have issues… we don’t mind helping those that show effort :wink:

Make sure that the ‘param’ statement is inserted in a the BLYNK_WRITE() function exactly as shown… don’t try to add this function into another function or a loop, it is a standalone and gets called whenever V1 changes state.

You can add or change the resulting commands (currently digitalWrite() commands) but be sure to maintain the proper order of the opening and closing { }

Lol :laughing:
it’s amazing to have a car like that! I love space

Thanks alot! it helped me
can I use ‘param’ statement in other BLYNK_WRTE() functions? like V1, V2, V3 etc. each result is different
sry I’m asking out of this topic but does blynk_timer function do something like delay? I’ve found in topics to NOT using delay() in sketch.

The difference is that bkynk_timer is non-blocking, which means that other functions can continue to run between timer cycles.
When you throw a delay()in to your code nothing else can run during that delay period, which will cause the Blynk connection to drop because the device isn’t keeping “heartbeat” communications going with the server.

Yes, one Blynk function per vPin is normal (but there are some cases where multiple vins can be merged - like in the case of Joystick or zeRGBa)… and the state or value of that Widget is transferred via the ‘param’

thank you so much, I got it
I have successfully connected my arduino to the blynk app that can send temp, humidity and soil humidity to blynk and I can control Relay from blynk app. now I have started connect arduino to NRF24 building master and slave which slave will do sending data and controlling relay and master is connected to the bynk to control slaves.
this is my master code:

#define BLYNK_PRINT Serial
#define BLYNK_NO_BUILTIN
#define BLYNK_NO_INFO
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

int Value;
int LED = 5;
int DataMgs[0];
RF24 radio(8, 9);
byte addresses[][6] = {"0"};


char auth[] = "XXXXXXXXXXXXXXXXX";

unsigned long lastRunTime = 0;
unsigned long currentTime = 0;
int h;
int t;
int s;


struct package
{
  int t ;
  int h ;
  int s ;
};
typedef struct package Package;
Package data;

void setup()
{
  Blynk.begin(auth);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  radio.begin();
 radio.setChannel(115); 
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, addresses[0]);
  radio.startListening();

}

void loop()
{
   Blynk.run();
   currentTime = millis();
     if ((currentTime - lastRunTime >= 5000) ){     //timer low-cost  
    lastRunTime = currentTime;
   if (!Blynk.connected()) {
    digitalWrite(LED, LOW);
   } else {
    digitalWrite(LED, HIGH);
   }
 if ( radio.available()) 
  {
    while (radio.available())
    {
      radio.read( &data, sizeof(data) );
     
    Blynk.virtualWrite(V5, data.h);  
    Blynk.virtualWrite(V6, data.t);
    Blynk.virtualWrite(V0, data.s);
    }
  }
}
}

  BLYNK_WRITE(V1) {
             radio.stopListening();

      radio.openWritingPipe(addresses[0]); 
      if (param.asInt() == 1) {
   DataMgs[0] = 1;
   radio.write(DataMgs, 1);
  } else { 
     DataMgs[0] = 1;
   radio.write(DataMgs, 0);
  }
}

and the slave:

#include <DHT.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

int relay = 4;
int DataMgs[0];

RF24 radio(8, 9);
byte addresses[][6] = {"0"};

unsigned long lastRunTime = 0;
unsigned long currentTime = 0;

struct package
{
int h;
int t;
int s;
};

typedef struct package Package;
Package data;


#define DHTPIN 7
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);


void readSensor()
{
  data.h = dht.readHumidity();
  data.t = dht.readTemperature();
  data.s = analogRead(A0);
}


void setup()
{
  dht.begin();
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  radio.begin();
  radio.setChannel(115); 
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(addresses[0]); 
 
 
}


void loop()
{

   if ((currentTime - lastRunTime >= 5000) ){     //timer low-cost  
    lastRunTime = currentTime;
    readSensor();
    radio.write(&data, sizeof(data));
    
}
  radio.startListening();
  if (radio.available())
   {
   bool done = false;
   while (!done)
  { 
   done = radio.read(DataMgs, 1);
    if (DataMgs[0] ==1)
    {
      digitalWrite(relay, HIGH);
    }  if (DataMgs[0] ==0)
    {
      digitalWrite(relay, LOW);
    }
}
   }
}

but I couldn’t receive any data and control relay! :expressionless:

Well that part is NOT Blynk related… you might be on your own there, at least in this Blynk forum.

maybe someone has done it before and could help me in this case; bcs I can send and receive data from two NRF’s but can’t share it to the blynk…

Try cleaning up your Blynk sketch… that void loop() is still messy… there is a good chance that you could lose Blynk connection while awaiting your RF data transfer.

Checkout those links and Help Center documents I mentioned earlier… the key is to keep the main loop clear and use timers to periodically poll sensor input and App output as required, not in a loop that can run hundreds of times a second.

Being very dependent on reading the RF network in a while loop, using NRF chips is at best unreliable in my opinion. I suggest using Wemos or similar chips. They cost almost the same and are much more stable. I haven’t used the NRF’s in a long time and probably never will again. They also interfere with the Wifi networks seeings as they are also on the 2.4 Ghz band.

No, just forget and it and use regular Wifi ESP-like chips, that would be my advice. Especially with Blynk. The combination with Blynk and NRF makes a bad headache.

If you use the NRF standalone or with and Arduino (without Blynk) it’s all find and dandy (I got some simple node0 node1 information exchange sketches if you really want to try).

thank you for reply
my project is about irrigation system iot , then I’m not able to connect all the stations to the wifi bcs they are far away…
bcs of that I’m gonna use NRFs to build a mesh network and a gateway which is near the router to connect internet via wifi or ethernet. any other suggestion to build a fixed network? have you ever tried ‘mysensors’ library? I think it’s more stable.
and I will be grateful if you share node0 node1 sketch with me.
thanks.

Just make a simple WiFi mesh network. In the past I used a product called openmesh to create a large WiFi network through a 1km long, and wooded, RV park. Nice thing about it is at it was dirt simple to then just pass any other networked signal across it, In my case IP cameras as well and WiFi hotspots.

No need for mixing wireless standards.

can I do it with esp8266?
I think I have to buy lots of that bcs I’m doing in 10km area.

Probably… haven’t looked into it, but they would NOT be running Blynk, but only acting as the mesh nodes for other independent clients (i.e. Blynk based MCUs).

The hardware I was referring to used higher gain antennas then a simple ESP, with options for external ones for much langer ranges between nodes.

Do you need hotspot coverage throughout the 10k, or just from one end to the other? You can easily use directional (yagi or dish) antennas to push a single long range link. Then run your Blynk based ESPs at either end

thats a good product but it’s not in my country and due to some law I can’t buy from amazon;
anyway, it’s a hotspot coverage for 20 nodes.
why blynk couldn’t run with this?

That’s not what Blynk is designed for… it will connect OVER a mesh (by connecting to mesh node hotspots), but it is not designed to be PART of a mesh (unless the developers are holding out on us :stuck_out_tongue_winking_eye: ). Even if you could hack the two different internal programs together, it would severely compromise the function of both and be completely unnecessary.

Ýou would also need a lot of NRF’s…

1 Like

Well the software can reportedly run on 3rd party hardware… look into other mesh options as well.

but nrfs have more range which I have is about 900m
could u please send me a link or something to find out how to have nrf information exchange between 2 nodes?