You can call this operation to query the curve that shows the number of connected MQTT clients in a group in the specified time range based on the specified group ID (GID).

Scenarios

OnsMqttQueryHistoryOnline is typically used to generate service statistics.

API operations are designed for you to implement custom management and development. Based on this, the MQTT broker throttles frequent calls that amount to 30 or more per minute. Therefore, do not call this operation in the main service process. To determine whether an MQTT client is connected, use the device online/offline notification function. If an MQTT client is online, this client has been connected to an MQTT broker.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. After you call this operation in OpenAPI Explorer, OpenAPI Explorer dynamically generates SDK sample code.

Request parameters

Parameter Type Required Example Description
Action String Yes OnsMqttQueryHistoryOnline

The operation that you want to perform. Set the value to OnsMqttQueryHistoryOnline.

BeginTime Long Yes 1570957261

The beginning of the time range to query.

EndTime Long Yes 1570962601

The end of the time range to query. We recommend that the start time and end time of a query fall on the same day. The back end allows query of messages for three days. If the time range for a query exceeds this time limit, the back end automatically returns query results that correspond to this time limit.

GroupId String Yes GID_test

The group ID that you want to query.

InstanceId String No post-cn-0pp12gl****

The ID of the MQTT instance to which the group ID you want to query belongs. This parameter is required for instances with separate namespaces.

Response parameters

Parameter Type Example Description
Data

The returned data set.

Records Array

The data set that included more detailed information.

StatsDataDo

The data set that included more detailed information.

X Long 1570960501

The X axis, which represents time in the timestamp format. Unit: millisecond.

Y Float 2

The Y axis, which represents the number of connected MQTT clients.

Title String The number of connected MQTT clients

The name of the table that lists the historical number of connected MQTT clients in the specified time range.

XUnit String Time

The time in the X axis, which is in the timestamp format. Unit: millisecond.

YUnit String The number of connected MQTT clients.

The number of connected MQTT clients.

RequestId String 5BC91C2F-C202-4AD8-9322-9F2AB3E320DC

The ID of the request, which is a common parameter. Each request has a unique ID to facilitate troubleshooting and fault locating.

Examples

Sample request


http(s)://[Endpoint]/? Action=OnsMqttQueryHistoryOnline
&BeginTime=1570959001
&EndTime=1570962601
&GroupId=GID_test
&InstanceId=post-cn-0pp12gl****
&<Common request parameters>

Sample success response

XML format

<OnsMqttQueryHistoryOnlineResponse>
  <Data>
        <Records>
              <StatsDataDo>
                    <X>1570960501</X>
                    <Y>2</Y>
              </StatsDataDo>
        </Records>
        <XUnit>time</XUnit>
        <YUnit>quantity</YUnit>
        <Title>number of connected clients</Title>
  </Data>
  <RequestId>5BC91C2F-C202-4AD8-9322-9F2AB3E320DC</RequestId>
</OnsMqttQueryHistoryOnlineResponse>

JSON format

{
	"Data":{
		"XUnit":"time",
		"Records":{
			"StatsDataDo":[
				{
					"Y":"2",
					"X":"1570960501"
				}
			]
		},
		"YUnit":"quantity",
		"Title":"connected clients"
	},
	"RequestId":"5BC91C2F-C202-4AD8-9322-9F2AB3E320DC"
}

Error codes

For a list of error codes, visit the API Error Center.