All, I have been happily using the WebSockets feature for some time now and I have one issue which I need help tracking down. I have seven devices which are programmed to connect at the top of the hour and report data to Ubidots. I use the device ID in the name of the WebHook and subscription so there does not seem to be any issue with keeping the hooks and responses straight.
char responseTopic[125];
String deviceID = System.deviceID();
deviceID.toCharArray(responseTopic,125);
Particle.subscribe(responseTopic, UbidotsHandler, MY_DEVICES); // Subscribe to the integration response event
I have read other posts about this issue and heard there is a 5 second timeout for a response from the web service (in my case Ubidots). I asked @aguspg about this and he looked up the Pingdom monitoring from this timeframe and their max response time was 1.19 seconds.
Here are the functions that call and subscribe to the web hook:
void sendEvent()
{
char data[256]; // Store the date in this character array - not global
snprintf(data, sizeof(data), "{\"hourly\":%i, \"daily\":%i,\"battery\":%i, \"temp\":%i, \"resets\":%i}",hourlyPersonCount, dailyPersonCount, stateOfCharge, temperatureF,resetCount);
Particle.publish("Ubidots-Hook", data, PRIVATE);
hourlyPersonCountSent = hourlyPersonCount; // This is the number that was sent to Ubidots - will be subtracted once we get confirmation
currentHourlyPeriod = Time.hour(); // Change the time period
dataInFlight = true; // set the data inflight flag
}
void UbidotsHandler(const char *event, const char *data) // Looks at the response from Ubidots - Will reset Photon if no successful response
{
// Response Template: "{{hourly.0.status_code}}"
if (!data) { // First check to see if there is any data
Particle.publish("Ubidots Hook", "No Data");
return;
}
int responseCode = atoi(data); // Response is only a single number thanks to Template
if ((responseCode == 200) || (responseCode == 201))
{
Particle.publish("State","Response Received");
dataInFlight = false; // Data has been received
}
else Particle.publish("Ubidots Hook", data); // Publish the response code
}
So, here is my question. If I am not getting ESOCKETTIMEDOUT from a slow response, could it be from multiple Electrons using the same Webhook at the same time? Is there a limit here which might require me to either create more web hooks or stagger the top-of-the-hour reporting?
Why this matters: When the web hook is sent, and there is an ESOCKETTTIMEDOUT, it is resent. Ubidots had received the first and second hooks and creates two data entries as you can see below. I would like to eliminate this duplicative data.
I am providing the screen shots from the activity log and the console output if there is more to the story in the data. Please let me know if you need to see more.
event: Ubidots-Hook
data: {"data":"{\"hourly\":91, \"daily\":934,\"battery\":82, \"temp\":75, \"resets\":0}","ttl":60,"published_at":"2017-11-02T21:59:36.468Z","coreid":"4f0031000251353337353037"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T21:59:36.495Z","coreid":"particle-internal"}
event: 4f0031000251353337353037_Ubidots-Hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T21:59:37.373Z","coreid":"particle-internal"}
event: Ubidots
data: {"data":"Success","ttl":60,"published_at":"2017-11-02T21:59:38.093Z","coreid":"4f0031000251353337353037"}
event: weatherU_hook
data: {"data":"null","ttl":60,"published_at":"2017-11-02T22:00:00.942Z","coreid":"37003e001447343339383037"}
event: hook-sent/weatherU_hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:00.990Z","coreid":"particle-internal"}
event: hook-response/weatherU_hook/0
data: {"data":"2~0~3~0~4~0~5~0~","ttl":60,"published_at":"2017-11-02T22:00:01.227Z","coreid":"particle-internal"}
event: AquaMaster_hook
data: {"data":"{\"Moisture\":494, \"Watering\":0, \"key1\":\"Not Time\", \"SoilTemp\":21}","ttl":60,"published_at":"2017-11-02T22:00:01.348Z","coreid":"37003e001447343339383037"}
event: hook-sent/AquaMaster_hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:01.384Z","coreid":"particle-internal"}
event: Ubidots-Hook
data: {"data":"{\"hourly\":11, \"daily\":66,\"battery\":79, \"temp\":71, \"resets\":0}","ttl":60,"published_at":"2017-11-02T22:00:01.602Z","coreid":"30005d001851353338363036"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:01.679Z","coreid":"particle-internal"}
event: Ubidots-Hook
data: {"data":"{\"hourly\":87, \"daily\":747,\"battery\":79, \"temp\":77, \"resets\":0}","ttl":60,"published_at":"2017-11-02T22:00:03.246Z","coreid":"4a003a000251363131363432"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:03.334Z","coreid":"particle-internal"}
event: Ubidots-Hook
data: {"data":"{\"hourly\":27, \"daily\":130,\"battery\":78, \"temp\":73, \"resets\":0}","ttl":60,"published_at":"2017-11-02T22:00:04.167Z","coreid":"550035000251363131363432"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:04.377Z","coreid":"particle-internal"}
event: 550035000251363131363432_Ubidots-Hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T22:00:04.901Z","coreid":"particle-internal"}
event: UbidotsHook
data: {"data":"Success","ttl":60,"published_at":"2017-11-02T22:00:05.631Z","coreid":"550035000251363131363432"}
event: hook-error/AquaMaster_hook/0
data: {"data":"ESOCKETTIMEDOUT","ttl":60,"published_at":"2017-11-02T22:00:06.601Z","coreid":"particle-internal"}
event: hook-error/Ubidots-Hook/0
data: {"data":"ESOCKETTIMEDOUT","ttl":60,"published_at":"2017-11-02T22:00:06.893Z","coreid":"particle-internal"}
event: hook-error/Ubidots-Hook/0
data: {"data":"ESOCKETTIMEDOUT","ttl":60,"published_at":"2017-11-02T22:00:08.537Z","coreid":"particle-internal"}
event: hook-sent/AquaMaster_hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:31.379Z","coreid":"particle-internal"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:31.648Z","coreid":"particle-internal"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:33.280Z","coreid":"particle-internal"}
event: 37003e001447343339383037_AquaMaster_hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T22:00:33.332Z","coreid":"particle-internal"}
event: AquaMaster
data: {"data":"Success","ttl":60,"published_at":"2017-11-02T22:00:33.466Z","coreid":"37003e001447343339383037"}
event: 30005d001851353338363036_Ubidots-Hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T22:00:34.413Z","coreid":"particle-internal"}
event: UbidotsHook
data: {"data":"Success","ttl":60,"published_at":"2017-11-02T22:00:36.381Z","coreid":"30005d001851353338363036"}
event: 4a003a000251363131363432_Ubidots-Hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T22:00:37.223Z","coreid":"particle-internal"}
event: Ubidots
data: {"data":"Success","ttl":60,"published_at":"2017-11-02T22:00:40.770Z","coreid":"4a003a000251363131363432"}
event: spark/status
data: {"data":"online","ttl":60,"published_at":"2017-11-02T22:00:49.217Z","coreid":"340040000251363131363432"}
event: Ubidots-Hook
data: {"data":"{\"hourly\":47, \"daily\":357,\"battery\":83, \"temp\":68, \"resets\":1}","ttl":60,"published_at":"2017-11-02T22:00:50.657Z","coreid":"340040000251363131363432"}
event: hook-sent/Ubidots-Hook
data: {"data":"","ttl":60,"published_at":"2017-11-02T22:00:50.695Z","coreid":"particle-internal"}
event: State
data: {"data":"Waiting for Response","ttl":60,"published_at":"2017-11-02T22:00:50.926Z","coreid":"340040000251363131363432"}
event: 340040000251363131363432_Ubidots-Hook/0
data: {"data":"201","ttl":60,"published_at":"2017-11-02T22:00:51.334Z","coreid":"particle-internal"}
event: State
data: {"data":"Response Received","ttl":60,"published_at":"2017-11-02T22:00:52.198Z","coreid":"340040000251363131363432"}
event: State
data: {"data":"Idle","ttl":60,"published_at":"2017-11-02T22:00:52.656Z","coreid":"340040000251363131363432"}
event: State
data: {"data":"Counting","ttl":60,"published_at":"2017-11-02T22:01:09.198Z","coreid":"340040000251363131363432"}
Thanks,
Chip