Hey guys,
I 'am working on a specific project that requires a database.
I have done the 'connection' and the "write" of data using a PHP file.
I have even reconfigured everything so it would be possible to access the database through a different device that is connected to the same wifi network as my computer.
All tested and working properly.
The Arduino for some reason is not connecting to the server, where Serial.println(client.connect(serv, 8095));
is returning 0, I have tried every possible solution but nothing seems to work.
I am using xampp, and I changed the port to 8095.
any possible information would be much appreciated.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xFDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };byte sensorInterrupt = A2;
byte sensorPin = A2;
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
char valvestatus= 'ON';
byte ip[] = {192, 168, 1, 4 }; //Read the code explanation https://102.159.198.42/
byte serv[] = {192, 168, 1, 3} ; //Read the code explanation 192.168.1.3
EthernetClient client;void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);}
void loop() {
if((millis() - oldTime) > 1000) {
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
unsigned int frac;
Serial.print(int(flowRate)); ////////
Serial.print(totalMilliLitres); /////////////
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);}
Serial.println(client.connect(serv, 8095));
if (client.connect(serv, 8095)) { //Connecting at the IP address and port we saved before
client.print("GET /ost/write_data.php?"); //Connecting and Sending values to database
client.print(flowRate);
client.print(totalMilliLitres);
client.print(valvestatus);
client.stop(); //Closing the connection
}
while(!client.available()){}}
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}