Azure IoT Function to Post Data to Particle Cloud


#1

I am very new to Azure IoT Hub and it has proven difficult to find resources for using Particle with Azure IoT Hub. I am looking to make an Azure function that sends data (device, event name, event data) to the Particle Cloud. This data would then be analyzed by the appropriate device and the device would do something with that data. I believe I have the Particle code worked out (I am currently using Particle.subscribe to retrieve the data, but I could switch to Particle.function, if necessary); I just need assistance on the Azure function portion. Has anyone made an Azure function that does this or know what exactly is needed to accomplish this?

I followed this workshop, but it looks to be outdated as I don’t find most of the options in Azure. It looks like JavaScript is no longer available in the Azure function development environment. .CSX is the only option I can find.


#2

I have actually found the solution to this. I hope this helps someone in my position. I used an Azure logic app instead of a function app. I have not added any dynamic data, but plan to in the future. Below is how to do it.

Before starting the Azure part:
Create a Particle.function("<your_function_name>", <your_handler>) instance in void setup()
Retrieve your access token by going to the Particle Web IDE and clicking on the settings icon on your currently uploaded firmware.
Retrieve your device id in the Particle Console.

Add your desired trigger as the first step.

Add an HTTP action with the following configuration:
URI: https://api.particle.io/v1/devices/<device_id>/<your_function_name>?access_token=<your_access_token>

Headers (key, value):
Connection, keep-alive
Content-Type, application/json

Queries: none

Body:
{
“<your_function_name>”: “<value_to_send>”
}

Authentication: None

Let me know if you have any questions.


#3

Hi, I work with Microsoft Azure from time to time and I find that getting to the exact resource you need for Azure functions in general is tough, let alone anything for Particle.
I have never done what you wanted, unfortunately.

I think Javascript and its older brother Typescript are going strong in Azure functions.
You can develop in either of them from VS Code with the help of this extension. I started with that flow recently and all I can say is that is amazing, although a tough ride.

The JavaScript dev guide for Azure functions is here. Right here you can find the one for Typescript.

Cheers,
Gustavo.