MySQL Forums
Forum List  »  Connector/Arduino

Re: Packet Error
Posted by: Gábor Horinka
Date: November 19, 2014 03:46PM

I tested it a lot in last 2 days, but if the program is in query i still got the error. The disconnect just slows the board, and i have a chance for "disconnect" between two queries.

/////////////////////////THE LOOP/////////////////////////////
loop{
if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
delay(50);
}

if (my_conn.is_connected()) {
do_query(TEST_QUERY);
num_fails = 0;
my_conn.disconnect();
//delay(50);
} else {
my_conn.disconnect();
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
delay(500);
Serial.println("Success!");
num_fails = 0;
} else {
num_fails++;
Serial.println("Connect failed!");
if (num_fails == MAX_FAILED_CONNECTS) {
Serial.println("Ok, that's it. I'm outta here. Rebooting...");
delay(2000);
soft_reset();
}}}}

////////////////////////THE QUERY///////////////////////////////////
void do_query(const char *q) {
column_names *c;
row_values *r;

if (!my_conn.cmd_query(q)) {
return;
}

c = my_conn.get_columns();
for (int i = 0; i < c->num_fields; i++) {

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

do {
r = my_conn.get_next_row();
if (r) {
// rows++;
for (int i = 0; i < num_cols; i++) {

String value = String(r->values);
String kapcs = String(r->values[i-1]);

if (value=="1" && kapcs=="kapcs1"){
digitalWrite(RELAY1, LOW);}
if (value=="0" && kapcs=="kapcs1"){
digitalWrite(RELAY1, HIGH);}

if (value=="1" && kapcs=="kapcs2"){
digitalWrite(RELAY2, LOW);}
if (value=="0" && kapcs=="kapcs2"){
digitalWrite(RELAY2, HIGH);}

// ...
}

my_conn.free_row_buffer();
}
} while (r);
my_conn.free_columns_buffer();

Options: ReplyQuote


Subject
Views
Written By
Posted
2886
October 04, 2014 01:53PM
1683
October 14, 2014 02:08PM
1292
November 01, 2014 04:46AM
1216
November 05, 2014 09:03AM
1184
November 07, 2014 12:13PM
1153
November 07, 2014 01:19PM
1135
November 14, 2014 02:08PM
1013
November 19, 2014 01:39PM
Re: Packet Error
1045
November 19, 2014 03:46PM
1055
November 26, 2014 10:14AM


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.