Caros boa tarde, o código abaixo esta se conectando e buscando dados do banco perfeitamente na base de dados
Por gentileza, preciso que dados verificados nas entradas do arduino como (HIGH e LOW) seja enviados para o Banco como (0 e 1).
Tentei iniciar essa parte do update, mas não tive sucesso, inserir ao lado das linhas novas : // UPDATE.
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <avr/pgmspace.h>
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(XXXXXXXXXX);
char user[] = "tabela";
char password[] = "XXXXXXXXXX";
char query_1[] = "select comando from tabela where id_rele =1;";
char query_2[] = "select comando from tabela where id_rele =2;";
char query_3[] = "select comando from tabela where id_rele =3;";
char query_4[] = "update tabela set posicao=’valor’ where id_rele =1;"; //UPDATE
EthernetClient client;
MySQL_Connection conn((Client *)&client);
MySQL_Cursor cur = MySQL_Cursor(&conn);
int port_relay1 = 5;
int port_relay2 = 6;
int port_relay3 = 7;
int port_relay4 = 8; //UPDATE
int valor=0; //UPDATE
long iloop = 1;
IPAddress server_ip;
void setup() {
Serial.begin(115200);
pinMode(port_relay1, OUTPUT);
pinMode(port_relay2, OUTPUT);
pinMode(port_relay3, OUTPUT);
pinMode(port_relay4, INPUT);//UPDATE
while (!Serial);
Ethernet.begin(mac_addr);
Serial.println("Conectando Servidor WEB");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Falha na conexão Servidor WEB");
}
void loop() {
row_values *row = NULL;
long head_count = 0;
int irelay1;
int irelay2;
int irelay3;
delay(100);
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
if (iloop ==1){
cur_mem->execute(query_1);
}
if (iloop ==2){
cur_mem->execute(query_2);
}
if (iloop ==3){
cur_mem->execute(query_3);
}
if (iloop ==4){ //UPDATE
{
valor = digitalRead(port_relay4); //UPDATE
}
column_names *columns = cur_mem->get_columns();
do {
row = cur_mem->get_next_row();
if (row != NULL) {
head_count = atol(row->values[0]);
}
} while (row != NULL);
delete cur_mem;
irelay1 = head_count;
irelay2 = head_count;
irelay3 = head_count;
if (iloop == 1){
if (irelay1 == 1){
digitalWrite(port_relay1, LOW);
}
else
{
digitalWrite(port_relay1, HIGH);
}
}
if (iloop == 2){
if (irelay2 == 1){
digitalWrite(port_relay2, LOW);
}
else
{
digitalWrite(port_relay2, HIGH);
}
}
if (iloop == 3){
if (irelay1 == 1){
digitalWrite(port_relay3, LOW);
}
else
{
digitalWrite(port_relay3, HIGH);
}
}
VARIABLE INCLUDED WITH INFORMATION WITH INPUT PIN
iloop = iloop +1;
if (iloop == 4){
iloop = 1;
}
}
Obrigado.
Abraço