Custom JSON with Azure Integration?

I’m working with the Azure IoT Hub integration, and have my Electron successfully pumping messages through the Particle cloud to my hub.
I’d like to expand on the data I’m sending, to include telemetry properties, and other metadata from code. Right now I see whatever string I send ends up being the “data” property value in the JSON, on the IoT Hub. However it is a quoted string, precluding me from sending in a serialized JSON object as data.
So I saw the “Advanced Settings” section of the integration definition, and see the “SEND CUSTOM JSON” feature, which says I can format my own JSON object. There is a link to “our docs.” which talks about WebHooks.

Ultimately, what’s unclear to me is how I can pass through one or more properties from my code, into this custom JSON structure. The WebHooks documentation seems to imply the JSON object is static and not parameterized by the Particle.publish() method.

Can anyone provide more information on how to use this custom JSON feature of the integration?

Thanks

-John

I figured it out. The “CUSTOM JSON”, is actually a template which uses placeholders (called ‘variables’) surrounded by double braces {{ }} (similar to AngularJS bindings).
When a template is fashioned in this way the “data” parameter of the .publish() method is now interpreted as a JSON object, with the property names matching the placeholders in the template. When a match is made, the placeholder is replaced with the value of the corresponding property in the JSON string from code.
This link provides a concise example, however it is discussing Webhooks.
https://docs.particle.io/reference/webhooks/#custom-variables
One tip: when a template is used, it replaces the entire payload, so if you liked the “device_id” and “published_at”, you have to add those to your template and utilize the pre-defined variables PARTICLE_DEVICE_ID and PARTICLE_PUBLISHED_AT respectively.

-John

3 Likes

Thanks for posting your solution!