Skip to end of metadata
Go to start of metadata

After adding an OMA binding with DeviceHub, you can use LoopFlows to send data from connected sensors and devices through the OMA object binding.

Example Flow

To add a flow for sending sensor data through an OMA object:

  1. Connect an Inject node, a Function node, and a Serial out node. Connect a Serial in node, a Function node, and a DataHub publish node separately from the first three nodes.

    The nodes should be connected like the below screenshot:



  2. Double-click either serial node. Click to create a configuration for the connected device. Make sure that the Baud rate and Port name match the device information. Assign this configuration to each serial node in the flow.



  3. Double-click the Inject node. Select String from the drop-down and enter a string message that will request the desired data from it. Here I am using F to request temperature data in Fahrenheit from the sensor. Set an interval to have the node automatically request data after each interval.



  4. Double-click the upper Function node to ensure that messages to the sensor are properly formatted. In the following code, I add a carriage return to the message to ensure that the device reads it properly.

    msg.payload = msg.payload + "\r"; // Add a carriage return to the output.
    return msg;
  5. Check DeviceHub > Tags to get the OMA object values to use. Click Update Binding under the Actions menu to review the OMA binding of the IPSO tag to publish to.



  6. Return to Flows. Double-click the lower Function node and write code to create the OMA object to send the data from the device with. Enter the same information that you see for the OMA binding in DeviceHub.

    var val = parseFloat(msg.payload); // Gets the temperature in degrees Fahrenheit from the string sent by the device.
    
    var obj =
    {
        "timestamp":Math.floor(Date.now() / 1000), // Creates a timestamp to send with the OMA object.
        "values": 
        [
            {
                "objectId":3303, // Sets the object id as 3.
                "instanceId":1, // Sets the instance id as 1.
                "resourceId":5700, // Sets the resource id as 5700.
                "datatype":"Float", // Sets the data type to be a floating point number.
                "value":val // Puts the temperature value as the value to send in the OMA object.
            }
        ]
    };
       
    msg.payload = obj;
    
    return msg;
  7. Return to DeviceHub > Tags. Copy the IPSO topic from the tag with the OMA binding.



  8. Return to Flows. Double-click the DataHub Publish node and paste the IPSO tag into the node.



  9. Click Done. Click Save.

To View the results of the flow. Check the LoopCloud Explore tab for the device, as described in the DeviceHub OMA Binding page.

  • No labels