@clone137
frankly, I have tried using the unique device id with not much success, but that has been around getting a customized callback (e.g. to update only the device that made the request). I haven’t played around with it enough to know if it works properly with a pair of photons!
that being said, I have had success using this method, I hope you can see it in the example… adding the device ID to the response… searching for the device id in the handler… works for me:
struct deviceTime{
int Hour;
int Minute;
};
deviceTime sunrise = {6,0};
deviceTime sunset = {18,30};
String myDeviceID;
char message[60] = "No Time Values Recieved";
bool startUpFlag = true;
unsigned long myTimer = 0;
void setup()
{
myDeviceID = System.deviceID();
Particle.variable("deviceID", myDeviceID, STRING);
Particle.variable("SunriseTime", &message, STRING);
Particle.subscribe("hook-response/sun_time", sunTimeHandler, MY_DEVICES); //MY_DEVICES
char buffer[60] = "Webhook Test Begin...";
Particle.publish("pushover", String(buffer), 60, PRIVATE);
}
void loop()
{
if((millis() - myTimer > 10 * 60 * 1000UL) || startUpFlag)
{
startUpFlag = false;
Particle.publish("sun_time", "{ \"myCity\": \"Weston\", \"myState\": \"FL\" }", 60, PRIVATE);
myTimer = millis();
}
}
void sunTimeHandler(const char * event, const char * data)
{
String sunriseReturn = String(data);
char sunriseBuffer[125] = "";
sunriseReturn.toCharArray(sunriseBuffer, 125);
char thisDeviceID[25] = "";
myDeviceID.toCharArray(thisDeviceID, 25);
if (strstr(sunriseBuffer, thisDeviceID)) // Filters responses unique to this device here!!
{
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, "Florida Sunrise: %02d:%02d, Sunset: %02d:%02d", sunrise.Hour, sunrise.Minute, sunset.Hour, sunset.Minute);
Particle.publish("pushover", String(buffer), 60, PRIVATE);
strcpy (message, buffer);
}
}
with this webhook:
{
"event": "sun_time",
"url": "http://api.wunderground.com/api/getYourOwnAPI/astronomy/q/{{myState}}/{{myCity}}.json",
"requestType": "POST",
"headers": null,
"query": null,
"responseTemplate": "{{#sun_phase}}{{sunrise.hour}}~{{sunrise.minute}}~{{sunset.hour}}~{{sunset.minute}}~{{/sun_phase}}{{SPARK_CORE_ID}}~",
"json": null,
"auth": null,
"coreid": null,
"mydevices": true
}
note the {{SPARK_CORE_ID}}
in the response template