Hi there I am new to the Arduino forum and I have a question. My intention is to read data from a KWH meter and send those data with a certain interval to a (XAMPP) SQL database. I managed to read the data from a single phase KWH meter and store it in the database with phpMyAdmin. The hardware is an Arduino Uno with ethernet shield and a home made prototypeboard shield with a MAX485 IC, to convert the TTL to MODBUS the language of the KWH meter and to display data with some LED's. This data might not be relevant for the problem I have, but just to be sure.
The problem: From Arduino I made a call to a PHP file, data.php which updates my table correctly.
I used this link to get my stuff running, which was a great help.
https://create.arduino.cc/projecthub/muhammad-aqib/logging-data-to-database-using-arduino-ethernet-shield-3e9a0e
Next I wanted to update another table log_book of the same database arduino which contains 2 fields. I made the PHP file similar tot data.php called record_log.php and stored it on th same directory as data.php. In my case /opt/lampp/htdos/ethernet (ubuntu). I did run the following command in the Brave browser
http://localhost/ethernet/record_log.php?request=2&response=23 and this correctly updated the log_book table. So the script is ok was my conclusion. Then I made the following simple code, just to check whether update will be carried out from Arduino. There was no update??? I checked the following:
- item Compared syntax's data.php & record_log.php
- compared authorizations of both files (the same)
- checked the php_error_log (no entry)
- checked the access_log file only entries found of successful update of file data.php.
The question where what can I check to discover what is going on???
Arduino code
#include <SPI.h>
#include <Ethernet.h>
#define LED_ERROR 5 // Indicates an error
byte mac[] = { 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX };
byte ip[] = {XXX, XXX, X, X }; //Enter the IP of ethernet shield
byte serv[] = {XXX, XXX, X, X} ; //Enter the IPv4 address, of the PC where the PHP pages exists.
int request = 25;
int response = 27;
EthernetClient eth_client;
void setup()
{
Ethernet.begin(mac, ip);
pinMode(LED_ERROR, OUTPUT); // Flashes the number of bytes
Serial.begin(9600); // set serial communication baudrate
delay(100);
}
void loop()
{
// put your main code here, to run repeatedly:
save_log();
}
// Start log
void save_log()
{
if (eth_client.connect(serv, 80))
{ //Connecting at the IP address and port we saved before
Serial.println("connected for save log");
flash_times(LED_ERROR, 250, 10);
eth_client.print("GET /ethernet/record_log.php?");
eth_client.print("&request=");
eth_client.print(request);
eth_client.print("&response=");
eth_client.print(response);
eth_client.stop(); //Closing the connection
} // end if
//
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
} // end else
delay(1000);
}
// End log
void flash_times(int pinno, int pulse_wdth, int no_times)
// pin number "pinno" will flash "no_times" times with a pulse width of "pulse_wdth" in msec
{
int f;
for (f=0; f<no_times; f++)
{
digitalWrite(pinno,HIGH);
delay(pulse_wdth);
digitalWrite(pinno,LOW);
delay(pulse_wdth);
}
}type or paste code here
