Unit 4: Reporting Device Event to EnOS


After the rule is built, you can now report the device event to EnOS by establishing a connection with EnOS through the standard MQTT protocol and sending the Hex data to the specified topic using the passthrough mode.

Establishing Connection Using MQTT Protocol

To establish connection using MQTT protocol, you need to have 3 things ready.

  • Client ID
  • Username
  • Password


For more information, see Establishing Connection with EnOS Cloud using the MQTT Protocol.

Client ID

The format of the client ID is {clientId}|securemode={secureMode},signmethod=sha256,timestamp={timeStamp}|.

  • clientId: The asset ID of the Human Sensor device, which can be found at the Device Management > Device Assets page.
  • secureMode: Use 2 for static authentication.
  • timeStamp: The UNIX timestamp of the current time in milliseconds.


Assuming the following are used.

  • clientId=id123456
  • securemode=2
  • timestamp=1234567890

The client ID would be: id123456|securemode=2,signmethod=sha256,timestamp=1234567890|.

Username

The format of the username is {deviceKey}&{productKey}. You can find both device key and product key at the device details page for the Human Sensor device.


For example, if the deviceKey is abcdefg and the productKey is 1234567, the username in this case would be abcdefg&1234567.

Password

The format of the password is toUpperCase(sha256({content}{deviceSecret})). Use the SHA256 algorithm to generate a new string from {content}{deviceSecret} and turn the new string into upper case letters.

  • content: It is concatenated by the clientId and its value (which is the asset ID of the device), the deviceKey and its value, the productKey and its value, and the timestamp and its value. The parameter names must be sorted in alphabetical order and concatenated without concatenation symbols.


    For example, assuming the following are used for content.

    • clientId=id123456
    • deviceKey=dK987654
    • productKey=pK11111
    • timestamp=1234567890

    The content in this case would be clientIdid123456deviceKeydK987654productKeypK11111timestamp1234567890.


  • deviceSecret: You can find the device secret at the device details page for the Human Sensor device. The value of the deviceSecret should be appended to content without any space or symbols.

Reporting Event

Once a connection is established, you can use the passthrough mode to report the device event. Using the passthough mode enables the device to send raw data such as Hex data to the cloud. EnOS will then convert the raw data to JSON format using the script defined in the Human Sensor Product.


The topic to report device event is /sys/{productKey}/{deviceKey}/thing/model/up_raw.


For more information, see Report Device Events​ (Passthrough).

Results

  1. After the event is reported, it is saved in EnOS as per the Checkpoint node to EnOS_default rule route, and you can open the Device Details page of the Human Sensor device, click Event, and view the details of the event in EnOS.


    ../../_images/s2_view_event.png


  2. An SMS will be sent to the specifed number in the SMS node.


    ../../_images/s2_sms.jpg