wireless sensor using nRF24l001 + ethernet shield

my project is about wireless sensor-based, I m using 3 nano Arduino and 1 uno Arduino board. considering node1, node 2, node 3 and base node, below I mentioned all the details.

node 1- nano arduino+nrf24l001+PIR motion sensor

node 2-nano arduino+nrf24l001+ultrasonic sensor

node3 -nano arduino+nrf24l001+flame sensor

base node -uno arduino+nrf24l001+lcd display+ ethernet shield

I succeeded in sending and receiving text messages through nrf24l001 wireless communication through pipes ., the problem I faced is how to display it through ethernet shield to HTML, below mentioned link is the code details for the base node and transmitter node.

https://drive.google.com/open?id=1qWMLheqx-Ks_I2Hz0Ee3OhYn1OIqMKfx

error is

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Ethernet.h>
#include <RF24_config.h>


LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

RF24 radio(7, 8); // CE, CSN

char Data1 = "";
char Data2[32] = "";
char Data3[32] = "";
char Data4[32] = "";


const uint64_t pipes[4] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL, 0xF0F0F0F0E4LL };

//int LEDpir = 4;    // green
//int LEDultra = 2;  // red
//int BUZfire = A0; // Fire

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x85, 0xD9 };   //physical mac address
byte ip[] = { 192, 168, 137, 177 };                   // ip in lan
byte subnet[] = { 255, 255, 255, 0 };              //subnet mask
byte gateway[] = { 192, 168, 137, 1 };              // default gateway
EthernetServer server(80);                       //server port


void setup() 
{
  lcd.begin(16, 2); 
  Serial.begin(9600);
  digitalWrite(10,HIGH);
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, pipes[1]);
  radio.openReadingPipe(2, pipes[2]);
  radio.openReadingPipe(3, pipes[3]);
  radio.startListening();
  Ethernet.begin(mac,ip,gateway,subnet);     // initialize Ethernet device
  server.begin();                                // start to listen for clients

  }

void loop() 
{
  if (radio.available()) 
  {
   
    char text1[32] = "";
    radio.read(&text1, sizeof(text1));
    
        Serial.println(text1); 
        Data1=text1;        
}

   {
   EthernetClient client = server.available();    // look for the client

// send a standard http response header

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();

/* 
This portion is the webpage which will be
sent to client web browser one can use html , javascript
and another web markup language to make particular layout 
*/

client.println("<!DOCTYPE html>");      //web page is made using html
client.println("<html>");
client.println("<head>");
client.println("<title>Ethernet Tutorial</title>");
client.println("<meta http-equiv=\"refresh\" content=\"3\">");

/*
The above line is used to refresh the page in every 1 second
This will be sent to the browser as the following HTML code:
<meta http-equiv="refresh" content="1">
content = 1 sec i.e assign time for refresh 
*/

client.println("</head>");
client.println("<body>");
client.println("<h1>Sensor network</h1>");
client.println("<h2>Monitoring</h2>");
client.println("<body bgcolor=#354166 text=white>"); client.println("</body>");
client.println("<table border=1 cellpadding=10 bgcolor=blue>");
client.println("<tr><th>Node Number</th><th>---------Status----------</th></tr>");

     client.println("<tr><th>");
          client.println(1);
          client.println("</th><th>");
          client.println(Data1);
          client.println("</th></tr>");
          client.println("<tr><th>");
          client.println(2);
          client.println("</th><th>");
          client.println(Data2);
          client.println("</th></tr>");
          client.println("<tr><th>");
          client.println(3);
          client.println("</th><th>");
          client.println(Data3);
          client.println("</th></tr>");
         
         
          client.println("</table>");
          client.println("</body>");
          client.println("
");
          
          client.println("</html>");

    delay(1);         // giving time to receive the data

/*
The following line is important because it will stop the client
and look for the new connection in the next iteration i.e
EthernetClient client = server.available();
*/
client.stop();
  
   }     }

Thank you
Ranjith

Please post the error message here.

...R

sorry, it's not an error. I'm not getting the text msg at the HTML status bar, but I received it at the serial monitor through nrf24l01. Click below link for details

https://drive.google.com/open?id=13jAkb03uJ09mc7LtDs7SB8Qfi2fHyqYE

Can’t you just post the text or whatever it is here?

If it is am image see this Simple Image Posting Guide

Assuming your base node can correctly receive the data from the other nodes then the problem has nothing to do with the nRF24s and I suggest that you just write a simple test / learning program to send some typical (but static) data via the Ethernet shield.

By the way I know a bit about nRF24s but I have no experience with an Ethernet shield.

…R

@robin2 thank you so much for guiding me, I succeeded in displaying the data at webserver through ethernet shield, the thing is data displayed rollout continues and it’s random at webserver. have any solution for this??

I have attached the details.

thank you

garbage_trail.ino (3.41 KB)

itsnaga015:
I have attached the details

Please make your image visible in your Post - I gave you the link to the simple instructions.

Please also post your program code in your Post so we don’t have to download it. Many readers use tablets and cannot download files. Also please use the code button </> when posting the code.

…R

above showed is the displayed output at webserver, sensor data which is sent by node1,node2,node3 to the master via nrf24l001 and displayed to web server through ethernet shield.

The output which I get in webserver scrolls out continuously(it is not stable in assigned place ) when sensors detect. Is there any solutions to display at a particular row and column.

below I mention code for master node

Thank you
Ranjith

#include <SPI.h>// Add  'SPI' library
#include <Ethernet.h>// Add 'Ethernet' library
#include <nRF24L01.h>
#include <RF24.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x85, 0xD9 };   //physical mac address
byte ip[] = { 192, 168, 1, 175 };                   // ip in lan
byte subnet[] = { 255, 255, 255, 0 };              //subnet mask
byte gateway[] = { 192, 168, 1, 176 }; 
                           
EthernetServer server(80);       
int led=2;
char text1[32] = "";
char text2[32] = "";
char text3[32] = "";

RF24 radio(7, 8);
const uint64_t pipes[4] = {0xF0F0F0F0E1LL,0xF0F0F0F0E2LL,0xF0F0F0F0E3LL,0xF0F0F0F0E4LL};


void setup() {
  radio.begin();
 radio.setDataRate(RF24_250KBPS);
 //radio.setPALevel(RF24_PA_MAX);
  radio.openReadingPipe(1,pipes[1]);
  radio.openReadingPipe(2,pipes[2]);
  radio.openReadingPipe(3,pipes[3]);
  radio.startListening();
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);// Initialize Serial communication at 9600 baudrate
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  //Serial.print("server is at ");// Displays 'server is at'
  //Serial.println(Ethernet.localIP());// Displays server IP address 
 pinMode(led,OUTPUT);

  }


void loop()
  {
 if (radio.available())
 //PIR TEXT
 {
    radio.read(&text1, sizeof(text1));
  
    delay(500);
    Serial.println(text1);  
  }
  //ULTRA TEXT 
  {
    radio.read(&text2, sizeof(text2));
   
    delay(500);
    Serial.println(text2);
    
  } 
   //FLAME TEXT 
  {
    
    radio.read(&text3, sizeof(text3));
   
    delay(500);
    Serial.println(text3);
    
  } 
  EthernetClient client = server.available();//Assign incoming client to 'client'
if (client) 
{ 
Serial.println("Web Client connected ");
String request = client.readStringUntil('\r'); 
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println("Refresh:1");
client.println();
client.println("<!DOCTYPE html><html>");  

client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");

client.println("<style>body { text-align: center; font-family: \"Arial\", Arial;}");
client.println("table { border-collapse: collapse; width:40%; margin-left:auto; margin-right:auto;border-spacing: 2px;background-color: white;border: 4px solid green; }");
client.println("th { padding: 20px; background-color:blue ; color: white; }");
client.println("tr { border: 3px solid blue; padding: 1px; }");
client.println("tr:hover { background-color:yellow; }");
client.println("td { border:2px; padding: 8px; }");
client.println(".text { color:blue; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");


client.println("</style></head><body><h1> WIRELESS SENSOR NETWORK </h1>");

client.println("<table><tr><th>NODE</th><th>STATUS</th></tr>");
client.println("<tr><td>1</td><td><span class=\"text\">");
client.println(text1);
//client.println(" *C</span></td></tr>"); 
client.println("<tr><td>2</td><td><span class=\"text\">");
client.println(text2);
//client.println(" *F</span></td></tr>"); 
client.println("<tr><td>3</td><td><span class=\"text\">");
client.println(text3);
//client.println(" %</span></td></tr>"); 
client.println("</body></html>"); 
client.stop();
client.println();
  } 
  }

As there seems to be no code in your program to set the content of the variable text1 to "No object found at (node2)" I can only assume that that message is what is being received by the nRF24

What are your Serial.print() statements showing?

...R

yeah, the Serial monitor (master) displays the text what I transmitted at node 1, node2, node3 via nrf24l001.

This is the output obtained at the serial monitor.

in webserver, the output displays but not in a particular column or row.
like

node1- motion detected at node1 or No motion
node2- Object detected at node2 or No Object
node3-Fire detected at node3 or no Fire

I Assigned it correctly, but don't know what went wrong. Any solution ??

itsnaga015:
in webserver, the output displays but not in a particular column or row.
like

I'm confused. if the program is correctly receiving the data from the slaves I don't understand what problem you have.

And, for the future, please don't post pictures of text. Just copy and paste the text - it is much easier to read.

...R

@robin2 : i m new and learner :slight_smile: ,i have problem in webserver, the output displays but not in a particular column or row.

As i mentioned earlier
In webserver it should print in particular row and column

Node STATUS

1- motion detected at node1/No motion

2- Object detected at node2 / No Object

3- Fire detected at node3 / no Fire

I Assigned it correctly, or what went wrong . Any solution ??

itsnaga015:
In webserver it should print in particular row and column

This sounds like a web programming problem rather than an Arduino problem. There are thousands of web pages with tutorials about web programming. I find w3schools very useful.

Can you post an example of how you want the output to appear.

...R

Example like above, and status as per i get output in Arduino below i mentioned the details.

Node STATUS

1- motion detected at node1/No motion

2- Object detected at node2 / No Object

3- Fire detected at node3 / no Fire

itsnaga015:
Example like above, and status as per i get output in Arduino below i mentioned the details.

Node STATUS

1- motion detected at node1/No motion

2- Object detected at node2 / No Object

3- Fire detected at node3 / no Fire

If the things are just in the wrong order all you need to do is change the order in which the variables text1, text2 and text3 are displayed.

...R

@robin2, hope you understood ?? or still, u didn't get what I facing. I wrote coding to display text it in webserver the thing is I get a random output like

Actually it as to display like this

Node STATUS

1- motion detected at node1/No motion

2- Object detected at node2 / No Object

3- Fire detected at node3 / no Fire

it displays randomly

Node STATUS

1- NO motion detected at node1

2- Object detected at node2 / No Object

3- motion detected at node 1

random repeats,etc....

Node STATUS

1- No object at node 2

2- Object detected at node2

3- No object at node2

itsnaga015:
@robin2, hope you understood ?? or still, u didn't get what I facing. I wrote coding to display text it in webserver the thing is I get a random output like

That suggests to me that your code to receive the data from the slaves is not correctly associating the received messages with the slave that sends the message - sometime the message from slaveA goes into boxB and on another occasion into boxC etc.

I don't use pipes myself - I just include an ID in the message that identifies the sender - so I'm a bit hazy about how they should be used.

I think you need code like this (from the TMRh20 documentation)

if(radio.available(&pipeNum)){
  radio.read(&data,sizeof(data));
  Serial.print("Got data on pipe");
  Serial.println(pipeNum);
}

In your case you should iterate through all 3 of your pipe numbers checking if there is data available. That way when you read a message you will know which pipe it arrived on and which slave sent it.

...R

@robin 2, thank you so much I succeded in displaying my sensor data in the webserver at a particular row and column.
now I want to use authentication, like login using username and password, logout button at webserver.
can u please guide me.

itsnaga015:
now I want to use authentication, like login using username and password, logout button at webserver.
can u please guide me.

I would have to learn all that myself in order to guide you.

This is a very common part of web programming. There will be hundreds of online tutorials and the basics will be identical whether the server runs on a PC or on an Arduino.

...R