Simplifying IoT Connectivity with myDevices and MongoDB

Dr. Humza Akhtar

#IoT

In the highly competitive era of Industry 4.0, companies that are able to adopt emerging Internet of Things (IoT) technologies and shift from traditional offerings to digitally differentiated ones are moving to the forefront of their respective industries. McKinsey & Company estimates that by 2030, IoT could enable $5.5 trillion to $12.6 trillion in value globally, including the value captured by consumers and customers of IoT products and services. From smart thermostats to smart factories, IoT already connects billions of devices worldwide.

Figure 1 shows potential areas where IoT solutions make a difference.

Figure 1:  IoT applications by industry (non-exhaustive).

All of these IoT applications and solutions require technologies that can offer low-power operation, low-cost, and low complexity in setting up and maintaining end devices. End devices that are able to communicate wirelessly over large distances with low-power consumption are key. The data generated by IoT devices is time series and high frequency, placing a unique strain on the underlying data infrastructure. Because of the polymorphic nature of IoT sensor data, the database must support flexible data schemas, making it easy for developers to work with the data. It must also ensure that the IoT applications are resilient to future changes.

MongoDB embraces the variety and volume of IoT data without compromising on performance. Through its document model, MongoDB eliminates data movement and blends time series with the rest of the enterprise data in a single developer data platform. In this article, we’ll describe how myDevices leverages the MongoDB developer data platform for IoT.

Overview of myDevices

myDevices is a U.S.-based IoT solutions company that empowers system integrators, MSPs, ISVs, VARS, and enterprise customers to quickly deploy IoT solutions to their customers. The company has more than 1000 plug and play sensors and multiple Long Range Wide Area Network (LoRaWAN) gateway options to create IoT solutions for a variety of use cases.

Over time, myDevices has created the world’s most extensive IoT device catalog from more than 150 hardware manufacturers around the globe. LoRaWAN offers unique IoT benefits, such as long range and coverage, which may reach up to 15 kilometers in line of sight (LOS). It offers ultra-low power consumption for end devices, low-cost infrastructure, and high capacity, which makes it possible to link thousands of devices to one single gateway.

myDevices understands that connecting devices from disparate manufacturers can be very challenging; thus, they have created a no-code solution that includes plug-and-play templates to connect sensors to the gateway just by scanning a QR code. After the sensor is connected to the gateway, users can perform remote monitoring and device management from a single-view interface. They can also get alerts through text and email and set up charts for visualization of sensor data.

The alert rules can be configured as time based or threshold based in the myDevices platform. The myDevices IoT platform is secure from the edge to the application layer through the cloud. The security is composed of LoRaWAN network security at the edge, TLS to the cloud, and SAML at the application layer. Figure 2 shows the architecture of the myDevices platform and how it connects to the sensors.

Figure 2:  MyDevices architecture.

myDevices also has multiple ready-to-go solutions for a variety of IoT use cases and applications. From machine health predictive maintenance to soil moisture detection, there are sensors that just work with the IoT in a box application. It takes only minutes to set up connectivity between the sensor and myDevices cloud, and myDevices enhances productivity because you don’t have to worry about writing code to extract data from the sensors and establishing secure connectivity with the gateway.

As LoRaWAN enables hundreds, if not thousands, of sensors sending data to a single gateway, it requires a database that can easily and automatically scale. When it comes to publishing data out of myDevices cloud to MongoDB Atlas, myDevices provides a webhook integration functionality that can be set up in minutes to establish connectivity between the two systems.

Database requirements for IoT and MongoDB Atlas

MongoDB and MongoDB Atlas are ideal partners for any IoT deployment, offering:

  • Deployment flexibility (on-premises, in-field, cloud)

  • Multi-cloud flexibility (AWS, Azure, GCP)

  • Schema flexibility (frequent changes and additions)

  • The ability to blend different data (time series, operational)

  • Real-time analytics readiness

  • Automated data tiering

As a result, IoT data platforms and service providers, such as Bosch and Software AG, as well as some of the world’s most intensive IoT users, including Toyota, Mercedes-Benz, and Vodafone, choose MongoDB for their IoT platforms and services.

MongoDB’s developer data platform supports the entire IoT data life cycle, from ingestion, storage, querying, real-time analytics, and visualization to online archiving (Figure 3). MongoDB Atlas brings the core components of real-time analytics into one developer data platform.

Figure 3:  MongoDB Developer Data Platform for IoT.

Let's talk about a few features that directly support IoT applications:

  1. Native time series platform: MongoDB supports native time series collections with hands-free schema optimization supporting high-efficiency storage and low-latency queries. This is an extremely important feature for IoT applications.

  2. Change streams: MongoDB change streams allow applications to access real-time data changes in the database without any complexity or risk. IoT applications can use change streams to subscribe to all data changes on a single collection, a database or an entire deployment and immediately react to them. This approach enables quick response time and fast decision making.

  3. Aggregation framework: By using the built-in aggregation framework in MongoDB, users are able to do real-time analytics without having to move the data to another platform. By using the aggregation framework, the work is done inside MongoDB, and the final results can be sent to the application, typically resulting in a smaller amount of data being moved around. For IoT applications, this can be a powerful tool to only transmit the filtered data to the Cloud or central storage resulting in improved security and reduced cost.

  4. Data Lake: As data is ingested, Atlas Data Lake automatically optimizes and partitions the data in a format and structure best for analytical queries. This capability significantly reduces the complexity of transforming data for the data scientist tasked with building machine learning models for analytical use cases and applications

  5. Data Federation: Atlas Data Federation provides the ability to federate queries across data stored in various supported storage formats, including Atlas Clusters, Data Lake Datasets, AWS S3 buckets, and HTTP stores. This feature reduces complexity of bringing data together for analytical model testing purposes.

  6. Data API: Companies can use Atlas Data API to integrate Atlas into any apps and services that support HTTPS requests. Leveraging this feature, the data from the myDevices cloud can be sent to Atlas and then used for storage and for analytical purposes using the aggregation framework or via the Atlas ecosystem connectors with third-party analytical software.

  7. Ecosystem integration: MongoDB Spark Connector opens up access to all Spark libraries for use with MongoDB datasets: Datasets for analysis with SQL (benefiting from automatic schema inference), streaming, machine learning, and graph APIs.

  8. Charts: MongoDB Charts is the best way to visualize IoT data stored in MongoDB. Charts is built specifically for the document model, no ETL, no time loss to data manipulation or duplication required to visualize rich JSON data. Using Charts, powerful engaging data experiences can be created for the use case stakeholders in no time.

Integrating Atlas and myDevices using Webhooks and Data API

myDevices offers a variety of no-code integrations for its clients to quickly get started by sending data to the platform of their choice. For MongoDB Atlas clients, this is great news because, by using myDevices Webhook integrator and payload transformation feature, MongoDB Atlas clients can receive and store LoRa sensor data into the specified collection.

Let’s run through the methodology to perform this integration:

Step 1: Log into your Atlas Cluster and set up Data API and API key.

The MongoDB Atlas Data API lets you read and write data in Atlas with standard HTTPS requests. To use the Data API, all you need is an HTTPS client and a valid API key. It is important to understand that the Data API is not a direct connection to the MongoDB database. Instead, it routes requests through a fully managed middleware layer, called Atlas App Services, that sits between your cluster and client apps. This layer handles user authentication and enforces data access rules to ensure that the data is secure.

The Data API supports two types of endpoints:

  • Data API endpoints are automatically generated endpoints that each represent a MongoDB operation. You can use the endpoints to create, read, update, delete, and aggregate documents in a MongoDB data source.

  • Custom endpoints are app-specific API routes handled by functions that you write. You can use custom endpoints to run your app's backend logic or as webhooks that integrate with external services.

In this example, we are using a data API endpoint. You can follow these easy steps to enable Data API and create a Data API Key.

Step 2: Log in your myDevices Console and set up integrations

After you log in, click on new webhook creation through the INTEGRATIONS option on the right-hand panel (Figure 4). For the purpose of this article, we are assuming that you have already created an organization in myDevices and added sensors and gateways to it. If you have not, please refer to myDevices API docs to get started.

Figure 4:  Set up integrations in myDevices.

Step 3: Click on Webhook integration to open up the new Webhook creation panel.

In this step, choose Webhook as the desired integration option, as shown in Figure 5.

Figure 5:  Choose Webhook as the integration option.

Step 4: Add key information.

In this step, you’ll want to include key information, such as Url, which is your Data API endpoint, Webhook Header, which will include the api-key at the very minimum, and the payload transform script, where you can specify the cluster, database, and collection where this sensor data needs to be stored (Figure 6).

Figure 6:  Paste the endpoint generated by Data API in Atlas.

An example payload transformation script looks like the following. This is according to Data API requirements where you have to specify the cluster, database and collection name in the raw body data.

function Transform(event, metadata) {
  return {
    dataSource: "my_cluster",
    database: "my_database",
    collection: "current_sensor",
    document: event,
  };
}

Step 5: Save your webhook.

Once you save your webhook, you can observe sensor data flowing into your MongoDB Atlas collection from the actual device using MongoDB Compass or Atlas Charts (Figure 7). For more details on how to create Charts, please visit the Atlas Charts documentation.

Figure 7: Visualize sensor data using Atlas Charts.

Conclusion

We have shown how easy it is to connect myDevices IoT platform with MongoDB using the Data API. The overall architecture is shown in Figure 8.

Figure 8: End-to-end architecture of myDevices and MongoDB Atlas integration.

Simplifying IoT connectivity is of paramount importance for any organization looking to embark on a digital transformation journey. Fortunately, both myDevices and MongoDB Atlas provide platforms that simplify management of the full life cycle of an IoT device from provisioning to connectivity to data storage and archival.

To learn more about how MongoDB enables IoT for our customers, please visit our IoT use cases page.