Hi everyone,
I was working with 2 NRF24L01+PA+LNA (s) perfectly, Transmitter / Reciever.
Then I tried to send some data to Php Web Server with UIPEthernet.h Library, It was also OK.
But when I try to combine NRF24L01+PA+LNA Reciever with Web Client.. It looks like confused..
I powered off the transmitter but The reciever always passes from radio.available() function
pls help me!
my code :
#include <UIPEthernet.h> // Used for Ethernet
#include <RF24.h>
#define NUM_OF_CLIENTS 3
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
struct {
int temp, hum, air;
char sensorId;
int measurementId;
}
dataReceived;
int lastMeasurements[NUM_OF_CLIENTS];
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
EthernetClient client;
char server[] = "192.168.0.31"; // IP Adres (or name) of server to dump data to
void setup() {
Serial.begin(9600);
delay(2000);
radio.begin();
Ethernet.begin(mac);
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();
for (int i = 0; i < NUM_OF_CLIENTS; i++)
{
lastMeasurements[i] = 0;
}
}
void loop() {
if (radio.available())
{
radio.read(&dataReceived, sizeof(dataReceived));
Serial.println("Data Recieved....");
if (lastMeasurements[((int)dataReceived.sensorId) - 1] != (int)dataReceived.measurementId)
{
lastMeasurements[((int)dataReceived.sensorId) - 1] = (int)dataReceived.measurementId;
// Print some information
Serial.print("SENSOR ID: ");
Serial.println((int)dataReceived.sensorId);
Serial.print("Measurement Id: ");
Serial.println((int)dataReceived.measurementId);
Serial.print("Temperature: ");
Serial.println(dataReceived.temp);
Serial.print("Humidity: ");
Serial.println(dataReceived.hum);
Serial.print("Air Quality: ");
Serial.println(dataReceived.air);
Serial.println();
if (client.connect(server, 80)) {
Serial.println("-> Connected");
client.print( "GET /sensorupdate.php?");
client.print("id=");
client.print((int)dataReceived.sensorId);
client.print("&temp=");
client.print(dataReceived.temp);
client.print("&hum=");
client.print(dataReceived.hum);
client.print("&air=");
client.print(dataReceived.air);
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
else
{
Serial.println("--> connection failed/n");
}
}
}
}
OUTPUT :
Data Recieved....
SENSOR ID: 0
Measurement Id: 0
Temperature: 0
Humidity: 0
Air Quality: 0
-> Connected
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....
Data Recieved....