Unit 2: Creating Data Parsing Script


As EnOS IoT and Custom is selected for the Onboarding Method when creating the Human Senor Product, this means that the devices under the product can send data in any format (for example, binary data) to EnOS Cloud.


This unit shows how to create a data parsing script to encode and decode the upstream data and how to upload it to EnOS runtime environment.


For more information, see Parsing Custom Format Data.

Creating a Parsing Script

  1. Go to Device Management > Products and click the btn_view icon for the Human Sensor Product.

  2. Click the Data Parsing tab in the Product Details page.

  3. Add a script to the Script area to process non-standard upstream data from the device. Example:

    function rawDataToJsonStr(bytes) {
     var uint8Array = new Uint8Array(bytes.length);
     for (var i = 0; i < bytes.length; i++) {
       uint8Array[i] = bytes[i] & 0xff;
     }
     return hex2str(uint8Array);
    }
    
    function hex2str(arr) {
     var str = "";
     for (var i = 0; i < arr.length; i++) {
       str += String.fromCharCode(arr[i]);
     }
     return str;
    }
    


../../_images/s2_product_parsing_script.png

Testing the Script

In order to verify the validity of the parsing script, you can test the script by using simulated data. In this tutorial, you can conver the following JSON to Hex data to use as simulated data.

  1. Convert the following JSON to Hex data.

    {
       "id": "1",
       "version": "1.0",
       "params": {
       "events": {
             "humanMoved": "target"
       },
       "time": 1635865450177
     },
     "method": "thing.event.HumanMoved.post"
    }
    


  2. Enter the converted Hex data below in the Simulated Input Data area and click Run.

    0x7b0a20202020226964223a202231222c0a202020202276657273696f6e223a2022312e30222c0a2020202022706172616d73223a207b0a2020202020202020226576656e7473223a207b0a2020202020202020202020202268756d616e4d6f766564223a20226d6f766564220a20202020202020207d2c0a20202020202020202274696d65223a20313633353836353435303137370a202020207d2c0a20202020226d6574686f64223a20227468696e672e6576656e742e48756d616e4d6f7665642e706f7374220a7d
    


  3. The JSON output will be shown in the Output Data area.


    ../../_images/s2_test_parsing_script_result.png

Next Unit

Building the Routing Rule