SQL + WebServer is possible? don't have conflict?

I can add in this code that when I send it to my Database it sends it to another Arduino (this new Arduino will be a WebServer that will show all the cards that were detected and make a list, like an exel table)

(i'm noob in Arduino and english, but i'm trying hard for learn <3)

my code:

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

RFID rfid(8,9);
LiquidCrystal_I2C lcd(0x27, 16, 2); 

char OS;
char OS1;
char OS2;
char OS3;
char funcao;
int cracha;

String cartao;
String nome;
String nome_funcao;
int vai = -1;
int i = 0;
int x = 0;
bool a = true;
bool erro = false;
bool manda = false;
bool trancado69 = false;
bool finaliza69 = false;
bool trancado60 = false;
bool finaliza60 = false;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serv[] = "192.168.2.121";
IPAddress ip(192, 168, 2, 188);
EthernetClient client; 

const byte ROWS = 4;
const byte COLS = 3; 
char keys[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 keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup() {
   
  SPI.begin();
  Ethernet.begin(mac, ip);
  if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");
   if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
   }
  }
  rfid.init();
  lcd.init(); 
  lcd.backlight();
  lcd.print("Iniciando");
}

void loop() {

  lcd.setCursor(0,0);
  lcd.print("Bata o cartao");
  if(rfid.isCard()){
    if (rfid.readCardSerial()) {
      cartao = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);
      if(cartao == "202 73 165 21"){cracha = 69; nome = "-Francisco";}
      else if(cartao == "199 91 20 179"){cracha = 60; nome = "-Alex";}
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Cartao Detectado");
      lcd.setCursor(0,1);
      lcd.print(cracha);
      lcd.setCursor(2,1);
      lcd.print(nome);
      delay(2500);
      vai = 0;
    }
  }
  rfid.halt();

  if(vai == 0){
    if(cracha == 60){confere60();}
    else if(cracha == 69){confere69();}
  }
  
  if(vai == 1){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Digita a OS");
    while(a == true){
      pega_OS();
    }
  }  
  if(vai == 2){
    pega_funcao();
    delay(2000);
  }
      
  if(manda){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enviando");
    lcd.setCursor(0,1);
    lcd.print("Bom Trabalho");
    delay(2000);
    if (client.connect(serv, 80)) {
      erro = false;
      client.print("GET /ethernet/data.php?"); //Connecting and Sending values to database
        client.print("OS1=");
        client.print(OS);
        client.print("&OS2=");
        client.print(OS1);
        client.print("&OS3=");
        client.print(OS2);
        client.print("&OS4=");
        client.print(OS3);
        client.print("&funcao=");
        client.print(funcao);
        client.print("&cracha=");
        client.println(cracha);
        client.stop();
        delay(1000);
        manda = false;
        vai = -1; 
        lcd.clear();
    }
     else{
      erro = true;
      while(erro){
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("ERRO-ERRO-ERRO");
        lcd.setCursor(0,1);
        lcd.print("ERRO-ERRO-ERRO");
        delay(500);
      }
    }
  }
  if(cracha == 69){
    if(finaliza69 == true){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Finalizando - F");
      lcd.setCursor(0,1);
      lcd.print("Bom Trabalho");
      delay(2000);
      if (client.connect(serv, 80)) {
        erro = false;
        client.print("GET /ethernet/data.php?"); //Connecting and Sending values to database
          client.print("OS1=");
          client.print(1);
          client.print("&OS2=");
          client.print(1);
          client.print("&OS3=");
          client.print(1);
          client.print("&OS4=");
          client.print(1);
          client.print("&funcao=");
          client.print(1);
          client.print("&cracha=");
          client.println(cracha);
          client.stop();
          delay(1000);
          manda = false;
          vai = -1; 
          lcd.clear();
      } 
      trancado69 = false;
      finaliza69 = false; 
    }
  }
  
  if(cracha == 60){
    if(finaliza60 == true){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Finalizando - A");
      lcd.setCursor(0,1);
      lcd.print("Bom Trabalho");
      delay(2000);
      if (client.connect(serv, 80)) {
        erro = false;
        client.print("GET /ethernet/data.php?"); //Connecting and Sending values to database
          client.print("OS1=");
          client.print(0);
          client.print("&OS2=");
          client.print(0);
          client.print("&OS3=");
          client.print(0);
          client.print("&OS4=");
          client.print(0);
          client.print("&funcao=");
          client.print(0);
          client.print("&cracha=");
          client.println(cracha);
          client.stop();
          delay(1000);
          manda = false;
          vai = -1; 
          lcd.clear();
      } 
      trancado60 = false;
      finaliza60 = false; 
    }
  }
}

void pega_OS(){
    while(a == true){
      char key = keypad.getKey();
      if(key){
    
        if(key == '#'){
        x = 0;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Limpando");
        delay(500);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Digita a OS");
        }

        if(key != '#'){
          lcd.setCursor(x,1);
         
          if(x == 0){OS = key;lcd.print(OS);}
          if(x == 1){OS1 = key;lcd.print(OS1);}
          if(x == 2){OS2 = key;lcd.print(OS2);}
          if(x == 3){OS3 = key;lcd.print(OS3);vai = 2; a = false;delay(2000);}
          x++;
        }
      }
    }
}

void pega_funcao(){

  a = true;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Funcao");
  while(a == true){
    char key = keypad.getKey();
    if(key){
      funcao = key;
      pega_nome_funcao();
      lcd.setCursor(0,1);
      lcd.print(funcao);
      lcd.setCursor(2,1);
      lcd.print(nome_funcao);
      delay(2000);
      manda = true;
      a = false;
      vai = 0;
    }
  }
}
void confere69(){
    if(trancado69 == true){
      finaliza69 = true;
    }
    else if(trancado69 == false){
      vai = 1;
      a = true;
      x = 0;
      trancado69 = true;
  }
}

void confere60(){
  if(trancado60 == true){
    finaliza60 = true;
  }
  else if(trancado60 == false){
    vai = 1;
    a = true;
    x = 0;
    trancado60 = true;
  }
}

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 = "- servico";
      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;
  }
}

I'm not sure if I understand the question; is the below what you want to achieve?

You want to send data to a database on a PC (current code) and you want to communicate with an Arduino-based webserver?

Ja consegui, deu tudo certo

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