good day! ive been trying to send some data from my arduino to mysql database in my pc. i used nrf24l01 and ethernet module on my arduino and succesfully print my data on the serial monitor. when i tried to connect it to the database, the serial monitor displays connection failure, and now im stuck with it. ill post my code here and please tell me where i had been wrong.
ps. i already ping the arduino from my pc and it is connected.
#include <RF24Network.h>
#include <Ethernet.h>
/*Master TxRx Node 00*/
#include <RF24.h>
#include <SPI.h>
#define soundalarm 1 // for alarm na toh
#define lightalarm 2
int msg[1]; // this is the received data storage
RF24 radio(7, 8); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format ( 04,031,etc)
const uint16_t node01 = 01; // Address of the other node in Octal format
byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
IPAddress ip(169,254,5,225);
char server[] = "169.254.5.220";
EthernetClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac,ip);
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
pinMode(soundalarm, OUTPUT);
pinMode(lightalarm, OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
}
void loop() {
network.update();
//===== Receiving and Sending Ack Signal=====//
while ( network.available()) { // Is there any incoming data?
RF24NetworkHeader header00;
network.read(header00, &msg[0], sizeof(msg[0])); // Read the incoming data
Serial.println(msg[0]);
if (msg[0] == 01) {
msg[0] = 11; // Read the incoming data and prepares the ack code bits
digitalWrite(soundalarm, HIGH);
digitalWrite(lightalarm, HIGH);
delay(2000); //babaguhin pa ito
digitalWrite(soundalarm, LOW);
digitalWrite(lightalarm, LOW);
RF24NetworkHeader header01(node01);
bool ok = network.write(header01, &msg[0], sizeof(msg[0]));}
if (msg[0] == 10) {
msg[0] = 11; // Read the incoming data and prepares the ack code bits
digitalWrite(soundalarm, HIGH);
digitalWrite(lightalarm, HIGH);
delay(2000); //babaguhin pa ito
digitalWrite(soundalarm, LOW);
digitalWrite(lightalarm, LOW);
RF24NetworkHeader header01(node01);
bool ok = network.write(header01, &msg[0], sizeof(msg[0]));}
// Connect to the server (your computer or web page)
msg[1] == msg[0];
if (client.connect(server, 80)) {
client.print("GET ,/write_data.php?"); // This
client.print("&value="); // This
client.print(msg[1]); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
client.println("HTTP/1.1"); // Part of the GET request
client.println("Host: 169.254.5.220"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server
}
else {
// If Arduino can't connect to the server (your computer or web page)
Serial.println("--> connection failed\n");
}
delay(10000);
}
}