设备属性¶
属性是附加到事物的键/值事实 - firmware_version、polling_interval_seconds、fleet_tier 等。每个属性都位于三个存储桶之一中,这三个存储桶的不同之处在于谁可以写入它以及它是否同步到设备。作为设备集成商,您需要与这三者中的两个合作。
三个桶¶
类别 |
谁写的 |
设备同步 |
按键示例 |
|---|---|---|---|
CLIENT |
仅设备 |
设备报告;云读 |
|
SHARED |
云和设备 |
两个方向 |
|
SERVER |
仅云 |
从未发送到设备 |
仅限租户方组织 |
您的设备固件涉及客户端(它报告的事实)和共享(它接收并确认的配置)。 SERVER 存储桶是云端组织,永远不会到达设备 - 您可以忽略它。
键由您定义。密钥必须匹配^[a-zA-Z_][a-zA-Z0-9_]{0,62}$;值可以是字符串、数字、布尔值、小对象或数组。
客户 — 报告事实¶
设备是 CLIENT 属性的真实来源。它会在连接时以及更改时报告它们;云可以读取它们,但永远不会写入它们。客户端报告利用设备现有的报告状态通道 - 无需构建单独的有线消息。
如果同一密钥的两个报告未按顺序到达,平台将保留具有较晚设备时间戳的报告(最后写入者按设备时间获胜),因此延迟或重播的报告永远不会覆盖较新的值。
连线主题¶
CLIENT 和 SHARED 在您的设备自己的子树上使用以下主题(请参阅设备 MQTT 主题访问):
主题 |
方向 |
承载内容 |
|---|---|---|
|
设备 → 云 |
报告的客户端属性(报告状态线) |
|
云 → 设备 |
共享值生效 |
|
设备 → 云 |
确认影响值 |
冻结电汇消息(DeviceAttributeSharedPush、DeviceAttributeSharedAck)在DDI-1合约中定义。使用下面的 SDK,而不是手动编码。
Python SDK¶
设备端DDI SDK(SiriusVoyager/ddi,Python)为您处理两个方向。构造一个客户端,注册一个 SHARED 回调,并报告 CLIENT 属性:
from fgai_mqtt import FGAIDeviceClient, DeviceConfig
client = FGAIDeviceClient(DeviceConfig(device_id="my-thing-id", ...))
# Receive SHARED-bucket pushes from the cloud. The SDK effects the value into a
# local shadow and publishes the ack for you — your callback just applies it.
def apply_shared(key, value):
print(f"cloud set {key} = {value}")
client.set_shared_attribute_callback(apply_shared)
client.connect()
# Report CLIENT-bucket facts up to the cloud.
client.report_client_attribute({"firmware_version": "8.4.2", "boot_count": 12})
# The last SHARED values the device received + effected:
print(client.shared_attribute_shadow)
调用 |
类别 |
它的作用 |
|---|---|---|
|
CLIENT |
报告设备拥有的事实 |
|
SHARED |
注册 |
|
SHARED |
设备最后生效的共享值( |
SDK 始终在您的回调运行后发布共享确认,因此云的有效值记录与设备保持同步 - 即使您的回调引发。
Did my change reach the device?¶
A cloud write to the SHARED bucket is sent over the device's live session, or
queued for its next connection. The /attribute-pushes/v1/things/{thing_id}
capability reports the dispatch status of those writes — per attribute key,
what the platform did with each request:
|
它的作用 |
|---|---|
|
the device was offline; the request is queued and will be sent on its next connection ( |
|
the request was published on a live device session |
|
the request was abandoned — the retry budget was spent, or it aged out of the queue — and will not be retried |
fgai attribute-pushes things-get --thing <thing-id> # newest first, every attribute key
Reading this surface requires a grant. The caller's principal must hold
ThingIoAttributePushReadAccess (attach it to a service principal with
fgai identity policy attach --account <id> --policy <policy-id>). A caller
without it is refused with a policy error whose body names the missing
action (thingio:AttributePush:Read) — read the action field rather than
assuming a generic denial. Error bodies are converging to RFC 7807
application/problem+json across Thing* services (PLT-0095); consult the
response body, not just the status code.
What this surface is not:
pusheddoes not mean applied. It means the platform published the down-channel message to a live session — not that the device received it, and not that the device applied it. Nothing here claims a configuration is in effect on a device.It never reports a device acknowledgement. The device's SHARED-bucket ACK (see the SDK's auto-ack above) is recorded in the attribute audit —
GET /attributes/v1/things/{thing_id}/auditshows the wire change whose source is the device. An acknowledgement is evidence the device received the value, which is still not the same claim as "applied".SERVER-bucket values have no dispatch status at all — they never touch a device.
The attribute audit is not the platform audit chain.
GET /attributes/v1/things/{thing_id}/auditreads the attribute-change audit (attribute_audit); business events such as enrollment are in the audit chain and do not appear here. A tenant read of the chain by target FRN is tracked in trustmint#525.
Each row carries the attribute key, the version the request was made at,
attempts (delivery attempts spent), superseded (a later request exists for
the same key — the device drains in order, so the newer request wins),
retry_pending, and created_at / updated_at timestamps. Attribute values
are not repeated here; read those through the attribute API, where your normal
permissions apply.