Receive reported updates from device twins from a backend app with mqtt

Senuda Jayalath 41 Reputation points

I want to know how to receive reported messages sent by IOT devices to the cloud from my backend app . From my research I have found out the way to do it is with the function twin.get( ){ } . But I cant exactly figure out how to write that function. Please help me with his .

I want the code in javascript. Thanks in advance

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,108 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,026 Reputation points

    Hello @Senuda Jayalath ,

    You may be interested in looking at this sample app.
    Download the sample Node.js project from and extract the ZIP archive.

    Make sure that port 8883 is open in your firewall. The device sample in this tutorial uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments.

    Please have a look at this section Process reported properties

    A back-end application accesses the current reported property values for a device through the device twin. The following snippet shows you how the back-end application reads the reported property values for the simulated device:

    // Display the reported properties from the device  
    function printReportedProperties(twin) {  
      console.log("Last received patch: " +;  
      console.log("Firmware version: " +;  
      console.log("Fan status: " +;  
      console.log("Min temperature set: " +;  
      console.log("Max temperature set: " +;  

    Please let us know if you need further help in this matter.

    1 person found this answer helpful.