Hi, I have this code working almost perfect, I took parts from other various projects to make this. The RFID scan however only capture the first 8 characters of the RFID and I am not sure why. I think it may have something to do with the buffer and size commands. I know it should be 10 characters because I scan the same RFID with a raspberry pi setup and I get exactly the same thing except an additional 2 letters at the end.
Any thoughts
thanks
Here is the code
*/
#include
#include
#include "MFRC522.h"
#include
/* wiring the MFRC522 to ESP8266 (ESP-12)
RST = GPIO5
SDA(SS) = GPIO4
MOSI = GPIO13
MISO = GPIO12
SCK = GPIO14
GND = GND
3.3V = 3.3V
*/
#define RST_PIN 5 // RST-PIN für RC522 - RFID - SPI - Modul GPIO5
#define SS_PIN 4 // SDA-PIN für RC522 - RFID - SPI - Modul GPIO4
char message_buff[200];
const char *ssid = "xxx"; // change according to your Network - cannot be longer than 32 characters!
const char pass = "xxxxx"; // change according to your Network
const char mqtt_server = "xxxx";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(115200); // Initialize serial communications
delay(250);
Serial.println(F("Booting...."));
client.setServer(mqtt_server, 1883);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
WiFi.begin(ssid, pass);
int retries = 0;
while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) {
retries++;
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println(F("WiFi connected"));
}
Serial.println(F("Ready!"));
Serial.println(F("======================================================"));
Serial.println(F("Scan for Card and print UID:"));
}
byte ActualUID[6];
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(100);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(100);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
//Serial.println();
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte buffer, byte bufferSize) {
String uid;
String rfidUid = "";
for (byte i = 0; i < bufferSize; i++) {
// Serial.print(buffer < 0x10 ? " 0" : " ");
_ // Serial.print(buffer, HEX);_
_// Serial.println(msg);_
_// Serial.print(buffer, HEX);
uid = uid + String(buffer, HEX);
ActualUID=mfrc522.uid.uidByte;
//Serial.println(uid);
rfidUid += String(mfrc522.uid.uidByte < 0x10 ? "0" : "");
rfidUid += String(mfrc522.uid.uidByte, HEX);
}
if (!client.connected()) {
}
client.loop();
// long now = millis();
// if (now - lastMsg > 2000) {
// lastMsg = now;
// ++value;
// snprintf (msg, 75, "This is msg store #%ld", value);
// Serial.print("Publish message: ");
// Serial.println(msg);
Serial.print("Attempting MQTT connection...");
if (client.connect("arduinoClient", "xxx", "xxxxx"))
//client.publish("outTopic", "test" );_
// rfidUid.toCharArray(message_buff, rfidUid.length() + 0);
uid.toCharArray(message_buff, 20);
client.publish("outTopic", message_buff);
_ Serial.println("UID is:");
Serial.println(uid);
Serial.println(rfidUid);
delay(500);
} *_