MySQL Forums :: Connector/Arduino :: loop speed


Advanced Search

loop speed
Posted by: Silvio Pedretti ()
Date: November 01, 2015 09:49AM

I would like to use arduino and mysql for a domotic project.
I got it all work, but I find it too slow in the response.
In the sketch I am posting, the SELECT query is done every 1 second.
Is there any way to better the speed?

Thank you





#include "SPI.h"
#include "Ethernet.h"
#include "sha1.h"
#include "mysql.h"

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(192, 168, 10, 13);

Connector my_conn;

char user[] = "arduino";
char password[] = "psw";
int num_fails;
int MAX_FAILED_CONNECTS = 10;
int last_value = 0;
const char QUERY_POP[] = "SELECT last_value FROM test_arduino.sensor WHERE sensor_num = 1";
char query[128];

const int relay_pin = 5;


void setup() {
digitalWrite(relay_pin, HIGH);
pinMode(relay_pin, OUTPUT);
Ethernet.begin(mac_addr);
Serial.begin(115200);
if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
delay(500);
Serial.println("Success!");
} else {
Serial.println("Connection failed.");
}
}

void soft_reset() {
asm volatile("jmp 0");
}

void loop() {
{

my_conn.cmd_query(QUERY_POP);
my_conn.get_columns();
row_values *row = NULL;
do {
row = my_conn.get_next_row();
if (row != NULL) {
last_value = atol(row->values[0]);
}
} while (row != NULL);
my_conn.free_columns_buffer();
my_conn.free_row_buffer();

if (last_value == 1) {
digitalWrite(relay_pin, LOW);
} else
digitalWrite(relay_pin, HIGH);

}
}

Options: ReplyQuote


Subject Views Written By Posted
loop speed 973 Silvio Pedretti 11/01/2015 09:49AM
Re: loop speed 476 Chuck Bell 12/01/2015 01:11PM
Re: loop speed 416 Silvio Pedretti 12/14/2015 02:33PM


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.