Particle Core stops emitting events

Hey all,

I’m attempting to build an RFID scanner using the Particle Core. There seems to be some inconsistent issues with emitting events.

After booting the device it’ll be able to emit events when a fob is tapped, but occasionally after some amount of time not being used then it won’t emit events. After resetting the device it then begins to work again.

Here’s the code I’m working with:

// This #include statement was automatically added by the Particle IDE.
#include <SparkJson.h>

// This #include statement was automatically added by the Particle IDE.
#include <MFRC522.h>


// This #include statement was automatically added by the Particle IDE.

// This #include statement was automatically added by the Particle IDE.
#include <MFRC522.h>

#define SS_PIN      A2
#define RST_PIN     D3

int red = D0;
int blue = D1;
int green = D2;

MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.

void myHandler(const char *event, const char *data) {
  
  // Handle the integration response
  digitalWrite(blue, LOW);
  String str = String(data);
  Serial.println(str);

  if (str == "true") {
      digitalWrite(green, HIGH);
      delay(1000);
      digitalWrite(green, LOW);
  } else {
      digitalWrite(red, HIGH);
      delay(1000);
      digitalWrite(red, LOW);
  }
}

void setup() {
    Serial.begin(9600);	// Initialize serial communications with the PC
	Serial.println("Hello!");
    
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    
    mfrc522.PCD_Init();

    Particle.subscribe("hook-response/rfid_scan", myHandler, MY_DEVICES);
    Particle.publish("device_setup", "Device has booted", 60, PRIVATE);
    
    pinMode(red, OUTPUT);
    pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
}

void loop() {

    // Look for new cards, if nothing found, quit
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
    	return;
    }
    
    // Select one of the cards, if nothing found, quit
    if ( ! mfrc522.PICC_ReadCardSerial()) {
    	return;
    }
    
    String cardID = "";
    
    for (byte i = 0; i < mfrc522.uid.size; i++) {
        cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
        cardID += String(mfrc522.uid.uidByte[i], HEX);
    }

    digitalWrite(blue, HIGH);
    Particle.publish("rfid_scan", cardID, 60, PRIVATE);
    Serial.println(cardID);
    mfrc522.PICC_HaltA();
}

As you can see I’m not using any sleeps, so any ideas on what I might be doing wrong?

I don't see any code that makes sure your project is adhering the publishing rate limit of 1/sec.

If your code doesn't Particle.publish() will be muted until your device stops chattering for at least 4sec.

This fact is documented here
https://docs.particle.io/reference/firmware/photon/#particle-publish-

I’ll look into limiting the publish, I guess you are talking about the loop() function. This wouldn’t be affecting the the situation though as it will happen after the device has been left alone for an extended period of time.

Cheers

@dexter, have you validated that the card reader is not going to standby mode and not operating as expected?

1 Like

No I haven’t, I wasn’t aware that the card reader could go to standby mode.
Is there some documentation you’d recommend for me to look at? :thinking:

Thanks again

@dexter, the comment was a hunch not based on any documentation research. Are you seeing the cardID being printed on the serial console when you scan a card and it is not being published? Also, which version of firmware are you running on your Core?

2 Likes

I’ve got the serial port printing out to my Mac, so when it next stops sending events I’ll post an update here.
I see device OS: 0.7.0. It also seems to be a Photon not a Core, my bad! I didn’t originally set this up.

@peekay123

1 Like