IDK my my code not work, help (RC522 + Ethernet w5100)

Shield W5100, RFID RC522, Keypad 3x4 and LCD 16x2 i2C.

#include <SPI.h>
#include <RFID.h>
#include <Keypad.h>
#include <Ethernet.h>
#include <LiquidCrystal_I2C.h>

RFID rfid(8,9);

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serv[] = "192.168.2.121";
LiquidCrystal_I2C lcd(0x27, 16, 2); 
IPAddress ip(192, 168, 2, 188);
EthernetClient client; 
 
char OS[4];
int cracha;
char funcao;
int estado = 0;
byte data_count = 0;
String nome_funcao;
String nome_pessoa;
int prioridade = 0;
String msg_lcd = "";
bool fica_aki = true;
bool cracha_1 = true;
bool pode_ir = false;
bool guarda69 = false;
bool cracha_69 = true;
bool autorizado = true;
bool sai_funcao = false;
bool modo_envia = false;
bool modo_finaliza = false;

char OS69[4];  
char guarda_funcao69;
char guarda_funcao1;
char OS1[4];  


const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {6,7,A0,A1};
byte colPins[COLS] = {2,3,5};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);



void setup() {

   nome_funcao.reserve(17);
   nome_pessoa.reserve(11);
   lcd.init(); 
   lcd.backlight();
   SPI.begin();
   Ethernet.begin(mac, ip);
   lcd.print("Iniciando");
    if (Ethernet.begin(mac) == 0) {
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      }
    }
   rfid.init();
  
}

void loop() {

   if (client.connect(serv, 80)) { //Connecting at the IP address and port we saved before
        
        client.print("GET /ethernet2/data.php?"); //Connecting and Sending values to database
        client.print("OS=");
        client.print(1);
        client.print("&funcao=");
        client.print(funcao);
        client.print("&cracha=");
        client.println(cracha);
        client.stop();
    }

  lcd.setCursor(0,0);
  lcd.print("BATA O CARTAO");
  if(rfid.isCard()){
    modo_cartao();
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Bom Trabalho");
    delay(1000);
  }
  rfid.halt();

  if(modo_envia == true){
    envia_dados();
    if(cracha == 69){cracha_69 = false;}
    else if(cracha == 1){cracha_1 = false;}
    modo_envia = false;
  }
}


void modo_cartao(){
      
      String rfidCard;
      if (rfid.readCardSerial()) {
        rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);
        if(rfidCard == "202 73 165 21"){cracha = 69; guarda69=true;}
        else if(rfidCard == "199 91 20 179"){cracha = 1; guarda69=false;}
        verifica_pessoa();
        if(autorizado == true){
           pega_nome_pessoa();
           lcd.clear();
           lcd.setCursor(0,0);
           lcd.print("Ola");
           lcd.setCursor(4,0);
           lcd.print(nome_pessoa);
           lcd.setCursor(0,1);
           lcd.print("Insira a OS");
           delay(1000);
           while(pode_ir == false){
             modo_teclado();
           }
           modo_confirmar();
           pode_ir = false;
           modo_envia = true;
        }
        else if(autorizado == false){
          if(rfidCard == "202 73 165 21"){cracha_69 = true; cracha = 69;}
          else if(rfidCard == "199 91 20 179"){cracha_1 = true; cracha = 1;}
          modo_finaliza = true;
        }
        data_count = 0;
    }
}


void modo_teclado(){

  char customKey;
  lcd.setCursor(0,0);
  while(fica_aki == true){
    customKey = customKeypad.getKey();
    if(estado == 2){
      fica_aki = false;
    }
    
    if (customKey){
      if(customKey == '#'){
        OS[data_count--] = 0;
        data_count = 0;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Limpando");
        delay(500);
      }
      else if(customKey == '*'){
        estado++;
      }

      if(estado == 1){
        funcao = customKey;
        if(guarda69==true){guarda_funcao69 = customKey;}
        else if(guarda69==false){guarda_funcao1 = customKey;}
      }
      
      if(estado == 0){
        if(data_count == 0){
          lcd.clear();
        }
        if(guarda69==true){
          OS69[data_count] = customKey;
        }
        if(guarda69==false){
         OS1[data_count] = customKey;
        }         
        OS[data_count] = customKey;
        msg_lcd ="Numero da os";
        lcd.setCursor(0,0);
        lcd.print(msg_lcd);
        lcd.setCursor(data_count,1); 
        lcd.print(OS[data_count]); 

      }

      if(estado == 1){
        lcd.clear();
        msg_lcd = "Funcao";
        lcd.setCursor(0,0);
        lcd.print(msg_lcd);
      }
      
      if(funcao == '4'){
        pega_nome_funcao();
        lcd.setCursor(0,1);
        lcd.print(customKey);
        lcd.setCursor(2,1);
        lcd.print(nome_funcao);
        delay(1000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("qual prioridade");
        lcd.setCursor(0,1);
        lcd.print("U-1");
        lcd.setCursor(4,1);
        lcd.print("M-2");
        lcd.setCursor(8,1);
        lcd.print("N-3");
        while(sai_funcao == false){
          customKey = customKeypad.getKey();
          if(customKey == '1'){
            prioridade = 1;
            lcd.clear();
            lcd.setCursor(0,1);
            lcd.print("Urgente");
            lcd.setCursor(0,0);
            lcd.print("prioridade");
            delay(1000);
            sai_funcao = true;
          }
          if(customKey == '2'){
            prioridade = 2;
            lcd.clear();
            lcd.setCursor(0,1);
            lcd.print("Medio");
            lcd.setCursor(0,0);
            lcd.print("prioridade");
            delay(1000);
            sai_funcao = true;
          }
          if(customKey == '3'){
            prioridade = 3;
            lcd.clear();
            lcd.setCursor(0,1);
            lcd.print("Normal");
            lcd.setCursor(0,0);
            lcd.print("prioridade");
            delay(1000);
            sai_funcao = true;
          }
        }
        estado++;
      }
      else if(funcao == '0'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '1'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '2'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '3'){
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '5'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '6'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '7'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '8'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
          
       else if(funcao == '9'){
          pega_nome_funcao();
          lcd.setCursor(0,1);
          lcd.print(customKey);
          lcd.setCursor(2,1);
          lcd.print(nome_funcao);
          delay(1000);
          estado++;
       }
       if(customKey != '#'){
        if(customKey != '*'){
          data_count++;
        }
       }
    }   
  }
  pode_ir = true;
  lcd.clear();
}

void modo_confirmar(){
  
  bool confirmacao = true;
  bool confirmado = false;
  bool pronto = false;
  char customKey;
  int i = 0;

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("OS:");
  
  while(i != (data_count - 1)){
    lcd.setCursor(i+3,0); 
    lcd.print(OS[i]);
    i++;
  }
  lcd.print("-");
  lcd.print("Funcao:");
  lcd.print(funcao);
  lcd.setCursor(0,1);
  lcd.print("confirma?"); 
  while(confirmado == false){
    customKey = customKeypad.getKey();
     if(customKey == '*'){
      confirmacao = false;
      confirmado = true;
     }
     else if(customKey == '#'){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Corrigir OS:1");
      lcd.setCursor(0,1);
      lcd.print("Corrir Funcao:2");
      confirmacao = true;
      confirmado = true;
     }
  }
  while(confirmacao == true){
    customKey = customKeypad.getKey();
    if(customKey == '1'){
      lcd.clear();
      OS[data_count--] = 0;
      data_count = 0;
      msg_lcd ="Numero da os";
      lcd.setCursor(0,0);
      lcd.print(msg_lcd);
      while(pronto == false){
        customKey = customKeypad.getKey();
        if(customKey == '*'){
          pronto = true;
          confirmacao = false;
        }
        else if(customKey){
          if(guarda69==true){
            OS69[data_count] = customKey;
          }
          if(guarda69==false){
            OS1[data_count] = customKey;
          }
          OS[data_count] = customKey;
          lcd.setCursor(data_count,1); 
          lcd.print(OS[data_count]);
          data_count++;
        }
       }
      }
    else if(customKey == '2'){
      lcd.clear();
      funcao = -1;
      if(guarda69==true){guarda_funcao69 = -1;}
      else if(guarda69==false){guarda_funcao1 = -1;}
      sai_funcao = false;
      msg_lcd ="Numero da funcao";
      lcd.setCursor(0,0);
      lcd.print(msg_lcd);
      while(pronto == false){
        customKey = customKeypad.getKey();
        if(customKey){
          funcao = customKey;
          if(guarda69==true){guarda_funcao69 = customKey;}
          else if(guarda69==false){guarda_funcao1 = customKey;}
          if(customKey != 4){
            pega_nome_funcao();
            lcd.clear();
            lcd.setCursor(0,1); 
            lcd.print(funcao);
            lcd.setCursor(0,0);
            lcd.print(nome_funcao);
            delay(1500);
            pronto = true;
            confirmacao = false;
          }
          else if(customKey == 4){
           while(sai_funcao == false){
            customKey = customKeypad.getKey();
            if(customKey){
              if(customKey == '1'){
                lcd.clear();
                lcd.setCursor(0,1);
                lcd.print("Urgente");
                lcd.setCursor(0,0);
                lcd.print("prioridade");
                delay(1500);
                prioridade = 1;
                sai_funcao = true;
              }
              if(customKey == '2'){
                lcd.clear();
                lcd.setCursor(0,1);
                lcd.print("Media");
                lcd.setCursor(0,0);
                lcd.print("prioridade");
                delay(1500);
                prioridade = 2;
                sai_funcao = true;
              }
              if(customKey == '3'){
                lcd.clear();
                lcd.setCursor(0,1);
                lcd.print("Normal");
                lcd.setCursor(0,0);
                lcd.print("prioridade");
                delay(1500);
                prioridade = 3;
                sai_funcao = true;
              } 
            }
          }
         }
       }
     }
   }
 }
 pode_ir = false;
}

void envia_dados(){

  bool conectou = false;
  while(conectou){
      if (client.connect(serv, 80)) { //Connecting at the IP address and port we saved before
        conectou = true;
        client.print("GET /ethernet2/data.php?"); //Connecting and Sending values to database
        client.print("OS=");
        client.print(OS);
        client.print("&funcao=");
        client.print(funcao);
        client.print("&cracha=");
        client.println(cracha);
        client.stop();
    }
  }
}

void finaliza_OS(){

  bool conectou = false;
  while(conectou){
    if(cracha = 69){
      if (client.connect(serv, 80)) { //Connecting at the IP address and port we saved before    
        client.print("GET /ethernet2/data.php?"); //Connecting and Sending values to database
        client.print("OS=");
        client.print(OS69);
        client.print("&funcao=");
        client.print(funcao);
        client.print("&cracha=");
        client.println(cracha);
        client.stop();
      }
    }
    else{
      if (client.connect(serv, 80)) { //Connecting at the IP address and port we saved before
        client.print("GET /ethernet2/data.php?"); //Connecting and Sending values to database
        client.print("OS=");
        client.print(OS1);
        client.print("&funcao=");
        client.print(funcao);
        client.print("&cracha=");
        client.println(cracha);
        client.stop();
      }
    }
  }
}

void pega_nome_funcao(){

  switch (funcao){
    case '1':
      nome_funcao = "- higiene ext";
      break;
    case '2':
      nome_funcao = "- desmontagem";
      break;
    case '3':
      nome_funcao = "- relacao peca";
      break;
    case '4':
      nome_funcao = "- prioridade";
      break;
    case '5':
      nome_funcao = "- estoque";
      break;
    case '6':
      nome_funcao = "- higiene peca";
      break;    
    case '7':
      nome_funcao = "- montagem";
      break;
    case '8':
      nome_funcao = "- teste";
      break;
    case '9':
      nome_funcao = "- check-out";
      break;
    case '0':
      nome_funcao = "- check-in";
      break;
  }
}

void pega_nome_pessoa(){
  if(cracha == 1){
    nome_pessoa = "Armando";
  }
  else if(cracha == 69){
    nome_pessoa = "Francisco";
  }
}

void verifica_pessoa(){
  if(cracha == 1){
   if(cracha_1 == true){
    autorizado = true;
   }
   else if(cracha_1 == false){
    autorizado = false;
   }
  }

  if(cracha == 69){
   if(cracha_69 == true){
    autorizado = true;
   }
   else if(cracha_69 == false){
    autorizado = false;
   }
  }
}

Is this the same question that you posted a few minutes earlier in the programming questions section?

If so, please don't duplicate posts.

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Yes,I thought it might be different places, sorry

The comments make it hard to figure out what you expect the code to do

"code not work"... useful

This code doesn't work either...

int x = 10;

Because I actually wanted x to be 11.

sorry guy, im noob, what should my code do, Receive and store an IDcard, store 4 KeyPad keys and then send it to my Database via PHP (and each step showing on LCD)

So, what was the last change you made, that stopped the code that had been working?

The last change was to send the information to the Database, before it used Serial.Print, now I want to send it to the Database

The code itself is not giving an error, but the ethernet is not sending the data to the database, I believe it is not connecting with the server, idk

I would suggest that you add some debug Serial.print statements to your code so you can see exactly where it is going wrong. Without this information you are basically guessing what the issue might be.

ok i will try

OK, it is going through all the programming correctly, it has all the right variables, but in the sending part it seems that it is not connecting with the server.

So which bit EXACTLY isn't working as expected?

You should try to get a cut down version of the code working. Maybe try the Ethernet example code also.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.