IoT Sensor Threshold Configuration via Mobile Application
Thresholds — sensor normal boundaries: above +28°C — warning, below +5°C — critical, send push. User configures these boundaries in the app, server stores them and generates alerts on violation. Task seems simple but requires careful UX and reliable backend sync.
UI for Threshold Configuration
Numeric input fields are a poor choice for thresholds. Users don't remember parameter range, see no context. Better — Range Slider showing current sensor value on the same scale.
On Android Compose — custom RangeSlider or Slider from Material3. Standard Material3 RangeSlider supports two sliders:
var thresholds by remember { mutableStateOf(sensor.minThreshold..sensor.maxThreshold) }
Column {
Text("Temperature: ${sensor.currentValue}°C")
Text("Allowed range: ${thresholds.start.roundToInt()}°C — ${thresholds.endInclusive.roundToInt()}°C")
RangeSlider(
value = thresholds,
onValueChange = { thresholds = it },
valueRange = sensor.absoluteMin..sensor.absoluteMax,
steps = 0,
onValueChangeFinished = {
viewModel.updateThresholds(sensor.id, thresholds.start, thresholds.endInclusive)
}
)
}
onValueChangeFinished — send to server only after slider release, not on every movement. Otherwise API request spam during dragging.
Show current sensor value on slider scale — vertical mark. Via Canvas above slider: calculate X position from (currentValue - min) / (max - min) * sliderWidth.
Threshold Types
Different parameters need different configurations:
| Parameter | Logic | Example |
|---|---|---|
| Temperature | Lower + upper bound | +5°C … +25°C |
| Motion | Only boolean trigger | Detected/not |
| CO2 Level | Only upper bound | > 1000 ppm |
| Pressure | Lower + upper + rate of change | < 950 or > 1050 hPa |
Don't try one universal component for all. Better — specialized set: BooleanThreshold, SingleBoundThreshold, RangeThreshold. Different config screens for different sensor types.
Server Sync and Local Cache
Thresholds stored on server, applied on server when processing telemetry. Mobile app is UI only.
On screen open: load current thresholds from server, display. On change: save locally (optimistic update), send to server, rollback on error.
fun updateThreshold(deviceId: String, min: Float, max: Float) {
val previous = _thresholds.value
// Optimistic update
_thresholds.update { it.copy(minValue = min, maxValue = max) }
viewModelScope.launch {
val result = repository.saveThreshold(deviceId, min, max)
if (result.isFailure) {
// Rollback
_thresholds.value = previous
_events.emit(UiEvent.ShowError("Failed to save settings"))
}
}
}
Optimistic update makes UI responsive — user doesn't wait for server. Rollback protects against data loss on network error.
Notifications on Threshold Violation
Alerts arrive via push (FCM/APNS). Payload must contain device_id, parameter, current_value, threshold_exceeded — so app can open right screen on tap.
On Android: setNotification() in FCM payload only if app in background. For foreground — FirebaseMessagingService.onMessageReceived() with local NotificationManager. Different channels (NotificationChannel) for warnings and critical alerts — different sounds and priorities.
Implementing threshold configuration with Range Slider, optimistic update, and push alerts: 2–3 weeks. Pricing calculated individually.







