Quick Start: Connecting Non-Smart Devices to EnOS Cloud via Edge


This section helps you quickly get started with provisioning sub-devices and EnOS Edge to the EnOS Cloud, enabling sub-devices to connect and send data to the EnOS Cloud through EnOS Edge, and view device and EnOS Edge communication information from the EnOS Cloud.

About This Scenario

For more information about the connection scenario of this task, see “Scenario 2.1” in Device Registration Methods.

About This Task

In this example, an inverter will be connected to EnOS Cloud through an edge gateway. The edge gateway will collect data from the inverter and send them to EnOS Cloud as a proxy. The overall connection scenario is shown in the flowchart below:

../_images/edge_connection_task_description.png


The procedure has the following steps:

  1. Creating device models

  2. Creating products

  3. Registering devices

  4. Using the device SDK to simulate the sending of data via EnOS Edge as a proxy of the sub-device.

  5. Checking the device communication status.

  6. Checking the device data.

Prerequisites

  • Before you start, make sure that you have the Developer role to access the Developer Console in EnOS Application Portal. Contact your OU administrator for role assignment.

  • Complete sub-device registration by following Steps 1-3 in Connecting Smart Devices to EnOS Cloud.

Step 1: Creating an Edge Device Model

Create an Edge device model called Edge_Model, with the assumption that there are no reusable edge device models.

  1. In EnOS Application Portal > Developer Console, click Model Management > Models from the left navigation menu.

  2. Follow Creating a Model from Scratch to create a new model with the following details:

    • Group: Custom (custom)

    • Name: Edge_Model

    • Business Identifier: Edge_Model_0

    • Model Usage: Device Connection

    • Description: Edge Model


    Note

    Ensure Device Connection is selected under Model Usage; otherwise, the model cannot be used for product creation and device registration.

    ../_images/model_edge.png
  3. On the model details page, create the following attribute by referring to Creating Model Elements:

    • Type: Attribute

    • Name: Version/Version

    • Identifier: version

    • Data Type: string

    • Max Length: 20

    • Default Value: None

    • Mandatory: Yes

    • Writable: Yes

  4. Click Save at the bottom to complete attribute creation.


media/create_edge_attribute.png


This model can now be used to create products and register devices.

Step 2: Create an Edge Product

Create a product called Edge_Product with the assumption that the EnOS Edge devices transmit data using the EnOS IoT standard format without CA certificate encryption.

  1. In EnOS Application Portal > Developer Console, select Device Management > Products.

  2. Click New Product, and provide the following settings in the New Product window:

    • Product Name: Edge_Product

    • Asset Type: Gateway

    • Model: Edge_Model

    • Onboarding Method: EnOS IoT Only

    • Protocol Gateway: Disabled

    • Certificate-based Authentication: Disabled

    • Description: Edge Product

  3. Click OK to complete the operation.

For more information about products, see Creating Products.

Step 3: Registering the Edge Gateway

Create an edge device named Edge01, which belongs to the Edge_Product product model created in the previous step.

  1. In EnOS Application Portal > Developer Console, select Device Management > Device Assets.

  2. Click New Device, and provide the following settings in the New Device window:

    • Product: Edge_Product

    • Device Name: Edge01

    • timezone: UTC+14:00

    • Version: 1.0.0

  3. Click OK to complete the operation.


After creation, the device appears in the list. Click |view| to access device details and obtain the device credentials (ProductKey, DeviceKey, DeviceSecret), which will be used in subsequent steps.


.. image:: ../media/register_edge.png


For more information about products, see Creating Products.

Step 4: Using the device SDK to simulate the sending of data via EnOS Edge as a proxy of the sub-device.


In this step, you will simulate sending inverter active power data to the cloud via the Device SDK.

  1. Obtain the Device SDK. For details, refer to the SDK’s GitHub Readme File.

  2. Configure the EnOS cloud connection according to the steps in Readme.

  3. Configure the credentials (ProductKey, DeviceKey, DeviceSecret) of both EnOS Edge and the sub-device in the sample connection program.

  4. Modify the postSubMeasurepoint method to specify the measurepoint name. In this case, set it to INV.GenActivePW for inverter active power, along with corresponding values.

  5. Execute the following sample methods:

    • Gateway log in: In the following sample code, environment_address is the address of EnOS Cloud, and the productKey, deviceKey, and deviceSecret are the device triple of the edge gateway.

      public static void initWithCallback() {
         System.out.println("start connect with callback ... ");
      
         try {
             client = new MqttClient(environment_address, productKey, deviceKey, deviceSecret);
             client.getProfile().setConnectionTimeout(60).setAutoReconnect(false);
      
             client.connect(new ConnCallback() {
                 public void connectComplete(boolean reconnect) {
                     System.out.println("connect success");
                 }
      
                 public void connectLost(Throwable cause) {
                     System.out.println("onConnectLost");
                 }
      
                 public void connectFailed(Throwable cause) {
                     System.out.println("onConnectFailed : " + cause);
                 }
             });
         } catch (Throwable var1) {
         }
      
         System.out.println("connect result :" + client.isConnected());
      }
      
    • The gateway adds the topology of sub-devices and the sub-device logs in through the edge gateway. In the following sample code, “sub_pk“, “sub_dk“, and “sub_ds“ are the device triple of the sub-device.

      public static void addTopo() throws Exception {
         System.out.println("start add topo ...");
         TopoAddRequest request = (TopoAddRequest)TopoAddRequest.builder().addSubDevice(new SubDeviceInfo("sub_pk", "sub_dk", "sub_ds")).build();
         TopoAddResponse rsp = (TopoAddResponse)client.publish(request);
         System.out.println("-->" + rsp);
         getTopo();
         subDeviceLogin();                    //Sub-device logs in through gateway
      }
      
    • The gateway sends the data of the sub-device as the proxy. The following sample code sends float data to the INV.GenActivePW measurment point.

      public static void postSubMeasurepoint() {
         Random random = new Random();
         System.out.println("start post sub device measurepoint ...");
         MeasurepointPostRequest request = (MeasurepointPostRequest)((MeasurepointPostRequest.Builder)((MeasurepointPostRequest.Builder)MeasurepointPostRequest.builder().setProductKey("sub_pk")).setDeviceKey("sub_dk")).addMeasurePoint("INV.GenActivePW", random.nextFloat()).build();
      
         try {
             MeasurepointPostResponse rsp = (MeasurepointPostResponse)client.publish(request);
             System.out.println("-->" + rsp);
         } catch (Exception var3) {
             var3.printStackTrace();
         }
      }
      


For more information, see Using the Device SDK.

Step 6: Check the Device Status

In EnOS Application Portal > Developer Console, click Device Management > Device Assets, locate the Edge01 and INV001 devices and confirm that the devices are online.

Step 7: Check the Device Data

  1. From the device list, locate the device and click the View icon to show the Device Details page.

  2. Click the Measurment Points tab, select the INV.GenActivePW measurment point, and click the View Data icon to open the Data Insights page.

  3. View the latest data of the measurent point on the Data Insights page. If the TSDB storage policy has been configured for the measurement point, you can also view the historic data of the measurement point in a chart or table. For more information about data insights, see Generating Time Series Data Chart.