From ‘Always Connected’ to ‘Fully Off-Grid’: A Case Study in Offline IoT Solutions
WhitespectreWhitespectre
Many IoT devices' Achilles' heel is their dependence on constant connectivity. In this article, we'll guide you through an approach to engineering offline-resilient IoT applications, turning the challenge of disconnection into an opportunity for enhanced functionality.
From robust data modeling to sophisticated synchronization strategies, we'll explore the architectural considerations and engineering principles that make this possible. To illustrate these principles, we will discuss how Whitespectre applied them in our collaboration with SpotOn, a leader in GPS-based virtual fence systems for dogs. Together, we developed an 'off-grid' mode that ensures pet safety in remote areas, enabling owners to take their dogs on backcountry adventures while maintaining the security of a virtual fence.
Drawing from our IoT experience, we've developed a framework of essential considerations for offline scenarios. We'll explore each consideration in detail, then illustrate their real-world impact through our SpotOn project.
The bedrock of any offline-capable system is its data model. We need a clear understanding of:
An application working offline must support at least one locally stored source of data, serving as both a cache for data downloaded from the backend and a fallback when disconnected. A well-structured data layer looks like this:
Reading data is relatively straightforward. The repository chooses the most up-to-date information and provides it to the data reader.
A common strategy here is:
If updating the Network data fails, you have several options:
A more sophisticated approach, often used in social media apps like Facebook or Instagram, is to provide local data immediately while fetching updated data in the background. This allows users to see content quickly, with the app refreshing once new data is available.
While reading data is straightforward, writing is more complex as it requires preparing data for later synchronization and conflict resolution.
There are 3 main writing strategies that your app can take:
The synchronization process happens when the app regains connectivity. Conflict resolution is crucial if the app writes data locally when offline that is misaligned with the network data source.
The choice depends on your specific use case and data update patterns.
Conflict resolution is a topic that deserves special attention. If the app writes data locally when offline that is misaligned with the network data source, a conflict has occurred that you must resolve before synchronization can take place.
To resolve conflicts the system must have a mechanism to decide what’s the last change to apply. Common methods include:
The last-write-wins approach works well for simple data that can be overwritten entirely. However, you'll need a more sophisticated reconciliation process for complex objects with multiple properties that can change independently.
For example:
The specific approach you take will depend on your application domain and the nature of your data. It’s crucial to plan your conflict resolution strategy as an integral part of your offline support implementation.
Remember, effective synchronization and conflict resolution are key to maintaining data integrity and providing a smooth user experience in applications with offline capabilities.
SpotOn's product enables dog owners to create wireless GPS fences, granting their pets safe boundaries to roam. The system comprises:
When a dog approaches the borders, it plays different sounds as alerts. If the dog crosses the boundaries, the collar applies vibration or static correction.
When fully online, the collar provides real-time updates on the dog's location, escape alerts, battery level, and connectivity status. While the collar reports status information to the backend server, all configuration and maintenance occur through the mobile app.
SpotOn’s product is designed for large geographic areas, so many customers reside in rural locations with poor cellular connectivity. While we had already implemented mechanisms to handle periodic connectivity drops, SpotOn envisioned a more ambitious goal: enabling users to go completely “off-grid” while maintaining the product’s core functionality.
Given the potential complexity offline scenarios could introduce, we aligned as a team on two critical questions:
We identified the following critical feature set:
Our guiding principles included:
For our product, the local data is stored in two places:
Since the active fence is stored both in the collar and the app, we can simplify the problem and only care about the synchronization between the app and the backend.
The network data is clearly all the data we have in our backend. One thing to note here is that while the app can be put in offline mode, the hardware could still report data to the backend that we must deal with.
For reading the data, we always use the local store. Using a reactive application allows us to update the application every time the local store is updated, so the problem is reduced to keep the local and network store synchronized, and connect the mobile application to the local store.
For writing the data, we took a lazy update approach: we always update the local storage and push the data to the backend as soon as we have an internet connection.
Finally, for synchronization and conflict resolution, there are two things to consider since the collar might keep sending information to the backend if it occasionally recovers connection:
Once we defined the technical approach and offline considerations, the product team needed to fully scope the feature set and user experience. Rather than engaging in theoretical discussions, we implemented an initial proof of concept (POC) with basic functionality and shared key insights on the implications of offline mode for other features.
This combination of a low-effort POC and tech investigations covered the following areas:
Our application has about 10 core features, but not all of them could be used offline. Some examples include:
The POC and the offline features documentation were then shared with the product and design team, who then defined the final set of features that the app should support according to our use case and a new user experience for each of those features.
Finally, for the implementation, the dev team integrated react-native-cache library to read/write/update the cache, and a synchronization mechanism that works as follows:
We developed the initial version based on the POC and product specifications, then shared it with a group of SpotOn beta testers. Their feedback helped us refine the feature, leading to a full release in Spring 2024. This enabled dog owners to confidently take their pets on off-grid adventures that summer, with overwhelmingly positive reviews.
This guide shows that IoT systems can deliver robust offline capabilities that enhance their overall value with proper architecture and implementation strategies. The key principles for success:
The Most Comprehensive IoT Newsletter for Enterprises
Showcasing the highest-quality content, resources, news, and insights from the world of the Internet of Things. Subscribe to remain informed and up-to-date.
New Podcast Episode
Related Articles