I'm trying to create a project in which my arduino must upload sensor readings into a database. I decided to use Xampp for this project and for the past week I've been struggling to establish a connection with my arduino using an Ethernet shield. Thing is the shield should be used with a router but I do not own one, I use a hotspot wifi for all of my needs. I've been trying to make the connection using my own PC as the local host, but to no avail. I'm simply wondering if it's actually possible to establish a connection to the database using my PC without the need of a router.
Do keep in mind I'm fairly new to this topic so I may be missing critical steps for this to work.
side note:
I used the "DhcpAddressPrinter" script for obtaining my Ethernet ip, it used to work before but now it won't work and simply prints "Failed to configure Ethernet using DHCP". I've kept the ip it used to give me before in my project as the ip for the shield.
my ethernet shield module is a W5100 in case if that's needed
This the code for my proyect:
/*Radio Libraries*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*Radio variables*/
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
/*Ethernet libraries*/
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Setting MAC Address
byte server[] = { 192, 168, 43, 13 };
//IPAddress ip( 192, 168, 137, 2 );
//IPAddress ip( 192, 168, 137, 166 );
IPAddress ip( 192, 168, 137, 177 );
EthernetClient client;
int Temperature = 100;
int Humidity = 20;
int AirP;
int CarbonM;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Ethernet.begin(mac, ip);
}
void loop() {
if (radio.available())
{
int text;
radio.read(&text, sizeof(text));
Serial.println(text);
}
Sending_To_phpmyadmindatabase();
Temperature++;
Humidity++;
delay(5000);
}
void Sending_To_phpmyadmindatabase() //CONNECTING WITH MYSQL
{
if (client.connect(server, 8080)) {
Serial.println("connected");
// Make a HTTP request:
Serial.print("GET /PHPArduinoscript/ArduinoDB.php?Humidity=");
client.print("GET /PHPArduinoscript/ArduinoDB.php?Humidity="); //YOUR URL
Serial.println(Humidity);
client.print(Humidity);
client.print("&Temperature=");
Serial.println("&Temperature=");
client.print(Temperature);
Serial.println(Temperature);
client.print(" "); //SPACE BEFORE HTTP/1.1
client.print("HTTP/1.1");
client.println();
client.println("Host: 192.168.43.13");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}