The rise of the cloud has accelerated the adoption of Internet of Things in consumer and enterprise segments. With storage and computing becoming affordable, data generated by various sensors and devices is aggregated, stored, processed, and analyzed by IoT platforms.
Developers with the background of building mobile and web solutions are acquiring new skills to develop IoT solutions. They are learning to deal with new protocols designed for sensor networks and device communication. Protocols such as MQTT, CoAP, REST, and WebSockets are gaining popularity among the new breed of developers. Many IoT solutions depend on at least a combination of these protocols to connect devices with applications. MQTT and REST are the most popular protocols among IoT developers.
Internet of Things is all about connecting devices, users, and applications. While MQTT has gained popularity for machine-to-machine communication (M2M), REST is the de facto protocol for building connecting applications. DreamFactory is an open source, API-first, REST-enabled platform for developers to build contemporary mobile and web applications. Based on REST, it empowers developers to rapidly integrate legacy data sources with modern applications.
Mosca is open source software to build machine-to-machine (M2M) applications based on MQTT. It acts as a scalable MQTT broker by enabling communication across hundreds of devices. Developers can embed Mosca in their solutions to expose the MQTT protocol for device connectivity.
In a recent project, Mosca has been tightly integrated with DreamFactory to enable developers to create data-centric, REST-enabled, IoT solutions. The lethal combination of DreamFactory and Mosca bring best of both worlds to developers through standard, open source software. This report highlights the IoT use cases and scenarios delivered by DreamFactory platform.
This report highlights some of the benefits of using DreamFactory and Mosca to develop modern IoT applications. It addresses the following aspects:
• The big picture of IoT development platforms
• When to use MQTT
• The role of REST protocol
• How to take advantage of Mosca and DreamFactory
The Big Picture of IoT Development Platforms
An IoT solution has multiple components comprising of devices, applications, and a variety of platform services. The platform plays the key role of securely connecting the devices to applications. It orchestrates the messages generated by the devices while routing the commands sent to appropriate devices by applications.
The platform exposes MQTT and REST to facilitate the communication between devices and applications. Let’s take a closer look at each of these layers.
The devices layer consists of the sensors, microcontrollers, and mechatronics that generate data. Some of the devices such as actuators and switches are responsible for controlling the equipment. While the sensor data is collected by the platform, the actuators and switches receive commands sent by the users and applications.
All the devices participating in the solution get registered with the device registry, which acts as a central repository of all the connected devices. The authentication and authorization policy is managed by the device gateway. It decides if a device can send data to the platform or can receive an event sent by an application. The device registry and device authentication components form the device gateway.
Data Processing Pipeline
The real value of an IoT solution lies in the actionable insights that it generates for the decision makers. The sensor data acquired by the platform is handled by the data processing pipeline. Real-time data is tackled by the hot-path analytics while cold-path analytics perform batch processing on historical datasets. The output of the pipeline is fed to enterprise business intelligence systems.
The rules engine is at the heart of the platform, orchestrating the flow of messages and commands across the system. It decides which device receives the command sent by a user or application. The rules engine tracks the sensor data to see if the data points match pre-defined thresholds and triggers appropriate actions. Business analysts define and declare rules stored and processed by the rules engine.
This layer is responsible for managing the registered users of the solution. Developers will be able to implement single-sign-on (SSO) and Role Based Access Control (RBAC) through the user management component. It either stores the user database or interfaces with an existing repository such as LDAP or a user profile service.
The application layer provides the user experience through control panels and dashboards. Decision makers can take advantage of the rich visualizations offered by dashboards that represent the current state of the devices. Supervisors and operations professionals can control devices through the intuitive interface offered by this layer. Application layer provides UI across web, desktop, mobile, wearables, and televisions.
MQTT – The M2M Protocol
MQTT plays a critical role in IoT by enabling machine-to-machine communication. It is a lightweight protocol designed for devices to exchange messages. It follows a simple publish/subscribe pattern to connect devices in a loosely coupled fashion.
MQTT doesn’t impose rules on the format of messages sent by devices. They can be simple strings, comma-separated values, or JSON payloads. This flexibility makes MQTT an ideal choice of protocol for resource-constrained devices such as microcontrollers and system-on-chip computers (SOC).
The device gateway of an IoT platform exposes MQTT for devices and sensors to talk to each other. They first register with the gateway with a unique identifier and security credentials. Each time they send or receive messages, the gateway authenticates and authorizes them.
REST – The De Facto Protocol of Web and Mobile
While MQTT is best suited for M2M, REST powers all other communications. It’s the most preferred protocol for accessing the platform services from the presentation layer.
Those devices that are capable of running HTTP, ingest the data directly into the data processing pipeline through REST. This enables a high-velocity, high-throughput ingestion when compared to MQTT. IoT Gateways, which represent resourceconstrained devices as a proxy, use REST to ingest aggregated data into the data processing pipeline.
Business intelligence systems that acquire data for rich visualizations and representation, rely on REST. The outcome of a data processing pipeline typically results in an aggregated dataset that contains valuable data. This is exposed through REST for BI dashboards to consume the statistical data.
Finally, the application layer uses REST to send commands to the devices. The platform converts these commands into MQTT messages before routing them through the device gateway.
Since most of the contemporary applications understand REST, IoT platforms expose most capabilities through this protocol, making it the de facto choice of developers.
DreamFactory & Mosca – Best of Both Worlds
As we have seen, robust IoT platforms use a combination of REST and MQTT to deliver the functionality. DreamFactory and Mosca are the most popular platforms for building applications based on REST and MQTT.
DreamFactory is an open source, LAMP-based platform designed to enable developers to build powerful web and mobile applications based on REST. It instantly exposes a REST API for legacy data sources such as SQL Server, Oracle, and DB2. Cloud-native databases such as Amazon DynamoDB and Azure DocumentDB can be easily integrated through DreamFactory. It also supports NoSQL databases such as MongoDB as RESTful backends. The server-side scripting capability of DreamFactory makes it an ideal platform for building a dynamic rules engine. Developers can create triggers before or after committing the data to the backend. In the context of IoT, this becomes a valuable feature for implementing powerful, declarative rules to route the messages and commands.
Mosca is a Node-based, open source software designed to be a lightweight MQTT broker. It powers Ponte, an official M2M platform managed by Eclipse Foundation. Since Mosca is a standalone tool, it can be easily integrated with DreamFactory to deliver MQTT capabilities. The authentication and authorization features of Mosca are tightly integrated with DreamFactory-based device registry. Developers start by calling REST APIs to register devices with DreamFactory. The credentials generated by DreamFactory are used by Mosca to authenticate and authorize the devices. The existing user management layer of DreamFactory is utilized for user profiles, roles, and RBAC. Developers can write stand-alone functions that act as rules for IoT messages. These functions are deployed as server-side scripts within DreamFactory.
In addition to the native capabilities, the DreamFactory + Mosca stack can be easily integrated with Big Data platforms running Apache Kafka, Apache Storm, Apache Spark, Apache HBase, and Apache Hadoop. The data processing pipeline can be easily delegated to an external platform designed to handle hot-path and cold-path analytics.
As mobile and web developers prepare to transition to IoT, they need to apply their existing skills while investing in new protocols and technologies. The combination of DreamFactory and Mosca delivers the right balance between choosing standard web protocols and device-specific protocols. This lethal combination brings the power of REST and MQTT through a single technology stack.
For a detailed walkthrough of setting up the stack and configuring devices, please refer to our tutorial on using MQTT for IoT communication with DreamFactory and Raspberry Pi devices