Hey Guys,
Im new to reading from MYSQL on an Arduino (Mega), I have been using it to write to a DB for ages, but cannot get my head around this.
I have a DB called relaycontrol1, it has several tables but the one im intrested in is called relaycontroldefaults, that has the floowing fields : relaynumber and default status.
The plan is on boot to read the table, and set the status on each relay ..
the Relaynumber is type int (1 to 16) and defaultstatus is boolean 1 being on 0 being off
Relaynumber, defaultstatus
1 , 0
2 , 1
ETC..
Im using the latest library by chuck, but struggling with this... My code (that does not work) is as follows :
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 1 ");
cur.get_columns();
relaystate1 = atol(row->values[0]);
Serial.println(row->values[0]);
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 2 ");
relaystate2 = atol(row->values[0]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 3 ");
relaystate3 = atol(row->values[2]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 4 ");
relaystate4 = atol(row->values[3]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 5 ");
relaystate5 = atol(row->values[4]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 6 ");
relaystate6 = atol(row->values[5]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 7 ");
relaystate7 = atol(row->values[6]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 8 ");
relaystate8 = atol(row->values[7]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 9 ");
relaystate9 = atol(row->values[8]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 10 ");
relaystate10 = atol(row->values[9]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 11 ");
relaystate11 = atol(row->values[10]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 12 ");
relaystate12 = atol(row->values[11]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 13 ");
relaystate13 = atol(row->values[12]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 14 ");
relaystate14 = atol(row->values[13]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 15 ");
relaystate15 = atol(row->values[14]);
cur.get_columns();
cur.execute("SELECT * FROM `relaycontroldefaults` WHERE `Relaynumber` = 16 ");
relaystate16 = atol(row->values[15]);
// Now we close the cursor to free any memory
cur.close();
// Show the result
Serial.print("Relay one = "); Serial.println(relaystate1);
Serial.print("Relay two = "); Serial.println(relaystate2);
Serial.print("Relay 3 = "); Serial.println(relaystate3);
Serial.print("Relay 4 = "); Serial.println(relaystate4);
Serial.print("Relay 5 = "); Serial.println(relaystate5);
Serial.print("Relay 6 = "); Serial.println(relaystate6);
Serial.print("Relay 7 = "); Serial.println(relaystate7);
Serial.print("Relay 8 = "); Serial.println(relaystate8);
Serial.print("Relay 9 = "); Serial.println(relaystate9);
Serial.print("Relay 10 = "); Serial.println(relaystate10);
Serial.print("Relay 11 = "); Serial.println(relaystate11);
Serial.print("Relay 12 = "); Serial.println(relaystate12);
Serial.print("Relay 13 = "); Serial.println(relaystate13);
Serial.print("Relay 14 = "); Serial.println(relaystate14);
Serial.print("Relay 15 = "); Serial.println(relaystate15);
Serial.print("Relay 16 = "); Serial.println(relaystate16);
Im up for any help as I just have never done this before - and I have other tables etc I will want to read in the future (Timers etc)
I can access the DB etc fine so the username password etc are all good..
Thanks in advance..