I am trying to get temperature data for my area. I followed the weather example from here:
https://docs.particle.io/guide/tools-and-features/webhooks/#your-first-webhook
What I’ve done:
I created the webhook. I checked it was created using “particle webhook list”.
I subscribed to my webhooks using “particle subscribe mine” and then from another terminal called the webhook uisng “particle publish get_weather”.
I can see the webhook getting called every single time reliably with the weather data I expect.
I also see the same activity in the Dashboard. This gives me confidence that the webhook work well and works every time.
Then, I copied and pasted the code from the example and flashed it into my core. I connected to the serial port to see activity.
The issue is that periodically, the core will lose connection and start blinking cyan just before calling the webhook. This keeps happening more often than not. I have see it blink red every now and then…
My wifi connection is fine; I’ve never had issues with the core on my network. I’ve had a core running continuously for a long time without issue displaying indoor temperature. As soon as I add a call for this webhook to the code, it starts to disconnect over and over. I was someone suggest to rename the webhook to something other than get_weather but that didn’t help.
This is from the Dashboard. You can see how it disconnects after or before every call. The computer displaying the dashboard is on the same wifi network so there is no doubt that wifi works.
This is the code running on the core:
void setup() {
Serial.begin(115200);
Spark.subscribe("hook-response/get_weather", gotWeatherData, MY_DEVICES);
for(int i=0;i<10;i++) {
Serial.println("waiting " + String(10-i) + " seconds before we publish");
delay(1000);
}
}
void loop() {
Serial.println("Requesting Weather!");
Spark.publish("get_weather");
delay(60000);
}
void gotWeatherData(const char *name, const char *data) {
String str = String(data);
String tempStr = tryExtractString(str, "temp", "pressure");
if (tempStr != NULL) {
Serial.println("The temp is: " + tempStr + String(" *F"));
}
String tryExtractString(String str, const char* start, const char* end) {
if (str == NULL) {
return NULL;
}
int idx = str.indexOf(start);
if (idx < 0) {
return NULL;
}
int endIdx = str.indexOf(end);
if (endIdx < 0) {
return NULL;
}
return str.substring(idx + strlen(start), endIdx);
}
Has anyone experienced this behavior? Is there anything I’m clearly doing wrong here? I’m kind of stuck on this issue so any help would be appreciated. Thanks.