百度智能云

All Product Document

          Intelligent Edge

          Upload Edge Data to MQTT Broker

          Scenario description

          For the edge broker that has collected data, it is necessary to report the collected data to the cloud. This article explains how to upload the edge business data to the remote MQTT Broker.

          Upload to Baidu IoT Core

          I. Prerequisites

          • A network edge node that can get the device data (This demo uses the demo node of Modbus temperature and humidity sensor in the application case as the test node.)
          • Baidu IoT Core account

          II. Overall Process

          The message flow of the edge side and IoT Core is shown in the figure below. Configure the message flow from broker topic to iotcore topic in this demo.

          flow.png

          III. IoT Core Configuration

          1. Create the IoT Core instance.

          image.png

          2. Add the template.

          Select the instance, and add the template.

          image.png

          Edit the template and add the MQTT broker topic.

          {deviceName} is the variable, which indicates that it shall be replaced with the device name when the corresponding device is connected. If the device name is device1 when you create the device, the device can subscribe to or release the $iot/device1/user/test topic according to the configuration.

          image.png

          3. Add the device.

          Add the device with the name device1. Select the key authentication, and select the default template configured at just.

          image.png

          4. Connect, receive and send a message through MQTT.

          Refer to Baidu AI Cloud Documentations to get the MQTT connection information and generate the user name and password.

          Example of device connection information

          IoTCoreId: agwrbcp
          DeviceKey: device1
          DeviceSecret: wgXHpQsNBnAPQSwx
          
          agwrbcp.iot.gz.baidubce.com     #Broker connection address
          thingidp@agwrbcp|device1|0|MD5     #Account name
          facd01cc28f85cf3d223b2529f479a38     #password

          IV. Edge Side Configuration

          The data circulation rules are configured in the baetyl-rule module.

          1. Create rule-conf configuration item

          image.png

          Configuration item code

          `
          clients:
            - name: iotcore
              kind: mqtt
              address: 'tcp://agwrbcp.iot.gz.baidubce.com:1883'
              username: thingidp@agwrbcp|device1|0|MD5
              password: facd01cc28f85cf3d223b2529f479a38
            - name: broker      #broker service name
              kind: mqtt
              address: 'tcp://broker:1883'
          rules:
            - name: rule1
              source:
                client: broker
                topic: test
                qos: 1
              target:
                client: iotcore
                topic: $iot/device1/user/test
                qos: 1
          
          `

          2. Create the container service, and add the configuration item.

          image.png

          • Service name:baetyl-rule
          • Image address: baetyltech/rule:v2.0.0
          • Container directory: /etc/baetyl/

          V. Testing

          Subscribe to the IoT Core topic in the MQTT Box. You can receive the message from the temperature and humidity sensors.

          image.png

          image.png

          Previous
          Acquire Temperature and Humidity Sensor Data Using modbus
          Next
          Connect Local baetyl-broker of Edge Node