Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/GaelCeballos/Smart_Enviro_Backend/llms.txt

Use this file to discover all available pages before exploring further.

This is the primary endpoint for ESP32 devices to synchronize with the backend. The device sends its device_token as a query parameter and receives its current command (ON, OFF, or STANDBY) and the full set of configuration properties. This endpoint requires no user authentication — only the device token.

Endpoint

FieldValue
MethodGET
Path/api/device/sync
Authdevice_token query parameter — no Bearer token required

Query Parameters

device_token
string
required
The 64-character device token provisioned in the database when the device was registered. This is the sole authentication mechanism for ESP32 devices.

Request Example

curl -X GET "http://localhost/api/device/sync?device_token=YOUR_64_CHAR_TOKEN"

Responses

200 OK

The device token is valid and the device is active. The backend responds with the current command and the device’s full configuration property map.
{
  "status": "success",
  "command": "STANDBY",
  "config": {
    "auto_water": "true",
    "humidity_threshold": "60",
    "dimmer_level": "75"
  }
}
status
string
Always "success" on a 200 response.
command
string
The current actuator command for the device. Possible values:
  • ON — activate the actuator
  • OFF — deactivate the actuator
  • STANDBY — hold in standby mode
  • SLEEP — only returned on a 401; instructs the ESP32 to enter deep sleep
config
object
A flat key→value map of all device_properties rows for this device. Keys are the property_key column values; values are always strings. The set of keys varies per device based on its configured properties.Example keys: "auto_water", "humidity_threshold", "dimmer_level", "has_pump", "has_humidity".

401 Unauthorized

The device_token does not match any device in the database, or the matching device has is_active = false. The ESP32 should enter deep sleep to conserve battery.
{
  "status": "error",
  "command": "SLEEP"
}

The command field maps directly to the device’s current_state column. The ESP32 firmware should enter deep sleep when command is SLEEP — this is returned whenever the device token is invalid or the device is marked inactive.
The config object contains all device_properties rows for this device as a flat key→value map. Property keys are defined by the property_key column in the device_properties table. Update individual properties via PUT /api/my-devices/{id}/properties.

Call this endpoint on every ESP32 boot, then again every 5 minutes to pick up configuration changes or new commands set by the user through the mobile app.

Build docs developers (and LLMs) love