Implementing Event Logging for IoT Devices in Mobile App
IoT event log isn't just a table with date and text. It's an incident investigation tool: when device lost connection, when sensor triggered, who and when sent command. Without filtering and fast search through hundreds of thousands of records, the log is useless.
Event Structure and Storage
Minimal event field set:
data class DeviceEvent(
val id: Long,
val deviceId: String,
val timestamp: Instant,
val severity: Severity, // DEBUG, INFO, WARNING, ERROR, CRITICAL
val category: String, // "connection", "sensor", "command", "firmware"
val message: String,
val metadata: Map<String, Any?>, // payload depends on category
)
Backend—TimescaleDB (PostgreSQL extension) or ClickHouse for time-series event storage with fast range queries. Mobile client—paginated loading with filters.
Filtering and Search
Future<List<DeviceEvent>> fetchEvents({
required String deviceId,
DateTime? from,
DateTime? to,
List<Severity>? severities,
String? searchQuery,
int page = 0,
int pageSize = 50,
}) async {
return _api.getEvents(
deviceId: deviceId,
from: from?.toIso8601String(),
to: to?.toIso8601String(),
severities: severities?.map((s) => s.name).toList(),
q: searchQuery,
offset: page * pageSize,
limit: pageSize,
);
}
Color coding by severity: gray (DEBUG), white (INFO), yellow (WARNING), red (ERROR/CRITICAL). Critical events—higher in list regardless of time, others—by descending time.
Local Cache and Offline
Cache last 500 events in SQLite (drift)—log accessible without internet. On connection restore, fetch new records since last sync via since API parameter.
Implementing IoT event log with filtering, search, color coding, and offline cache: 1–2 weeks. Cost individually quoted.







