Boa noite,
Gostaria de ajuda para implementar a comparação de 25 combinações de tags, ou seja, serão cadastrados 50 tags, porém somente com a combinação de 2 tags (pessoa e veículo) irá liberar o acesso.
O mesmo ainda informa no banco mysql data e hora e a combinação das 2 tags.
// Variáveis de para banco de dados
byte MAC[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x0A, 0x16 }; //MAC do shield ethernet
IPAddress server_addr(192, 168, 25, 8); //IP do servidor MySQL
Connector my_conn; // O Connector/Arduino para MySQL
char user[] = "root"; //
char password[] = "root";
//o comando SQL deve ter no máximo 70 caracteres
char INSERT_SQL[70] = "INSERT into controleacesso.acesso VALUES ('IGOR',NOW(),'PALIO');";
boolean flag = true, abriu_portao = false;
int carro_ok = 0, pessoa_ok = 0;
int tempo, fecha_portao = 0, rele = 31 ;
//tags gravadas
char tag_carro[13] = "6A003E869B49";
char tag_pessoa[13] = "6A003E38E08C";
// Variável para LCD
LiquidCrystal LCD(12, 11, 7, 6, 5, 3); // Cria uma nova instancia do objeto LCD
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
pinMode(rele, OUTPUT);
LCD.begin(20, 4);
LCD.setCursor(0,0);
LCD.print(" Inicializando...");
LCD.setCursor(0,1);
LCD.print("Por favor, aguarde..");
delay(5000); //espera que se abra a porta serial
if(Serial)
{
Serial.println("Iniciando...");
Serial.println("Obtendo IP...");
}
LCD.clear();
LCD.print("Obtendo IP...");
if (Ethernet.begin(MAC))
{
if(Serial)
{
Serial.println("Conexão estabelecida com sucesso");
Serial.print("Meu IP: ");
Serial.println(Ethernet.localIP());
}
LCD.setCursor(0,1);
LCD.print("Meu IP: ");
LCD.setCursor(0,2);
LCD.print(Ethernet.localIP());
delay(2000);
if (Serial)
Serial.print("Conectando ao Servidor de Dados...");
LCD.clear();
LCD.print(" Conectando ao BD ");
delay(2000);
if (my_conn.mysql_connect(server_addr, 3306, user, password))
{
delay(1000);
if (Serial)
Serial.println("Conexão com Servidor de Dados estabelecida com sucesso!");
LCD.setCursor(0,1);
LCD.print(" Conexao com BD OK! ");
delay(1000);
}
else
{
if (Serial)
Serial.println("Conexão com Servidor de dados não pode ser estabelecida!");
LCD.setCursor(0,1);
LCD.print(" Conexao Falhou!");
}
}
else
{
if(Serial)
Serial.println("A conexão não pode ser estabelecida");
LCD.setCursor(0,1);
LCD.print(" Falha Conexao Rede ");
}
}
void loop()
{
//escreve apenas no primeiro ciclo
if (flag)
{
Serial.println("SISTEMA PRONTO");
LCD.clear();
LCD.print("Controle Acesso RFID");
flag = false;
}
char tagString[13];
int i = 0;
boolean Ler = false;
//executa o lanço enquanto tiver dados do leitor RFID
while(Serial1.available())
{
int ByteLido = Serial1.read();
if(ByteLido == 2) Ler = true;
if(ByteLido == 3) Ler = false;
if(Ler && ByteLido != 2 && ByteLido != 10 && ByteLido != 13)
{
//preenche tag
tagString = ByteLido;
- i ++;*
- }*
- }*
- checkTag(tagString);*
- limpaTag(tagString);*
- resetLeitor(); /*
- VerificaAcesso(); /*
- FechaPortao();*
}
void checkTag(char tag[])
{
///////////////////////////////////
//Verifica todos os tags
///////////////////////////////////
- if(strlen(tag) == 0) return; //se vazio, não verifica*
- if(compareTag(tag, tag_carro))*
- { // se é carro*
- Serial.println("TAG 1");*
- LCD.setCursor(0,1);*
- LCD.print(" Carro OK ");*
- carro_ok = 1;*
- }else if(compareTag(tag, tag_pessoa))*
- { //se é pessoa*
- Serial.println("TAG 2");*
- LCD.setCursor(0,1);*
- LCD.print(" Igor OK ");*
- pessoa_ok = 1;*
- }*
- else*
- {// senão é nenhum dos dois escreve na serial*
- Serial.println("Tag Invalido!");*
- LCD.setCursor(0,1);*
- LCD.print(" Tag Invalido ");*
- carro_ok = 2;*
- pessoa_ok = 2;*
- }*
}
void resetLeitor()
{
///////////////////////////////////
//Reset o leitor RFID para a próxima leitura
/////////////////////////////////// - delay(150);*
}
void limpaTag(char um[])
{
///////////////////////////////////
//limpa o tag com caracteres ASCII nulo
/////////////////////////////////// - for(int i = 0; i < strlen(um); i++){*
_ um = 0;_
* }*
}
boolean compareTag(char um[], char dois[])
{
///////////////////////////////////
//Compara o tag dois tags e retorna true se for igual
///////////////////////////////////
* if(strlen(um) == 0) return false;*
* for(int i = 0; i < 12; i++){*
if(um != dois*) return false;*
* }*
* return true;*
}
void VerificaAcesso()
{
* if (carro_ok == 1 && pessoa_ok == 0 || carro_ok == 0 && pessoa_ok == 1)
_ {
delay(250);
tempo ++;
}_
else if (carro_ok == 2 && pessoa_ok == 2)
_ {
LCD.setCursor(0,1);
LCD.print("tag Invalido!");
delay(500);
LCD.setCursor(0,1);
LCD.print(" "); _
carro_ok = 0;
pessoa_ok = 0;
_ }_
else if (carro_ok == 1 && pessoa_ok == 1)
_ {
LCD.setCursor(0,2);
LCD.print("Liberado!");
digitalWrite(rele, HIGH);
delay(500);
digitalWrite(rele, LOW);_
my_conn.cmd_query(INSERT_SQL);
carro_ok = 0;
pessoa_ok = 0;
_ tempo = 0;_
abriu_portao = true;
_ LCD.clear();
LCD.print("Controle Acesso RFID");
}*_
* if (tempo == 40)*
* {*
* carro_ok = 0;
pessoa_ok = 0;
_ tempo = 0;
LCD.clear();
LCD.print("Controle Acesso RFID");
}
}
void FechaPortao()
{
//verifica se o portão foi aberto*
* //caso sim, espera 2 min para dar o*
* //comando de fechamento.*_
* if (abriu_portao)
_ {
delay(250);_
fecha_portao++;
if (fecha_portao == 480)
_ {
digitalWrite(rele, HIGH);
delay(500);
digitalWrite(rele, LOW);_
fecha_portao = 0;
abriu_portao = false;
_ }
}
}*
No aguardo de ajuda.
Dessa forma, no banco mysql só mostra as duas tags cadastradas._