Estoy haciendo una consulta a un MySQL desde una Arduino Ethernet.
Consulto tres campos de una BD MySQL: idTipusSonda (Char[5]), Calibartge (fload), Periode (int)
Programa:
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEA };
int idSonda = 1002;
// MySQL
IPAddress serverMySQL_addr(172,20,105,7); // IP of the MySQL *server* here
char userMySQL[] = "rrrrrrrrrrrr"; // MySQL user login username
char passwordMySQL[] = "xxxxxxx"; // MySQL user login password
// Query
char query[] = "SELECT Calibratge, Periode, idTipusSondes FROM gesregistres.sondes WHERE idSonda = '1002'";
EthernetClient client;
MySQL_Connection conn((Client *)&client);
// Create an instance of the cursor passing in the connection
MySQL_Cursor cur = MySQL_Cursor(&conn);
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println("Connecting...");
if (conn.connect(serverMySQL_addr, 3306, userMySQL, passwordMySQL)) {
delay(1000);
}
else
Serial.println("Connection failed.");
}
void loop() {
row_values *row = NULL;
float head_count = 0;
float head_count1 = 0;
char head_count2;
delay(3000);
Serial.println("1) Demonstrating using a cursor dynamically allocated.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
cur_mem->execute(query);
// Fetch the columns (required) but we don't use them.
column_names *columns = cur_mem->get_columns();
// Read the row (we are only expecting the one)
do
{
row = cur_mem->get_next_row();
if (row != NULL)
{
head_count = atol(row->values[0]);
head_count1 = atol(row->values[1]);
head_count2 = (row->values[2]);
}
}
while (row != NULL);
// Deleting the cursor also frees up memory used
delete cur_mem;
// Show the result
Serial.print(" Calibratge = ");
Serial.println(head_count);
Serial.print(" Periode = ");
Serial.println(head_count1);
Serial.print("idTipusSondes = ");
Serial.println(head_count2);
Serial.println();
}
En la BD:
Calibratge=-5.123
Periode=14
idTipusSonda=a
Resultado que obtengo al leer con el Arduiono:
-->
) Demonstrating using a cursor dynamically allocated.
Calibratge = -5.00
Periode = 14.00
idTipusSondes = ⸮
-
Demonstrating using a cursor dynamically allocated.
Calibratge = -5.00
Periode = 14.00
idTipusSondes = \ -
Demonstrating using a cursor dynamically allocated.
Calibratge = -5.00
Periode = 14.00
idTipusSondes = u
Aquí las preguntas:
Porque no consigo leer "calibratge" con los decimales?
Porque no consgo leer idTipus sonda el valor "a" ?
Adjunto imagen de la BD del MySQL
Gràcias.