Home / Docs Center / Pet Feeder (ODM Case) / DeviceUnified Report

DeviceUnified Report

Pet Feeder (ODM Case) · Device Report API

Project: Pet Feeder | page_id: 1720

Device Report Interface Documentation

1. Interface Information

  • Interface name: Unified Device Report
  • Path: /api/device/report
  • Method: POST
  • Content-Type: application/json
  • Authentication method: device signature authentication
  • Handler function: deviceH.Report

2. Function Description

The device reports different types of data through the same interface, using action to distinguish the business type.

Supported actions:

  • status: report device status
  • feedlog: report feeding records
  • alarm: report alarm information

3. Authentication Rules

When reportSecret is configured on the server side, the token and timestamp must be verified.

  • token calculation rule:

md5(reportSecret + ":" + deviceId + ":" + timestamp + ":" + action)

  • timestamp unit: seconds
  • timestamp validity period: reportTokenTTL (default 300 seconds)
  • Failure response:
  • 401 + code=401 + msg=Device authentication has expired
  • 401 + code=401 + msg=Device authentication failed

4. Common Request Body

Field Type Required Description
deviceId string Yes Unique device identifier
action string Yes status/feedlog/alarm
timestamp int64 Yes Request timestamp (seconds)
token string Yes Device signature
data string No A JSON string whose structure is determined by action; the server parses it according to action

5. data Structure for Each action

5.1 action = status

Field Type Required Description
batteryLevel int No Battery percentage
isCharging bool No Whether it is charging
foodLevel int No Remaining food percentage
wifiName string No Name of the currently connected WiFi
wifiSignal int No WiFi signal strength
firmwareVersion string No Firmware version

Example:

{
  "deviceId": "dev_001",
  "action": "status",
  "timestamp": 1752297600,
  "token": "md5signature",
  "data": "{\"batteryLevel\":90,\"isCharging\":false,\"foodLevel\":80,\"wifiName\":\"Home-2.4G\",\"wifiSignal\":-58,\"firmwareVersion\":\"1.0.2\"}"
}

5.2 action = feedlog

Field Type Required Description
amount int No Feeding portion
planId int64 No Plan ID; can be 0 for manual feeding
feedTime int64 No Feeding timestamp (seconds)
userId int64 No User ID
userName string No User nickname

Example:

{
  "deviceId": "dev_001",
  "action": "feedlog",
  "timestamp": 1752297600,
  "token": "md5signature",
  "data": "{\"amount\":20,\"planId\":1,\"feedTime\":1752297600,\"userId\":10001,\"userName\":\"Tom\"}"
}

5.3 action = alarm

Field Type Required Description
alarmType string No Alarm type
message string No Alarm content

Example:

{
  "deviceId": "dev_001",
  "action": "alarm",
  "timestamp": 1752297600,
  "token": "md5signature",
  "data": "{\"alarmType\":\"low_battery\",\"message\":\"Battery level below 10%\"}"
}

6. Response Description

Unified response structure:

Field Type Description
code int Business status code
msg string Response message
data any Returned data; generally null when this interface succeeds

6.1 Success Response

  • HTTP status code: 200
  • Response example:
{
  "code": 200,
  "msg": "Report successful",
  "data": null
}

6.2 Failure Responses (Common)

  • Parameter error or business processing failure
{
  "code": 400,
  "msg": "Parameter error",
  "data": null
}
  • Unknown action
{
  "code": 400,
  "msg": "Unknown action: xxx",
  "data": null
}
  • Authentication expired or failed (HTTP 401)
{
  "code": 401,
  "msg": "Device authentication failed",
  "data": null
}

7. Notes

  • Code location:
  • Route registration: cmd/main.go
  • Handler function: internal/handler/device_handler.go
  • The data field is agreed by the interface to be a JSON string, and the server continues to parse it in the corresponding action branch.
  • If data is an empty string or missing, parsing will not report an error, but the business layer may fail because the fields are empty.
Didn't find what you need?Contact us,Talk to our engineers directly.

Request a Quote

Fill in the form and we will get back with a quote and proposal within 1 business day.

Click "Generate inquiry email" to open your mail client with the body pre-filled. If no mail client is configured, click "Copy" and paste it into webmail — recipient: sunshiyang@xstrive.com.