ekfa/docs/heartbeat.md

1.2 KiB
Raw Blame History

UDP 心跳

efka 通过独立的 efka_iot_heartbeat 进程向 iot 发送 UDP 心跳。该心跳只表示主机存活,不依赖 TLS control channel 是否在线。

配置

TLS 和 UDP 共用同一个 iot_server.host

{iot_server, [
  {host, "localhost"},
  {tls_port, 443},
  {udp_port, 18080}
]},

{heartbeat, [
  {interval, 5000}
]},

{auth, [
  {uuid, "qbxmjyzrkpntfgswaevodhluicqzxplkm"},
  {token, "zpxlkvmqwnbghytrujsdieofazxcvbnm"}
]}
  • tls_port 用于 efka_iot_client 建立 TLS 连接。
  • udp_port 用于 efka_iot_heartbeat 发送 UDP 心跳。
  • heartbeat.interval 是发送间隔,单位毫秒,默认 5000。
  • UDP 心跳和 TLS 鉴权复用 auth.uuidauth.token

包格式

<<
    Version:8,
    UuidLen:16,
    UUID:UuidLen/binary,
    Timestamp:64/unsigned-big,
    Nonce:16/binary,
    Mac:32/binary
>>

Mac 使用 HMAC-SHA256

HeartbeatSecret = crypto:hash(sha256, Token),
Payload = <<Version:8, UuidLen:16, UUID:UuidLen/binary, Timestamp:64/unsigned-big, Nonce:16/binary>>,
Mac = crypto:mac(hmac, sha256, HeartbeatSecret, Payload)

其中 Tokenauth.tokeniot 侧注册 efka client 时保存同样的 SHA256(Token) 派生值,并用它校验心跳。