SD card reader with publish

Dear all,

I’would like to publish on the cloud a basic text file (10 lines) who is stored inside a SD card (in .txt format) on the cloud using an Electron. I’m using the SdFat library.

Basically, I would like to change the Serial by Particle.publish() on the code just bellow:

myFile = SD.open(“test.txt”);
if (myFile) {
Serial.println(“test.txt:”);
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();

Thank you in advance for your help.

Particle.publish() has its limitations.
You can only publish at an average rate of 1 event per second and the payload for each publish is limited to 255 characters.
If that is OK for you, you should collect your single bytes you get with myFile.read() into a char[] buffer and then publish the content of that buffer in one go.

1 Like