arduino/MySQL

Hello community

For a student project, I have to make communicate an arduino card with a MySQL server.
The server is already functional and communicates with a python program.

It's been two months that I look on all the programming forums but all the ideas which are given there do not work in my case, I ask you the question: How to make communicate the card to the database?

For more information on this project (in french) : GitHub - BenCestMoiQuoi/Suivi-Medical-A-Distance: Projet de TIPE 2020/2021

Think
Corentin

Ps : sorry for my english who is, I think, bad.

Vous voudrez peut-être demander de l'aide dans propre langue. Which "card" are you using? How are you connecting to the server? Usually, talking to python is done through GET or POST methods.

There is a common problem with getting MySQL to work: by default, it will not accept connections from anything except the server it is running on.

Can you use the Python page to put data in the database from a browser on a different computer?

Perehama:
Vous voudrez peut-être demander de l’aide dans propre langue. Which “card” are you using? How are you connecting to the server? Usually, talking to python is done through GET or POST methods.

I use an Arduino Uno card whith a Ethernet shield.
I d’ont understand your last sentence.

wildbill:
There is a common problem with getting MySQL to work: by default, it will not accept connections from anything except the server it is running on.

Can you use the Python page to put data in the database from a browser on a different computer?

OK, I see
I can use the Python page to put data in the database from my computer, because my database is in my computer

Post the code you're using on the Arduino.

Have a look at

MySQL_MariaDB_Generic Library

You can connect your Arduino project directly to a MySQL / MariaDB server without using an intermediate computer or a web-based or cloud-based service. Having direct access to a MySQL / MariaDB database server means you can store data acquired from your project as well as check values stored in tables on the server.

  1. This is terminal debug output when running Query_Progmem on nRF52 Adafruit NRF52840_FEATHER using W5500 Ethernet module and Ethernet3 library, connecting to MySQL Server.
Starting Query_Progmem on NRF52840_FEATHER using W5x00/Ethernet3 Library

Ethernet3 W5500 init, using SPI_CS = 10, number of sockets = 4
Using mac index = 10
Connected! IP address: 192.168.2.145
Connecting to SQL Server @ 192.168.2.112, Port = 5698
User = invited-guest, PW = the-invited-guest
[SQL] Connecting to Server: 192.168.2.112 , Port =  5698
[SQL] Connect OK. Try reading packets
[SQL] Try parsing packets
[SQL] Try send_authentication packets
[SQL] Connected. Server Version =5.7.31-0ubuntu0.18.04.1

Running SELECT from PROGMEM and printing results

SELECT * FROM world.city LIMIT 12
ID,Name,CountryCode,District,Population
1,Kabul,AFG,Kabol,1780000
2,Qandahar,AFG,Qandahar,237500
3,Herat,AFG,Herat,186800
4,Mazar-e-Sharif,AFG,Balkh,127800
5,Amsterdam,NLD,Noord-Holland,731200
6,Rotterdam,NLD,Zuid-Holland,593321
7,Haag,NLD,Zuid-Holland,440900
8,Utrecht,NLD,Utrecht,234323
9,Eindhoven,NLD,Noord-Brabant,201843
10,Tilburg,NLD,Noord-Brabant,193238
11,Groningen,NLD,Groningen,172701
12,Breda,NLD,Noord-Brabant,160398
12 rows in result.

wildbill:
Post the code you’re using on the Arduino.

/*
MySQL Connector/Arduino Example : connect

This example demonstrates how to connect to a MySQL server from an
Arduino using an Arduino-compatible Ethernet shield. Note that “compatible”
means it must conform to the Ethernet class library or be a derivative
with the same classes and methods.

For more information and documentation, visit the wiki:
https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki.

INSTRUCTIONS FOR USE

  1. Change the address of the server to the IP address of the MySQL server
  2. Change the user and password to a valid MySQL user and password
  3. Connect a USB cable to your Arduino
  4. Select the correct board and port
  5. Compile and upload the sketch to your Arduino
  6. Once uploaded, open Serial Monitor (use 115200 speed) and observe

If you do not see messages indicating you have a connection, refer to the
manual for troubleshooting tips. The most common issues are the server is
not accessible from the network or the user name and password is incorrect.

Note: The MAC address can be anything so long as it is unique on your network.

Created by: Dr. Charles A. Bell
*/
#include <Ethernet.h>
#include <MySQL_Connection.h>

byte mac_addr = { 0x90, 0xA2, 0xDA, 0x10, 0xA9, 0x58 };

IPAddress server_addr(192,168,1,24); // IP of the MySQL server here
char user = “corroc”; // MySQL user login username
char password = “86.07”; // MySQL user login password

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println(“Connecting…”);
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
// You would add your code here to run a query once on startup.
}
else
Serial.println(“Connection failed.”);
conn.close();
}

void loop() {
}

This code do nothing

Please take a moment to read the sticky post at the top of this forum. It shows you how to properly post your code using code tags which makes it better for everyone. Help yourself by helping others help you.

When you say "This code do nothing", that can't be true. It will print "Connecting..." and then possibly "Connection failed." to the serial monitor. What do you see?

If you don't see the "Connection failed." output, you can assume the connection was made, but that is all the code does. It does not do any queries, etc. You will have to add that.

Ok, sorry for this mistake, indeed it’s better for you.

When I open the Serial Monitor (with 115200 speed, like the exemple), it’s written :

Connecting...
Connecting...
Connecting...
Connection failed.

And my code

#include <Ethernet.h>
#include <MySQL_Connection.h>

byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x10, 0xA9, 0x58 };

IPAddress server_addr(192,168,1,24);  // IP of the MySQL *server* here
char user[] = "corroc";              // MySQL user login username
char password[] = "86.07";        // MySQL user login password

EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  Serial.begin(115200);
  while (!Serial); // wait for serial port to connect
  Ethernet.begin(mac_addr);
  Serial.println("Connecting...");
  if (conn.connect(server_addr, 3306, user, password)) {
    delay(1000);
    // You would add your code here to run a query once on startup.
  }
  else
    Serial.println("Connection failed.");
  conn.close();
}

void loop() {
}

Take another look at post #2.

Also, check your server sql logs - it may tell you that there was a remote connection rejected.

Yes, I see your message #2 , but you know if in the database, there is an option who will allowed to resolve the probleme ?