MySQL Forums
Forum List  »  Connector/Arduino

Read values float from mysql
Posted by: Denys Oliveira
Date: August 18, 2015 07:07AM

Hello!
I need read a value float from my data base.
I using this code from a example(I changed only the select)
But I could only read the whole of the value and I need the two decimal places

value displayed in serial monitor = 127

necessary value = 127.62

anybody can help me?


/**
* Example: Simple Select Example: Hello, MySQL!
*
* This code module demonstrates how to create a simple
* database-enabled sketch with selecting data.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <sha1.h>
#include <mysql.h>
/* Setup for Ethernet Library */
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(192, 168, 0, 103);
/* Setup for the Connector/Arduino */
Connector my_conn; // The Connector/Arduino reference
char user[] = "operador";
char password[] = "secret";
const char QUERY_POP[] =
"SELECT tensao FROM banco.hello WHERE id = (SELECT MAX(id) FROM banco.hello)";
float head_count = 0;
void setup() {
Ethernet.begin(mac_addr);
Serial.begin(115200);
while (!Serial);
delay(1000);
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)){
Serial.println("Connected!");
my_conn.cmd_query(QUERY_POP);
my_conn.get_columns();
row_values *row = NULL;
do {
row = my_conn.get_next_row();
// We use the first value returned in the row - population of NYC!
if (row != NULL) {
head_count = atol(row->values[0]);
}
my_conn.free_row_buffer();
} while (row != NULL);
my_conn.free_columns_buffer();
Serial.print("ultima tensao = ");
Serial.println(head_count);
} else {
Serial.println("Connection failed.");
}
}
void loop() {
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Read values float from mysql
1497
August 18, 2015 07:07AM
623
August 20, 2015 07:10AM
577
August 20, 2015 09:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.