I use an electron with firmware 0.7.0 to collect data offline. It connects every hour to the cloud and publishes the collected data as encoded binary (Z85) in the events data string. Then I use a Webhook to forward the data to my server where the event data string is decoded and stored into a database. It is important that I do not loose any event data therefore my device code retries a Particle.publish() if it returns false.
void publishMessage(const char* message) {
int republishLimit = 10;
bool ack = false;
while(!ack) {
ack = Particle.publish(mEventName, message, WITH_ACK);
if(!ack) {
republishLimit--;
if(republishLimit <= 0) {
Log.error("republish limit reached => skip message!");
return;
}
Log.warn("publish failed => sleep and try to re-publish");
Particle.process();
delay(1000);
Particle.process();
}
}
}
I now see on my server that sometimes I get duplicated data because the same data is received more than once. I see that I receive multiple requests from the webhook with same data but another published_at
time. Therefore I concluded that the webhook is sometimes triggered even though Particle.publish() returned false on the device side.
I did not expect this.
So my question is:
Is this expected behavior and I need to add additional checks/means to my server code to avoid duplicated data or is this considered a bug of Particle.publish()/Webhooks and should be fixed in Particle firmware and/or cloud?
Thanks and regards
Franz