Skip to content

Bad mojo. EOF found reading column header. ERROR: You must read the columns first! #86

@xIceFox

Description

@xIceFox

Hello,
I do a project where I read RFID Card System to check how long people are on a event. My Arduino is the MySQL Client, which reads the RFID Cards and call procedures on the SQL Server.
Im using the MySQL Connector to run stored Procedures in MySQL. At the End of the Procedure in MySQL I do:

Select "Successful"
or when the Procedure crashes:
Select "Error"

Now I want to read this with Basic Select.

The Problem is:
The First time I do the Basic Select, it works fine. I get the Information of the Procedure instantly.

The Second Time I do the Basic Select, I get an empty Line back.

The Third Time I do the Basic Select, I get an Bad mojo. EOF found reading column header. ERROR: You must read the columns first!.

I can post my Serial Monitor here:

22:55:15.378 -> Connecting...
22:55:17.623 -> Connected to server version 8.0.14
22:59:30.872 -> Modus: Anmelden
22:59:32.067 -> Gelesene UID: 7A 2E 8C BB
22:59:32.615 -> call sas.Anmeldung('7A 2E 8C BB',1);
22:59:32.719 -> Successful
22:59:32.719 -> Anmeldung abgeschlossen :)
22:59:34.122 -> Gelesene UID: 7A 2E 8C BB
22:59:34.666 -> call sas.Anmeldung('7A 2E 8C BB',1);
22:59:35.555 -> 
22:59:35.555 -> Anmeldung abgeschlossen :)
22:59:36.810 -> Gelesene UID: 7A 2E 8C BB
22:59:37.355 -> call sas.Anmeldung('7A 2E 8C BB',1);
22:59:37.390 -> Bad mojo. EOF found reading column header.
22:59:37.424 -> ERROR: You must read the columns first!
22:59:37.459 -> 
22:59:37.459 -> Anmeldung abgeschlossen :)

I don't know why, but when I reset the Arduino, or I reconnect to the Server with the SoftReset, the first time it will work. The Problem is, that I haven't the time to soft reset my Arduino every time, because there are many people trying to get into this event.

My code is here:

#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

#include <SPI.h>
#include <MFRC522.h>


#define RST_PIN   5
#define SS_PIN    53


IPAddress server_addr(I will hide this for security reasons :D);
byte mac_addr[] = {I will hide this for security reasons :D };
char user[] = "I will hide this for security reasons :D";
char password[] = "I will hide this for security reasons :D";

EthernetClient client;
MySQL_Connection conn((Client *)&client);

MFRC522 mfrc522(SS_PIN, RST_PIN);

int GID = 1;
char query[128];
char SQLQueryAnmeldung[] = "call sas.Anmeldung('%s',%d);";
char SQLQueryAbmeldung[] = "call sas.Abmeldung('%s',%d);";
String Modus;


void setup() {
  pinMode(30, INPUT);
  pinMode(31, INPUT);
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(26, OUTPUT);
  Serial.begin(9600);

  SPI.begin();
  mfrc522.PCD_Init();

  Ethernet.begin(mac_addr);
  Serial.println("Connecting...");
  if (conn.connect(server_addr, 3306, user, password)) {
    delay(500);
    digitalWrite(26, LOW);
    digitalWrite(24, HIGH);
    digitalWrite(22, LOW);
  }
  else {
    Serial.println("Connection failed.");
    digitalWrite(26, HIGH);
    digitalWrite(24, LOW);
    digitalWrite(22, LOW);
  }
}


void loop() {

  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ) {
    if (Modus == "Anmeldung") {
      SQLAnmeldung(ReadTag());
      digitalWrite(26, LOW);
      digitalWrite(24, HIGH);
      digitalWrite(22, LOW);
    }

    if (Modus == "Abmeldung") {
      SQLAbmeldung(ReadTag());
      digitalWrite(26, LOW);
      digitalWrite(24, HIGH);
      digitalWrite(22, LOW);
    }
  }

  if (digitalRead(30)) {
    Modus = "Anmeldung";
    delay(1000);
    Serial.println("Modus: Anmelden");
  }
  if (digitalRead(31)) {
    Modus = "Abmeldung";
    delay(1000);
    Serial.println("Modus: Abmelden");
  }
}



void SQLAnmeldung(String RFID) {
  row_values *row = NULL;
  String Res = "";
  digitalWrite(26, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(22, LOW);
  delay(500);
  sprintf(query, SQLQueryAnmeldung, RFID.c_str(), GID);
  Serial.println(query);
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  cur_mem->execute(query);
  column_names *columns = cur_mem->get_columns();

  do {
    row = cur_mem->get_next_row();
    if (row != NULL) {
      Res = row->values[0];
    }
  } while (row != NULL);
  delete cur_mem;
  Serial.println(Res);
  Serial.println("Anmeldung abgeschlossen :)");
  delay(500);

}

void SQLAbmeldung(String RFID) {
  digitalWrite(26, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(22, LOW);
  delay(500);
  sprintf(query, SQLQueryAbmeldung, RFID.c_str(), GID);
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  cur_mem->execute(query);
  delete cur_mem;
  Serial.println("Abmeldung abgeschlossen :)");
}

String ReadTag() {
  String UID;
  Serial.print("Gelesene UID: ");

  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] < 0x10) {
      UID = UID + "0";
    }
    UID = UID + String(mfrc522.uid.uidByte[i], HEX);
    if (i != mfrc522.uid.size - 1) {
      UID = UID + " ";
    }
  }
  UID.toUpperCase();
  Serial.println(UID);
  mfrc522.PICC_HaltA();
  return UID;
}>

Im thankful for every help i can get :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions