Hi,
I’ve been trying to figure out why the photon is crashing and rebooting, I cant for the life of me figure out what is causing it.
My code pulls some weather data using a webhook:
{
"event": "weatherU_hook",
"url": "http://api.wunderground.com/api/mykeyhere/conditions/q/AZ/Tucson.json",
"requestType": "POST",
"headers": null,
"query": null,
"responseTemplate": "{{#current_observation}}{{wind_dir}}~{{wind_mph}}~{{wind_gust_mph}}~{{precip_1hr_in}}{{/current_observation}}",
"json": null,
"auth": null,
"mydevices": true
}
My device code is:
#define HOOK_RESP "hook-response/weatherU_hook"
#define HOOK_PUB "weatherU_hook"
bool weatherGood;
int badWeatherCall;
String currentWind_dir;
float currentWind_mph = 0;
float currentWind_gust_mph = 0;
float currentPrecip_1hr_in = 0;
unsigned long uptime;
Timer timer(150000, getWeather);
void setup() {
Time.zone(-7);
delay(2000);
Spark.subscribe(HOOK_RESP, gotweatherData, MY_DEVICES);
Spark.publish(HOOK_PUB);
timer.start();
}
void loop(){
}
void getWeather() {
weatherGood = false;
Spark.publish(HOOK_PUB);
unsigned long wait = millis();
while (!weatherGood && (millis() < wait + 5000UL))
Spark.process();
delay(500);
if (!weatherGood) {
badWeatherCall++;
if (badWeatherCall > 2) {
}
}
else
badWeatherCall = 0;
}
void gotweatherData(const char *name, const char *data) {
if (strlen(data)+1 > 0){
String str = String(data);
char strBuffer[strlen(data)+1] = "";
str.toCharArray(strBuffer, strlen(data)+1); // example: "\"North~0~1.3~0.00\""
strtok(0,0);
String wind_dir = strtok(strBuffer, "\"~");
float wind_mph = atof(strtok(NULL, "~"));
float wind_gust_mph = atof(strtok(NULL, "~"));
float precip_1hr_in = atof(strtok(NULL, "~"));
currentWind_dir = wind_dir;
currentWind_mph = wind_mph;
currentWind_gust_mph = wind_gust_mph;
currentPrecip_1hr_in = precip_1hr_in;
bool weatherGood = true;
}
}
If someone could help point me in the right direction I’d be super grateful.