MySQL Forums
Forum List  »  Connector/Arduino

Re: error 5
Posted by: Kurt Bierbaum
Date: July 14, 2016 11:52AM

Hi Chuck,

please find enclosed a very condensed version of my swetch which shows the error. The table referenced in the query contains the fields id (INT 11), date (TIMESTAMP), tag (VARCHAR 30)and value (INT 11).

Best regards
Kurt

P.S: On a side note, I was not aware that the connector was added to the list of libraries, but this is certainly a good move.
Your library is great, I am using it now for more than a year (1.04ga)!


#include "SPI.h"
#include "sha1.h"
#include "mysql.h"
#include <Ethernet.h>
#include "Streaming.h"

Connector my_conn; // The Connector/Arduino reference

char user[] = "yyyyy";
char password[] = "xxxxx";
IPAddress server_addr(192, 168, 2, 200);// Supply the IP of the MySQL *server* here
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x60, 0xCD }; //adjust this for your Arduino

void setup ()
{

Serial.begin(115200);
delay(100);

if (Ethernet.begin(mac) == 0) {
Serial << ( F("Failed to configure Ethernet using DHCP"));

}
else {
delay(1000);
Serial << F("\nEthernet using DHCP connected\n");
}

if (my_conn.mysql_connect(server_addr, 3306, user, password))
{
delay(500);
}
else {
Serial << F("\nConnection failed." ) << endl;
}

boolean sys_enableAutoWatering = ( getParameter ( "enableAutoWatering" ) == 1);

my_conn.disconnect ();

}

void loop () {
}

//************************** getParameter ******************************

int getParameter ( char *tag ) {

if ( my_conn.is_connected() ) { // if successful

column_names *c; // pointer to column values
row_values *r; // pointer to row values

char query[255];

const char SELECT_QUERY5 [] = "SELECT * FROM plants.preferences WHERE tag = \"%s\""; // läuft in Sequel Pro
sprintf ( query, SELECT_QUERY5, tag );
// Serial << query << endl;

// First, execute query. If it returns a value pointer,
if (!my_conn.cmd_query(query)) {
return 0;
}

// Next, we read the column names and display them.
c = my_conn.get_columns();

int num_cols = c->num_fields;
int rows = 0;

// Next, we use the get_next_row() iterator.
r = my_conn.get_next_row();
if (r) {

int plant_id = atol(r->values[0]);
//char *myDate = r->values[1]; // is date, we don't need it
//char *myTag = r->values[2]; // is tag
int value = atol(r->values[3]);

my_conn.free_row_buffer(); // free the row read to free the memory allocated for it.
my_conn.free_columns_buffer(); // free the column buffers
my_conn.clear_ok_packet();

return value;

} else return 0;
}
}

Options: ReplyQuote


Subject
Views
Written By
Posted
2816
July 12, 2016 08:49AM
1351
July 14, 2016 06:46AM
Re: error 5
1491
July 14, 2016 11:52AM
1262
July 14, 2016 06:57AM
1361
July 14, 2016 12:13PM
1899
July 14, 2016 12:43PM
1426
July 14, 2016 02:25PM
1138
July 19, 2016 06:31AM


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.