Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/diarpicu2022-commits/backend-AgroPulse/llms.txt

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

Sensor thresholds are the rules that tell the AnomalyDetectionService when a reading is abnormal. Each sensor can have at most one threshold record. When a reading arrives via POST /api/readings, GreenhouseMonitor.processSensorReading() looks up the threshold for the sensor and evaluates four conditions: value out of range, no data received for too long, value stuck at the same level, and sudden spike. Sensors without an active threshold are silently skipped by the anomaly pipeline.
Anomaly detection only runs for sensors that have an active threshold (active: true). Creating a threshold via PUT always sets active to true. To suspend monitoring for a sensor without deleting its threshold, delete the threshold record and recreate it when needed.

Endpoints

MethodPathDescription
GET/api/sensors/{id}/thresholdRetrieve the threshold for a sensor
PUT/api/sensors/{id}/thresholdCreate or update the threshold for a sensor (upsert)
DELETE/api/sensors/{id}/thresholdRemove the threshold for a sensor

GET /api/sensors//threshold

Returns the threshold record for the given sensor. Returns 404 if no threshold has been configured.

Path parameters

id
number
required
The sensor ID whose threshold to retrieve.

Response

{
  "id": 5,
  "sensorId": 1,
  "minValue": 10.0,
  "maxValue": 40.0,
  "noDataMinutes": 10,
  "stuckMinutes": 30,
  "spikePercent": 50.0,
  "active": true,
  "updatedAt": "2024-06-01T14:00:00"
}

curl example

curl http://localhost:8080/api/sensors/1/threshold

PUT /api/sensors//threshold

Creates the threshold if one does not yet exist, or updates the existing record. This is a full upsert — only fields present in the request body are changed; omitted fields retain their stored values. The active flag is always set to true on every save.

Path parameters

id
number
required
The sensor ID to configure a threshold for.

Body parameters

minValue
number
Lower bound for acceptable readings. When a reading falls below this value, an anomaly event is raised. Set to null to disable the lower-bound check.
maxValue
number
Upper bound for acceptable readings. When a reading exceeds this value, an anomaly event is raised. Set to null to disable the upper-bound check.
noDataMinutes
number
default:"10"
Number of minutes without any reading before the service raises a “no data” anomaly. Use this to detect sensor disconnections or network outages.
stuckMinutes
number
default:"30"
Number of minutes during which the sensor reports the same value before the service raises a “stuck value” anomaly. Catches frozen sensors or broken ADC circuits.
spikePercent
number
default:"50.0"
Percentage change between consecutive readings that qualifies as a spike. For example, 50.0 means a jump of more than 50 % from the previous value triggers a spike anomaly.

Response fields

id
number
Auto-generated threshold record identifier.
sensorId
number
The sensor this threshold applies to.
minValue
number
Lower acceptable bound. null when the check is disabled.
maxValue
number
Upper acceptable bound. null when the check is disabled.
noDataMinutes
number
No-data timeout in minutes.
stuckMinutes
number
Stuck-value window in minutes.
spikePercent
number
Spike detection threshold as a percentage of the previous reading.
active
boolean
Always true after a PUT. Delete the record to suspend anomaly detection.
updatedAt
string
ISO-8601 datetime of the last update, set server-side on every save.

curl examples

curl -X PUT http://localhost:8080/api/sensors/1/threshold \
  -H "Content-Type: application/json" \
  -d '{
    "minValue": 10.0,
    "maxValue": 40.0,
    "noDataMinutes": 15,
    "stuckMinutes": 30,
    "spikePercent": 50.0
  }'

DELETE /api/sensors//threshold

Removes the threshold record for the sensor. After deletion, the sensor is excluded from all anomaly detection checks until a new threshold is created with PUT.

Path parameters

id
number
required
The sensor ID whose threshold to delete.

Response

{ "deleted": true }
If the sensor has no threshold configured, the endpoint still returns 200 with { "deleted": true } rather than 404. It is safe to call idempotently.

curl example

curl -X DELETE http://localhost:8080/api/sensors/1/threshold

Build docs developers (and LLMs) love