Device API Documentation

This API allows users to interact with their devices, retrieve information, update configurations, and manage schedules and logs. Below is the list of available endpoints and example request/response formats.

List Devices

GET /devices

Fetch a list of all devices linked to the current user.

Response Example

{
  "devices": [
    {
      "id": "DEVICE123",
      "name": "Temperature Sensor",
      "status": "active",
      "config": { "samplingRate": "10s", "threshold": 40 }
    }
  ]
}

Get Device Information

GET /device/:deviceId

Retrieve detailed information about a specific device.

Response Example

{
  "device": {
    "id": "DEVICE123",
    "name": "Temperature Sensor",
    "status": "active",
    "config": { "samplingRate": "10s", "threshold": 40 }
  }
}

Get Device Schedules

GET /device/:deviceId/schedules

Retrieve schedules for the specified device.

Response Example

{
  "schedules": [
    { "sound": "Alarm", "date": "2024-01-01", "time": "10:00" }
  ]
}

Post Device Schedules

POST /device/:deviceId/schedules

Add a new schedule to the specified device.

Request Body Example

{
  "sound": "Alarm",
  "date": "2024-01-01",
  "time": "10:00"
}

Response Example

{
  "message": "Schedule added successfully"
}

Get Device Logs

GET /device/:deviceId/logs

Retrieve logs for the specified device.

Response Example

{
  "logs": [
    { "sensor": "Temperature", "value": 35.6, "timestamp": "2024-10-12T10:00:00Z" }
  ]
}

Post Device Logs

POST /device/:deviceId/logs

Submit sensor data and logs from the device, and receive the latest configuration.

Request Body Example

{
  "sensors": [{ "sensor": "Temperature", "value": 35.6 }],
  "status": "active",
  "config": { "samplingRate": "10s" },
  "schedule": [],
  "sound": {}
}

Response Example

{
  "message": "Log data saved successfully",
  "config": { "samplingRate": "5s", "threshold": 45 }
}

Update Device Configuration

POST /device/:deviceId/config

Update the configuration settings of a specific device.

Request Body Example

{
  "config": { "samplingRate": "5s", "threshold": 45 }
}

Response Example

{
  "message": "Device config updated successfully"
}