Devices that use Wi-Fi can report the network status to IoT Platform by using specified topics. This article describes the topics and data formats that are used by devices to report the network status, and the network errors that can be reported.

Note If your device uses AliOS Things V3.0 or later, the device automatically monitors and reports network status data.

Automatically report the network status to IoT Platform

The following topics are used when a device sends requests to IoT Platform and IoT Platform sends responses to the device:

Request topic: /sys/${productKey}/${deviceName}/_thing/diag/post

Response topic: /sys/${productKey}/${deviceName}/_thing/diag/post_reply

Sample request in the Alink JSON format:

  • Current data: the data that is immediately reported after the data is collected by the device.

    The device immediately reports the network status data in the following two scenarios:

    • When a network error is detected, the device immediately reports the error to IoT Platform.
    • If you have set scheduled collection, the device collects data at the specified time and immediately reports the data.

    For example, the device detects a network error at 08:10:29 of August 22, 2019 and immediately reports the data. Sample request that reports data when the device detects a network error:

    {
      "id": "123",
      "version": "1.0",
      "params": {
        "p": {
          "wifi": {
            "rssi": 75,
            "snr": 20,
            "per": 10,
            "err_stats":"10,02,01;10,05,01"
          },
          "_time": 1566432629000
        },
        "model": "quantity=single|format=simple|time=now"
      }
    }
    Note If no error is detected during scheduled collection, the err_stats parameter is empty.
  • Historical data: the data that is not immediately reported. In most cases, the device may delay the reporting of the collected network metrics. When the device reports historical data, the device can report multiple data records at a time.

    Sample request:

    {
      "id": "123",
      "version": "1.0",
      "params": {
        "p": [
          {
            "wifi": {
              "rssi": 75,
              "snr": 20,
              "per": 10,
              "err_stats":"10,02,01;10,05,01"
            },
            "_time": 1566432629000
          }
        ],
        "model": "format=simple|quantity=batch|time=history"
      }
    }
    Note If no error is detected, the err_stats parameter is empty.
Table 1. Request parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
version String The version of the protocol. Valid value: 1.0.
params Object The request parameters.
wifi Object The metrics of the network status. Four metrics are reported when the device uses Wi-Fi.
rssi integer The strength of the received wireless signal.
snr integer The signal-to-noise ratio of the wireless signal.
per integer The packet loss rate.
err_stats String The network error message. This parameter is included in the reported data only when the device detects a network error.

Format: "type,code,count;type,code,count". Example: "10,02,01;10,05,01".

Fields in the network error message:

  • type: the error type.
  • code: the error code.
  • count: the number of errors.

For more information about specific errors, see err_stats.

_time Long The timestamp that indicates when the network status was collected.
Note The timestamp can be empty. If it is empty, the Device Network Status tab in the IoT Platform console does not display the time when data was collected.
model String The model of the message body. The parameter value includes the following fields:
  • format: the data format. Only the simple format is supported. It indicates that the data is in a simplified format.
  • quantity: the number of data records to report. Valid values:
    • single: indicates that a single data record is reported.
    • batch: indicates that multiple data records are reported. This option is used only to report historical data.
  • time: indicates whether current or historical data is reported. Valid values:
    • now: indicates that current data is reported.
    • history: indicates that historical data is reported.
Table 2. err_stats
Error type Description Cause
0x00 The parameters of the wireless network environment.
  • Received signal strength indicator (RSSI): 0x01
  • Signal-to-noise ratio (SNR): 0x02
  • Packet loss rate (drop ratio): 0x03
0x10 The device failed to connect to IoT Platform.
  • The device failed to connect to the router (Wi-Fi fail): 0x01
  • The device failed to obtain the IP address (DHCP fail): 0x02
  • The domain name of IoT Platform failed to be resolved (DNS fail): 0x03
  • The TCP handshake failed (TCP fail): 0x04
  • The TLS handshake failed (TLS fail): 0x05
0x20 A network exception occurred between the device and IoT Platform.
  • IoT Platform closed the connection from the device (CLOUD_REJECT): 0x01
  • Errors occurred during device upload or download (RW_EXCEPTION): 0x02
  • Errors occurred during the ping operation between the device and IoT Platform (PING_EXCEPTION): 0x03
0x30 An exception occurred on the device.
  • The device was rebooted because the watchdog timer was reset (WD_RST): 0x01
  • The device was rebooted due to a storage exception (PANIC_ERR): 0x02
  • The device was rebooted due to a power outage (RE-POWER): 0x03
  • The device was rebooted due to a fatal error (FATAL_ERR): 0x04
0x40 The memory information.
  • Total memory (type of total size): 0x01
  • Total idle memory (type of free size): 0x02
0x50 A Bluetooth Low Energy (BLE) exception occurred. BLE exception.

Sample response in the Alink JSON format:

{
  "id": "123",
  "version": "1.0",
  "code": 200,
  "data": {}
}
Table 3. Response parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
code Integer The status code in the response. A value of 200 indicates that the request was successful.
version String The version of the protocol. Valid value: 1.0.
data Object The value is empty.