Hi there,
I have my Arduino Uno, including ethernet shield. It downloads values from a power meter and stores that in MariaDB database (LAMPP), My LAMPP server is on my Ubuntu 22.04 Laptop. I use IDE 2.04. The protocol I use is MODBUS. It works fine but misses sometimes records. This is rather difficult to determine. What I want now is to store text data in another database table, the text data will be a combination of data which I think is important to debug a current problem. E.g.
"ID = 2345 Loop is read data time duration is 23000 millisec."
Some how I don't manage to store text in the database. I have made a small arduino program to test it, but I got stuck.
EthernetClient eth_client;
String message = "Dit is ook een test 34";
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
Ethernet.begin(mac, ip, dns, gateway);
// sprintf(message," dit is getal %d ", getal);
// sscanf("String", "%s", &message);
Serial.println(message);
save_debug();
}
void loop() {
// put your main code here, to run repeatedly:
}
void save_debug() {
if (eth_client.connect(serv, 80)) { //Connecting at the IP address and port we saved before
// duration_s = millis();
Serial.println("connected for storage debug");
eth_client.print("GET /ethernet/debug_message.php?"); //Connecting and Sending values to database
eth_client.print("message=");
eth_client.print(message);
eth_client.print(" HTTP/1.1");
eth_client.println("");
delay(5000);
// duration_s = millis() - duration_s;
eth_client.stop(); //Closing the connection
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
delay(1000);
}
}
The file debug_message
<?php
include ('connection.php');
$sql_insert = "INSERT INTO debug_message (message)
VALUES
('".$_GET["message"]."'
)";
if(mysqli_query($con,$sql_insert))
{
echo "Done";
mysqli_close($con);
}
else
{
echo "error is ".mysqli_error($con );
}
?>
If I run the following command via my browser
http://localhost/ethernet/debug_message.php?message=”ID 23 duration 5000”
This data is stored correctly in the database, even when I dismiss the double quotes.
In access.log I saw the following log:
<TCP/IP address> [24/Mar/2023:11:25:22 +0100] "GET /ethernet/debug_message.php?message=Dit is" 400 960
It seems that the text is just partly (truncated) there. So the question is how can I transfer fields which contains text to the database. In MariaDB the message field is defined as TEXT and the unicode utf8mb4_general_ci.
The reason to store debug data in the database instead of displaying it on the serial monitor is that the Uno is placed in our Barn (cold and windy) and some meters away from the house, so to have a look on the serial monitor I have to travel to the barn and that is not handy. As far as I know is the serial monitor not available via Ethernet.