# 设备连接状态

### 功能概述 <a href="#gong-neng-gai-shu" id="gong-neng-gai-shu"></a>

平台设备状态服务负责监视设备连接状态并触发推送到**规则引擎的**的设备连接事件。平台开发者可以对相关事件出相关处理。

支持事件如下:

* **Connect event** - 设备连接到平台时触发。基于MQTT的会话传输和HTTP请求传输同时连接事件将在每一个HTTP请求上触发。
* **Disconnect event** - 设备与平台断开连接时触发。基于MQTT的会话传输和HTTP请求传输同时连接事件将在每一个HTTP请求上触发。
* **Activity event** - 通过属性(attribute update)或者rpc命令推送遥测数据。
* **Inactivity event** - 当设备指定时间内不活动时触发。请注意即使没有从设备断开连接事件也可能触发此事件。通常表示一段时间没有触发任何活动事件。
* 设备状态服务负责维护以下**服务端属性**属性:
* **active** - 表示当前设备状态为true或false;
* **lastConnectTime** - 表示设备最后一次连接到平台的时间，自1970年1月1日格林威治标准时间00:00:00以来的毫秒数
* **lastDisconnectTime** - 表示设备与平台断开连接的最后时间，自1970年1月1日格林威治标准时间00:00:00以来的毫秒数
* **lastActivityTime** - 表示设备上次推送遥测属性更新或rpc命令的时间，自1970年1月1日格林威治标准时间00:00:00以来的毫秒数
* **inactivityAlarmTime** - 表示上一次触发不活动事件的时间，自1970年1月1日格林尼治标准时间00:00:00以来的毫秒数

### 系统配置 <a href="#pei-zhi" id="pei-zhi"></a>

设备状态服务将全局配置参数用于不活动超时参数(state.defaultInactivityTimeoutInSec)在**iot.yml**中定义默认为10秒。

用户可以通过设置服务器端属性”inactivityTimeout”来覆盖单个设备的此参数（值以毫秒为单位）。

设备状态服务使用全局配置参数来检测不活动事件,参数(state.defaultStateCheckIntervalInSec)在**iot.yml**中定义默认为10秒。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.yuncitys.com/ping-tai-jie-shao/ruan-jian-gong-neng/she-bei-lian-jie-zhuang-tai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
