Problem writing to Mifare 1K RFID tag with SM130

Hello,

I'll preface by saying that I based my code off of Seb Mabwick's demo sketch for the SM130 and the reading I've done thus far shows that a lot of members here have big problems with his approach.

That said, I've created a script whose purpose is to assign a barcode to an RFID tag using the SM130
For some reason, it seems to be working entirely except for the write command which I dubbed "sendPayload"

The parseResponse is coming out as all 0's, which is another indicator that the command is not being successfully executed.

/*
  Barcode to Tag Associator Prototype
*/

#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);

int incomingByte = 0;
int convertedIncoming = 0;
int i = 0;
int j = 0;
int k = 0;
int bar[20];
int Str1[20];
int Str2[20];
int flag = 0;
int writeResponse[50];

void setup() {
  Serial.begin(9600);
  Serial.println("Barcode to Tag Associator");
  rfid.begin(19200);
  delay(10);
  halt();
}

void loop() {

  defineBarcodeData();
  
  Serial.println("Ready for RFID Tag");
  
  halt();
  PICCHALTED();
  selectCommand();
  parse();
  print_serial();
  authenticate();
  parseAuth();
  checkAuth();
  print_serial();
  sendPayload();
  parseResponse();
  flag = 0;
  i = 0;
  j= 0;
  k = 0;
  Serial.println("----------------------------------------");
}

void defineBarcodeData()
{
  while (i < 14)
  {
    pullBarcode();
    printArray();
  }
}

void pullBarcode()
{
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    convertedIncoming = incomingByte - 48;
    bar[i] = convertedIncoming;

    i++;
  }
}

void printArray()
{
  if (i == 14)
  {
    Serial.print("Envelope: ");
    for (int j = 5; j < 11; j++)
    {
      Serial.print(bar[j], DEC);
    }
    Serial.print("-");
    Serial.print(bar[11], DEC);
    Serial.print(bar[12], DEC);
    Serial.println(bar[13], DEC);
  }
}

void halt()
{
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
  delay(10);
}

void PICCHALTED()
{
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)2);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)76);
  rfid.write((uint8_t)225);
  delay(10);
}

void selectCommand()
{
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)131);
  rfid.write((uint8_t)132);
  delay(10);
}

void parse()
{
  while (rfid.available()) {
    if (rfid.read() == 255) {
      for (int i = 1; i < 10; i++) {
        Str1[i] = rfid.read();
      }
    }
  }
  delay(10);
}

void print_serial()
{
  if (flag > 0)
  {
    Serial.print("Tag Serial: ");
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
  }
}

void authenticate()
{
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)3);
  rfid.write((uint8_t)133);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)136);
  delay(10);
}

void parseAuth()
{
  while (rfid.available()) {
    if (rfid.read() == 255) {
      for (int i = 1; i < 6; i++) {
        Str2[i] = rfid.read();
      }
    }
  }
  delay(10);
}

void checkAuth()
{
  if (Str2[5] == 211)
  {
    Serial.println("Authentication Successful");
    flag++;
  }
  if (Str2[5] == 213)
  {
    Serial.println("Authentication Failed; This could be because no tag is present.");
  }
  delay(10);
}

void sendPayload()
{
 // if (flag > 0)
 Serial.println("Sending payload");
  {
    rfid.write((uint8_t)255);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)18);
    rfid.write((uint8_t)137);
    rfid.write((uint8_t)1);

    rfid.write((uint8_t)18);
    rfid.write((uint8_t)131);
    rfid.write((uint8_t)56);
    rfid.write((uint8_t)1);

    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
    rfid.write((uint8_t)0);
   
    rfid.write((uint8_t)57);
  }
  delay(10);
}

void parseResponse()
{
  if (flag > 0)
  {
    while (rfid.available()) {
      if (rfid.read() == 255) {
        for (int j = 1; j < 21; j++) {
          writeResponse[i] = rfid.read();
        }
      }
    }
    Serial.print("Final Parse: ");
    for (int j = 1; j < 21; j++)
    {
      Serial.print(writeResponse[i], HEX);
    }
    Serial.println(writeResponse[21], HEX);
    Serial.println("Operation Complete");
  }
  delay(10);
}

Here's the output:

Barssociator
Barcode to Tag Associator
Envelope: 128382-001
Ready for RFID Tag
Authentication Successful
Tag Serial: 60FFE1
Sending payload
Final Parse: 000000000000000000000
Operation Complete
----------------------------------------
Envelope: 128382-001
Ready for RFID Tag
Authentication Successful
Tag Serial: A7A94924
Sending payload
Final Parse: 000000000000000000000
Operation Complete
----------------------------------------
Envelope: 128382-001
Ready for RFID Tag
Authentication Failed; This could be because no tag is present.
Sending payload
----------------------------------------
Envelope: 128382-001
Ready for RFID Tag
Authentication Successful
Tag Serial: A7A94924
Sending payload
Final Parse: 000000000000000000000
Operation Complete
----------------------------------------

Obviously Sector 0 Block 1 will be written the Decimal equivalent of "18, 131, 56, 1, and the rest 0's"
Once I get the script to write to the tag successfully, I'll replace those values with bar[5-13].

No dice eh?

Mods, feel free to close this thread.
I paid a freelancer to fix it.