So I have been thinking and messing around and read this from @ScruffR
made me think... "what about using Particle.subscribe()
and using the device's own ID" like this:
void setup()
{
myDeviceID = System.deviceID();
Particle.variable("deviceID", myDeviceID, STRING);
Particle.variable("SunriseTime", &message, STRING);
Particle.subscribe("hook-response/sun_time", sunTimeHandler, myDeviceID);
}
but, it doesn't seem to respond...
entire test code:
struct deviceTime{
int Hour;
int Minute;
};
deviceTime sunrise = {6,0};
deviceTime sunset = {18,30};
String myDeviceID;
char message[40] = "No Time Values Recieved";
void setup()
{
myDeviceID = System.deviceID();
Particle.variable("deviceID", myDeviceID, STRING);
Particle.variable("SunriseTime", &message, STRING);
Particle.subscribe("hook-response/sun_time", sunTimeHandler, myDeviceID);
}
void loop()
{
static unsigned long myTimer = 0;
if(millis() - myTimer > 60000UL)
{
Spark.publish("sun_time", "{ \"myCity\": \"Weston\", \"myState\": \"FL\" }");
myTimer = millis();
}
}
void sunTimeHandler(const char * event, const char * data)
{
String sunriseReturn = String(data);
char sunriseBuffer[40] = "";
sunriseReturn.toCharArray(sunriseBuffer, 40);
sunrise.Hour = atoi(strtok(sunriseBuffer, "\"~"));
sunrise.Minute = atoi(strtok(NULL, "~"));
sunset.Hour = atoi(strtok(NULL, "~"));
sunset.Minute = atoi(strtok(NULL, "~"));
char buffer[60] = "";
sprintf(buffer, "Sunrise: %02d:%02d, Sunset: %02d:%02d", sunrise.Hour, sunrise.Minute, sunset.Hour, sunset.Minute);
Particle.publish("pushover", String(buffer), 60, PRIVATE);
strcpy (message, buffer);
}
though the hook does fire and of course the myDeviceID
is correct in the response (redacted):
{"name":"sun_time","data":"{ "myCity": "Weston", "myState": "FL" }","ttl":"60","published_at":"2015-08-29T13:21:21.314Z","coreid":"myCoreID"}
{"name":"hook-response/sun_time/0","data":""7~00~19~44~"","ttl":"60","published_at":"2015-08-29T13:21:24.500Z","coreid":"undefined"}
but you can see that I get a:"coreid":"undefined"
argument returned in the response...
Am I missing something here?
webhook:
{
"event": "sun_time",
"url": "http://api.wunderground.com/api/myApiKey/astronomy/q/{{myState}}/{{myCity}}.json",
"requestType": "POST",
"headers": null,
"query": null,
"responseTemplate": "{{#sun_phase}}{{sunrise.hour}}~{{sunrise.minute}}~{{sunset.hour}}~{{sunset.minute}}~{{/sun_phase}}",
"json": null,
"auth": null,
"coreid": "{{SPARK_CORE_ID}}",
"mydevices": true
}