im having trouble with @red_car code. my module came with a worked example and I tired having it run through that example with the code but its not correctly producing the TAG ID
the example is:
02 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 07 f8 03
which when converted through ASICII: 171A9253A34830010000000000
which contains:
tag id: 1-10 byte (10 long)
country code bytes 11-14 (4 long)
171A9253A3 483 0010000000000
which should produce: country: 900 tag: 250000023921
byte buffer[30] = {0x02, 0x31, 0x37, 0x31, 0x41, 0x39, 0x32, 0x35, 0x33, 0x41, 0x33, 0x34, 0x38, 0x33, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x07, 0xf8, 0x03};
byte b;
uint8_t idx;
boolean started = false;
byte XOR;
byte inverted;
uint32_t value;
void setup() {
// Initialize serial communication at 9600 baud
Serial.begin(9600);
delay(1000);
Serial.println("start:");
}
void loop() {
// Print the contents of the buffer to Serial Monitor for verification
for (int i = 0; i < sizeof(buffer); i++) {
Serial.print(buffer[i], HEX);
Serial.print(" ");
}
Serial.println();
// Check we received the message ok. XOR checksum on bytes 01-26 should match byte 27.
XOR = buffer[1];
for (int x = 2; x <= 26; x++)
{
XOR ^= buffer[x];
}
Serial.print("Calculated checksum: ");
Serial.print(XOR, HEX);
if (XOR == buffer[27])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Check the inverted XOR checksum
inverted = ~XOR;
Serial.print("Inverted checksum: ");
Serial.print(inverted, HEX);
if (inverted == buffer[28])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Extract the card number from bytes 01 (LSB) - 10 (MSB).
value = 0;
for (int x = 10; x >= 1; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Card number: ");
Serial.println(value);
// Extract the country number from bytes 11 (LSB) - 14 (MSB).
value = 0;
for (int x = 14; x >= 11; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Country number: ");
Serial.println(value);
// Extract the Data Block from byte 15.
Serial.print("Data block: ");
Serial.println(buffer[15] - '0');
// Extract the Animal Flag from byte 16.
Serial.print("Animal flag: ");
Serial.println(buffer[16] - '0');
Serial.println("\r");
delay(100000);
}
which returns the card id: 891920753
2 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 7 F8 3
Calculated checksum: 7 (Correct)
Inverted checksum: F8 (Correct)
Card number: 891920753
Country number: 900
Data block: 0
Animal flag: 1