Real-Time IoT Device Status Monitoring in Mobile App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Real-Time IoT Device Status Monitoring in Mobile App
Medium
~3-5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Real-Time Monitoring of IoT Device Status in Mobile Applications

User opens the device list and sees the current status of each — online, offline, power error, low battery. Not "status from 5 minutes ago", but now. Technically, this is a task of bidirectional realtime connection with proper lifecycle management on a mobile device.

Transports for Real-Time Status

MQTT with LWT (Last Will Testament). When a device connects to the broker, it registers an LWT message: if the connection drops without explicit disconnect, the broker publishes {"online": false} to topic devices/{id}/status. Mobile app subscribes to devices/+/status and updates UI on receipt.

This is the best pattern for IoT: offline detection happens automatically, without polling.

WebSocket. For web-based backends. Home Assistant API, custom backend on Laravel with Pusher or Laravel Echo — all via WebSocket. Works when MQTT broker is not directly accessible from the phone.

Server-Sent Events (SSE). Unidirectional HTTP streaming. Simpler than WebSocket, works through any CDN. On Android — OkHttp with EventSource:

val request = Request.Builder().url("$baseUrl/api/devices/stream").build()
val eventSource = EventSources.createFactory(okHttpClient)
    .newEventSource(request, object : EventSourceListener() {
        override fun onEvent(source: EventSource, id: String?, type: String?, data: String) {
            val update = json.decodeFromString<DeviceStatusUpdate>(data)
            repository.updateDeviceStatus(update.deviceId, update.status)
        }
        override fun onFailure(source: EventSource, t: Throwable?, response: Response?) {
            // Reconnect via ExponentialBackoff
            scheduleReconnect()
        }
    })

Long polling — outdated pattern, not recommended for mobile. Keeps HTTP connection open, poor with network switching.

MQTT on Android: Lifecycle Management

MQTT connection shouldn't bind to Activity or Fragment lifecycle. Correct — use foreground Service:

class MqttService : Service() {
    private lateinit var mqttClient: MqttAsyncClient

    override fun onCreate() {
        val options = MqttConnectOptions().apply {
            isAutomaticReconnect = true
            isCleanSession = false
            keepAliveInterval = 30
        }
        mqttClient = MqttAsyncClient(brokerUrl, clientId, MqttDefaultFilePersistence())
        mqttClient.connect(options).waitForCompletion()
        mqttClient.subscribe("devices/+/status", 1) { topic, message ->
            val deviceId = topic.split("/")[1]
            // Broadcast or via Repository
            DeviceRepository.getInstance().updateStatus(deviceId, message.toString())
        }
    }
}

When transitioning to background, Android can kill ordinary services. startForeground() with notification protects against kill. On Android 14, foreground service requires explicit type: android:foregroundServiceType="connectedDevice".

Handling Online/Offline Transitions

Three states to reflect in UI:

  • online — device connected, data current
  • offline — device not responding (LWT fired or timeout)
  • unknown — no connection to broker/backend, status unknown

unknown is separate. If the phone itself lost network, you can't show all devices as offline — that's false. Detect network state via ConnectivityManager.NetworkCallback:

val networkCallback = object : ConnectivityManager.NetworkCallback() {
    override fun onAvailable(network: Network) {
        viewModel.setConnectionState(ConnectionState.CONNECTED)
    }
    override fun onLost(network: Network) {
        viewModel.setConnectionState(ConnectionState.NO_NETWORK)
        // Show "No connection" banner instead of offline statuses
    }
}

UI Indicators

Simple green/red dot — readable but uninformative. Better:

  • Icon + color: green = online, gray = offline, red = error, yellow = warning
  • Last activity time for offline devices: "offline · 2 hours ago"
  • For battery devices — battery level next to status

"2 hours ago" time — not database timestamp directly. Format via DateUtils.getRelativeTimeSpanString() on Android or RelativeDateTimeFormatter — otherwise reopening after an hour shows "3 hours ago" only after screen reload.

Implementing real-time status monitoring with MQTT/WebSocket: 2–4 weeks depending on transport and device count.