[Fixed] Webhooks callbacks are not reliable!

Hi @jeiden Thanks for the quick reply, the new particle CLI is installed and particle webhook list returns the following (it’s a temperature log):
Found 1 hooks registered

1.) Hook #555a23f22ccd38832b250421 is watching for "get_salon_temp"
    and posting to: http://api.thingspeak.com/channels/20769/feeds/last?key=5QS7Q31I9CR1DFU8
    created at 2015-05-18T17:40:02.333Z

Exact FW follows:

void setup() {
    //  particle serial monitor
    Serial.begin(115200);

    // Lets listen for the hook response
    Spark.subscribe("hook-response/get_salon_temp", gotSalonTemp, MY_DEVICES);

    // Lets give ourselves 10 seconds before we actually start the program.
    // That will just give us a chance to open the serial monitor before the program sends the request
    for(int i=0;i<10;i++) {
        Serial.println("waiting " + String(10-i) + " seconds before we publish");
        delay(1000);
    }

     Serial.println("Setup!");
}

void loop() {

    Serial.println("Requesting salon temp!");

    // publish the event that will trigger our webhook
    Spark.publish("get_salon_temp");

    // and wait at least 60 seconds before doing it again
    delay(60000);

}

void gotSalonTemp(const char *name, const char *data) {
    // Important note!  -- Right now the response comes in 512 byte chunks.  
    //  This code assumes we're getting the response in large chunks, and this
    //  assumption breaks down if a line happens to be split across response chunks.
    //

    String str = String(data);
    Serial.println(str);
    
    String TemperatureStr = tryExtractString(str, "field1", " C");
    Serial.println(TemperatureStr);
    
}

// Returns any text found between a start and end string inside 'str'
// example: startfooend  -> returns foo
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;
    }

    idx = idx + 5;
    return str.substring(idx + strlen(start), endIdx);
}

The FW worked yesterday, then didn’t today. I reset my Core, changed it’s name and flashed the firmware again and it looks like it’s more reliable for the moment. It works now so fingers crossed !


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy