JSON Webhook Custom Template POST to Parse

I know this is probably something simple I’m missing but I’ve been scouring the docs and forum for the last day to no avail.

My web hook:

 {
      "eventName": "post_data",
      "url": "https://api.parse.com/1/classes/SensorData",
      "requestType": "POST",
      "headers": {
          "X-Parse-Application-Id":"xxx",
          "X-Parse-REST-API-Key":"xxx",
          "Content-Type":"application/json"
      },
      "json": {
        "ph" : "{{ph}}",
        "temperature" : "{{temperature}}"
      },
      "mydevices": true
    }

And my firmware, customized from some of the readily available examples and tutorials. Using OneWire for my DS18b20, Wire for an Atlas Scientific pH circuit:

char ph_data[48];       // 48 byte char array to hold data from ph
float celsius, fahrenheit;    // float to hold and convert data from temp

// Publish Data
  sprintf(resultStr, "%s %s", ph_data, String(fahrenheit).c_str());   

  Spark.publish("post_data", resultStr, 60, PRIVATE);
//Spark.publish("post_data", "{ \"ph\": \"ph_data\", \"temperature\": \"fahrenheit\" }", 60, PRIVATE);

With the above code, Parse creates the object and inputs blank data into the ph and temperature columns. Event Data on both Parse and Particle Dashboard shows current ph_data and fahrenheit as a single string (resultStr). Particle Dashboard shows hook-sent data as undefined.

If I switch to the commented out Spark.publish based on the Webhook Custom Template docs, Parse inputs plain text ph_data and fahrenheit, not the values they represent.

Also, if I change

      "json": {
        "ph" : "{{ph}}",
        "temperature" : "{{temperature}}"
      },

to

      "json": {
        "ph" : "{{ph_data}}",
        "temperature" : "{{fahrenheit}}"
      },

it inputs blank data to Parse, regardless of which Spark.publish I use.

can you show the event stream in a terminal using the CLI’s particle subscribe mine once you publish “post_data” ?

Yes, it displays the same as the Particle Dashboard. Post, Hook-Sent, and Hook-Response. Hook data is undefined, Post data is “{ “ph”: “ph_data”, “temperature”: fahrenheit }”

EDIT: To clarify, Post data is “3.355 79.137497” (ph and temp) if I use Spark.publish("post_data", resultStr, 60, PRIVATE); It’s “{ “ph”: “ph_data”, “temperature”: fahrenheit }” if I use Spark.publish("post_data", "{ \"ph\": \"ph_data\", \"temperature\": \"fahrenheit\" }", 60, PRIVATE);

Didn’t you mean to say this instead?

sprintf(resultStr, "{\"ph_data\": %s, \"temperature\": %s}", ph_data, String(fahrenheit).c_str());
2 Likes

Just tried that and the event value comes up null instead of the combined strings.

Edit: Nevermind, it’s actually posting properly into Parse now even though the hook-sent data shows null in terminal. By the way it was your tutorials that got me going here so thanks for those as well as this fix!

2 Likes

Hi @m9er,

Ahh sorry about that, the “hook-sent” event is to let you know that the hook was triggered and the request was started, the contents of that event are generally always null at the moment. :slight_smile:

Thanks,
David

2 Likes