0
votes

I would like to receive IOT Hub messages from an endpoint. With client side Javascript and REST.

I used this article https://msdn.microsoft.com/nl-nl/library/mt590786.aspx for creating the URL.

This is my code:

function readIOTHub()
{
  $.getJson("https://MyIOTHub.azure-devices.net/devices/device1/messages/devicebound?api-version=2016-02-03", function(result)
  {
    alert(result);
  });
}

But my Request is not receiving any messages. Does someone know how to receive messages from IOT Hub, with Javascript REST?

2
curl/node.js example for Azure IoT Central github.com/Azure/iot-central-firmware/tree/master/HttpOnly/Bash .. Basically, the sample shows you the authentication and sending event via HTTP request to Azure IoT Hub and Azure IoT DPSOzzz

2 Answers

0
votes

I don't think this is currently possible, first because, from what I see, Azure IoT hub REST API does not issue CORS requests (i.e. they don't write in the CORS header access-control-allow-origin), so your JS client can't access it from within the browser.

0
votes

You might want to take a look at the Node.js sdk for the IoT hubs, but then again this is in the context of Node.js.

If you are ok with node.js, it becomes much simpler.

Hope this helps!

Mert