Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Industrial IoT Systems with Android and Kotlin ...

Avatar for Jasveen Jasveen
September 24, 2025

Industrial IoT Systems with Android and Kotlin Multiplatform - DroidKaigi 2025

Explore how Android and Kotlin Multiplatform can power industrial-grade IoT systems. This talk covers hardware connectivity patterns (USB, Wireless, Web Serial API), KMP architecture for code sharing across platforms, and real-world implementation strategies for RFID systems and industrial applications. Learn about reliability patterns, offline sync, zero-trust security, and practical deployment considerations for enterprise environments.

Presented at DroidKaigi 2025 (September 11, 2025) in Tokyo, Japan.

Topics covered:
- Android hardware capabilities for industrial use
- Web Serial API as a bridge for hardware connectivity
- Kotlin Multiplatform architecture patterns
- Real-time data handling with Kotlin Flow
- Zero-trust security in industrial systems
- Deployment strategies for enterprise

GitHub: https://github.com/jsxs0
X/Twitter: https://x.com/SJasveen

Avatar for Jasveen

Jasveen

September 24, 2025
Tweet

Other Decks in Technology

Transcript

  1. TODAY'S TOPICS 1. Android's hardware capabilities 2. Connection approaches 3.

    Kotlin Multiplatform details 4. Implementation patterns 5. Practical considerations
  2. USB CONNECTION PATTERN Direct hardware access // Conceptual example only

    class USBManager { fun findDevices(): List<device> { // Discovery logic } fun connect(device: Device) { // Connection logic } }</device>
  3. WIRELESS PATTERN Flexible deployment // Conceptual example only class WirelessManager

    { suspend fun scan(): List<device> { // Scanning logic } suspend fun connect(address: String) { // Connection logic } }</device>
  4. WEB TECHNOLOGY BRIDGE Experimental approach // Conceptual pattern class WebBridge

    { // JavaScript bridge concept // Requires WebView // Limited platform support }
  5. WHAT IS WEB SERIAL API? • Browser API for serial

    devices • Released in Chrome 89 (2021) • Requires user permission • Works with USB/serial ports
  6. BROWSER SUPPORT ✓ Chrome/Edge (desktop) ✓ Chrome Android (via flag)

    ✗ Firefox (no plans) ✗ Safari (no support) Limited but growing support
  7. WEB SERIAL USE CASES • Arduino programming • IoT device

    configuration • Industrial sensors • Educational hardware
  8. WEB SERIAL LIMITATIONS • Requires HTTPS • User gesture required

    • No background access • Platform restrictions
  9. WEB SERIAL VS NATIVE USB WEB SERIAL + Cross-platform +

    No app install - Browser only - Limited support NATIVE USB + Full control + Always available - Platform specific - App required
  10. BASIC WEB SERIAL PATTERN // JavaScript example async function connectSerial()

    { // Request port access const port = await navigator.serial.requestPort(); // Open with standard settings await port.open({ baudRate: 9600 });
  11. PERMISSION MODEL 1. User action required (click/tap) 2. Browser shows

    device picker 3. User selects device 4. Permission granted for session
  12. THE BRIDGE: JS TO KOTLIN RFID Reader (Serial) ↓ Web

    Serial API (JavaScript) ↓ JavaScriptInterface ↓ Android App (Kotlin) ↓ KMP Shared Logic
  13. BRIDGE IMPLEMENTATION // androidMain: Expose a Kotlin function to WebView's

    JS class WebAppInterface(private val onTagRead: (String) -> Unit) { @JavascriptInterface fun postTagData(hexData: String) { // Data from RFID reader is received here onTagRead(hexData) } } // In your Activity/Fragment
  14. KMP BENEFITS • Code reuse across platforms • Type safety

    • Native performance • Gradual adoption possible
  15. KMP ARCHITECTURE // commonMain - shared code expect class DeviceManager

    { fun initialize() fun connect() } // androidMain actual class DeviceManager { actual fun initialize() { /* Android */ } actual fun connect() { /* Android */ }
  16. KMP PROJECT STRUCTURE commonMain/ - Shared logic androidMain/ - Android

    specific iosMain/ - iOS specific jsMain/ - Web specific
  17. SHARED RFID LOGIC // commonMain: Parse raw data into a

    typed object data class RFIDTag(val id: String, val type: String) class RFIDParser { // Shared logic to parse a tag from raw hex data fun parseTagData(rawHex: String): RFIDTag? { if (!isValid(rawHex)) return null // ...logic to parse SGTIN or other formats return RFIDTag(id = "...", type = "UHF")
  18. PLATFORM SPECIFICS // androidMain actual fun getPlatformName(): String = "Android"

    // iosMain actual fun getPlatformName(): String = "iOS" // jsMain actual fun getPlatformName(): String = "Web"
  19. RELIABILITY PATTERNS // Retry pattern concept suspend fun reliableOperation() {

    repeat(MAX_ATTEMPTS) { try { // Operation return } catch (e: Exception) { // Handle error } }
  20. OFFLINE SYNC PATTERN [ Queued Locally ] ↓ [ Syncing

    ] ↓ [ Synced ] ✓ [ Failed ] ✗
  21. STATE MANAGEMENT // Shared state management class StateManager { private

    val _state = MutableStateFlow<state>() val state: StateFlow<state> = _state fun updateState(newState: State) { _state.value = newState } }</state></state>
  22. HANDLING REAL-TIME STREAMS A fast RFID reader can produce hundreds

    of reads per second. How do you prevent overwhelming the UI? // Use Flow operators to manage the stream without blocking rfidReader.dataFlow() .buffer(capacity = 64) // Absorb bursts of data on a background thread .conflate() // Drop intermediate reads if the UI is busy .onEach { tag -> // Only the latest tag is sent to the UI for rendering viewModel.updateLatestTag(tag) } .launchIn(viewModelScope)
  23. TESTING STRATEGY • Unit tests in commonTest • Platform tests

    in specific modules • Integration testing • UI testing per platform
  24. ZERO TRUST SECURITY Principle: Never Trust, Always Verify Device Identity:

    Each device authenticates with a unique certificate. Per-Request Auth: Every API call is authenticated with a short-lived token. Assume Breach: Network is hostile; all traffic encrypted (TLS 1.3). Data Validation: Raw data is untrusted until validated by KMP logic.
  25. IMPLEMENTATION APPROACH Phase 1: Requirements analysis Phase 2: Architecture design

    Phase 3: Prototype development Phase 4: Testing & refinement
  26. RECOMMENDATIONS • Start with proven APIs • Focus on reliability

    • Plan for offline scenarios • Test thoroughly
  27. KEY POINTS • Android is capable for industrial use •

    KMP enables code sharing • Web Serial provides a hardware bridge • Reliability must be designed in
  28. LEARN MORE • Android developer documentation • Kotlin Multiplatform resources

    • Industrial IoT best practices • Web Serial API on web.dev