Run end-to-end integration testing

Updated at:
Copy as MD

After developing applications for the device and server, perform end-to-end integration testing. Start the server program to connect with IoT Platform. Then, run the device simulation script to report data and call the Pub API from the server to send control commands.

Test data reporting

Device

In your terminal, use the cd command to navigate to the directory that contains the iot_device.js file. Then, run the following command to start the device.

node iot_device.js

After the device connects successfully, it prints the following payload data.

payload=[ DE02,23,16,011101010,am024,1d478f ]
payload=[ DE02,29,24,011101010,am024,1d478f ]
payload=[ DE02,28,17,011101010,am024,1d478f ]
payload=[ DE02,26,18,011101010,am024,1d478f ]
payload=[ DE02,25,10,011101010,am024,1d478f ]
payload=[ DE02,18,10,011101010,am024,1d478f ]
payload=[ DE02,29,13,011101010,am024,1d478f ]

Server

In IntelliJ IDEA, run the AmqpClient.java program.

Note The sample code includes Thread.sleep(60 * 1000);, which allows the program to run for one minute before stopping. In a production environment, you can adjust this runtime as needed.

The server prints the message data it receives from IoT Platform in real time. The following example shows a message containing the complete original payload from the device.

11:17:34.134 [pool-1-thread-8] INFO com.aliyun.iotx.demo.AmqpClient - receive message,
topic = /a1xxxx/deviceSN1/user/data/up,
messageId = 1xxx7,
content = {"payload":"DE02,26,16,011101010,am024,1d478f","deviceName":"deviceSN1","timestamp":1658891854095}

IoT Platform

Log on to the IoT Platform console, select your instance, and choose Monitoring and O&M > Log Service > Cloud-side Running Logs.

You can find logs where the Business Type is Device Behavior. These logs record device events such as going online and offline.

You can also view the details of each upstream message, including its topic and payload, to track the message flow.

The logs are listed chronologically and show the following sequence of events:

  1. The device reports a message.
  2. The rule engine forwards the message to AMQP.
  3. AMQP pushes the message to the server.
  4. The server returns an ACK.

In the left-side navigation pane, choose Message Forwarding > Server-side Subscription. Click the Consumer Group List tab. For the consumer group named Power Bank Business Data Processing, click View. On the Consumer Group Details page, you can view metrics such as the message processing rate, message backlog, the timestamp of the last processed message, and information about the connected server (client).

Send control commands

Server

In IntelliJ IDEA, run the PubClient.java program.

Call the Pub API on the server to send a control command to the device. The API returns the following response.

{"requestId":"705EADF6-B5A3-579E-B7F9-2CBAACD4CF37","success":true,"messageId":"1xxx8"}

Device

The device prints the command information in real time, as shown in the following example.

topic /a16****/deviceSN1/user/cmd/down
message CMD,82923,ad322

IoT Platform

Log on to the IoT Platform console, select your instance, and choose Monitoring and O&M > Log Service > Cloud-side Running Logs.

You can view the complete flow of the command message.

The logs are listed chronologically and show the following sequence of events:

  1. The server calls a downlink API.
  2. IoT Platform receives the API call and pushes the message to the device.

Results