accounting.db 的 zapp_device 表)。
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
device_name |
string | 是 | 设备唯一标识名称(如 "Android_01", "Camera_A") |
timestamp |
int64 | 否 | 时间戳(支持秒或毫秒)。不传或为 0 时使用服务器接收时间。 |
| 字段名 | 类型 | 说明 |
|---|---|---|
code |
int32 | 业务状态码(成功为 200) |
message |
string | 描述信息 |
device_name |
string | 设备名称 |
status |
string | online |
last_heartbeat |
string | 服务器记录的心跳时间(YYYY-MM-DD HH:MM:SS) |
service: apipy.heartbeat.v1.HeartbeatService
method: ReportHeartbeat
request type: google.protobuf.Struct
response type: google.protobuf.Struct
import time
import grpc
from google.protobuf import struct_pb2
channel = grpc.insecure_channel("your-host:50051")
call = channel.unary_unary(
"/apipy.heartbeat.v1.HeartbeatService/ReportHeartbeat",
request_serializer=struct_pb2.Struct.SerializeToString,
response_deserializer=struct_pb2.Struct.FromString
)
req = struct_pb2.Struct()
req["device_name"] = "Python_Client_01"
req["timestamp"] = float(int(time.time()))
resp = call(req)
print(resp)
{
"code": 200,
"message": "Heartbeat received",
"data": {
"device_name": "Python_Client_01",
"status": "online",
"last_heartbeat": "2026-03-15 22:10:05"
}
}