Hello,
I’m having a problem publishing a String using IFTTT. I believe the problem lies in converting the char array to a string but I’m not sure (am I doing this correctly?). The “Error” publish sends me an email with the String in the 2nd parameter. The “Data” Publish fills a row to a google spreadsheet with the String in the 2nd parameter. UnsentData.txt is a file that lines of data were written to previously when they failed to send (in case of a Wi-fi outage). I can to send lines of data to the spreadsheet with wi-fi by just having the second parameter be the same String I would write to the SD if it didn’t send. I don’t get any emails past “Some data still needs to be sent…” and nothing is saved onto the spreadsheet.
Thanks!
File dataToBeSent = SD.open("UnsentData.txt", FILE_WRITE);
if(dataToBeSent)
{
Particle.publish("Error","Some data still needs to be sent...");
delay(1000);
while(dataToBeSent.peek()!=-1) //continue until .peak() returns -1 (end of file)
{
val[i]=dataToBeSent.read();
i++;
if (val[i-1]=='\n')
{
val[i]='\0';
v=String(val);
if (Particle.publish("Error", v))
{
delay(1000);
Particle.publish("Error", "The Error call worked for the unsent data");
}
if(Particle.publish("Data", v)) //Send the unsent value to google spreadsheet
{
delay(1000);
Particle.publish("Error", "Unsent data sent");
//SD.remove("UnsentData.txt"); //Destroy the "to be sent" file if the data sent
}
v="";
i=0;
char val[40];
delay(1000);
}
}
dataToBeSent.close();
}