This document will serve as an introduction and user guide to the minimum viable product developed by Integ.ro to provide the structural foundation of the Lake Nona Responsive City Fabric project that will provide useful insights and serve as case studies for future stages of development.
In the following sections of this document, some key concepts and terms of the MQTT messaging protocol will be explained, essential to understand the operation of the proposed system. The proposed solution will be presented and finally a concrete example of an interactive control panel using different sources of information.
An MQTT messaging broker operates through two different channels. The first is responsible for transmitting the emissions that come from the messaging agent or the work service to the broker. The second channel is responsible for disseminating the emissions that enter the broker to all the agents that are subscribed to a specific topic. These emissions are stored in the database before being used in real time to generate graphs or dashboards.
Topic: In the context of MQTT (Message Queuing Telemetry Transport), a topic is a text string used to identify the content or category of a message. MQTT clients can subscribe to certain topics to receive messages related to that specific topic. For example, a topic could be “sensors/temperature” for messages related to sensor temperatures.
Payload: The payload in MQTT refers to the useful part of a message, which contains the data or information being sent. It can be any type of structured information, such as text, a number, a JSON object, among others. For example, if an MQTT message is sent to monitor the temperature of a sensor, the payload could contain the temperature value in numeric format.
Subscribe: Subscribing in MQTT implies that a client wants to receive messages published in certain topics. When a client subscribes to a specific topic, the client will receive all messages published to that topic. This allows customers to stay informed and up-to-date on information relevant to them. For example, a customer could subscribe to the “sensors/temperature” topic to receive updates on temperature readings.
Emit: In the context of MQTT, emit refers to the act of publishing a message to a specific topic. An MQTT client can broadcast a message to send data or information to other clients that are subscribed to that topic. For example, a client could issue a message on the topic “sensors/temperature” to inform other clients about the change in ambient temperature.
Broker: A broker in MQTT is a server that receives messages published by clients and sends them to clients subscribed to the corresponding topics. It acts as an intermediary between clients, ensuring that messages are delivered efficiently and reliably. The broker is fundamental in the MQTT architecture, since it coordinates communication between clients.
Retained Message: A retained message in MQTT is a message that is stored in the broker and delivered to new subscribers as soon as they connect. Allows customers to get the latest information available on a specific topic, even if they have missed previous messages. The held message is identified by a flag at the time of publication.
In this section we will find the topics of route 1, which establishes a connection from the messaging agent, service worker or sensor to the broker.
This topic notifies that there is an agent that wants to connect to the broker, the broker takes its payload and creates or updates the list of payload messaging brokers:
payload = json.dumps({ "name": string })
MQTT_SERVICE_HOST = '134.000.000.000' MQTT_SERVICE_PORT = 1883 payload = json.dumps({ "name": 'cisco-meraki' }) publish.single('connected',payload, hostname=MQTT_SERVICE_HOST, port=MQTT_SERVICE_PORT)
This topic is responsible for sending the selected information in the messaging agent, service worker or sensor to the broker.
payload = json.dumps({ "agent": { "name": "weather" }, "metrics": [{"type": 'weather', "value": data}] })
import paho.mqtt.publish as publish MQTT_SERVICE_HOST = '134.000.000.000' MQTT_SERVICE_PORT = 1883 MQTT_SERVICE_TOPIC = 'agent/message' MQTT_CLIENT_ID = 'openweather-mqtt-service' payload = json.dumps({ "agent": { "name": "weather" }, "metrics": [{"type": 'weather', "value": data}] }) topic = MQTT_SERVICE_TOPIC + '/' + MQTT_CLIENT_ID publish.single(topic, payload, hostname=MQTT_SERVICE_HOST, port=MQTT_SERVICE_PORT,client_id=MQTT_CLIENT_ID)
This topic notifies the broker that an agent has disconnected and the broker is responsible for updating its status in the database.
payload = json.dumps({ "name": string })
MQTT_SERVICE_HOST = '134.000.000.000' MQTT_SERVICE_PORT = 1883 payload = json.dumps({ "name": 'cisco-meraki' }) publish.single('disconnected',payload, hostname=MQTT_SERVICE_HOST, port=MQTT_SERVICE_PORT)
In this section we will find the topics of channel 2, these are published by the messaging broker and are used for dashboards, graphs and real-time monitoring of the information that enters the broker.
This topic notifies all subscribers that a service worker agent or sensor is connected and delivers its information.
payload:{ agent”: { “name”: string, “connected”: Boolean } }
This topic notifies all subscribers that an agent, service worker, or sensor has been disconnected and provides information about the disconnected payload.
payload:{ agent”: { “name”: string, “connected”: Boolean } }
This topic delivers the message delivered by the agent, service worker or sensor to the broker for use in real-time dashboards, filtering this message by the name of the agent, to know which specific topic to subscribe to.
payload = json.dumps({ agent": { name": "weather" }, metrics": [{"type": 'weather', "value": data}] })
All data is stored in a NoSQL MongoDB database available for custom queries. On the other hand, data preprocessing work is carried out using databricks, which queries the database and organizes the information in SQL tables to facilitate querying from Grafana-type visualization tools.
Another methodology in development is through the AWS Lambda service in which a template provided by Integ.ro can be used to preprocess the data.
Below is a detailed technical manual for any device manufacturer to connect to our MQTT network.
To report data via MQTT with a device that already has this technology, it is only necessary to configure the connection parameters in the MQTT client, which include the manufacturer identifier, the IP address or host name of the MQTT broker and the connection port.
MQTT_SERVICE_HOST = '134.000.000.000'
MQTT_SERVICE_PORT = 1883
MQTT_SERVICE_TOPIC = '{your_mqqt_topic}'
MQTT_CLIENT_ID = '{your_mqtt__client_id}'
To report data via MQTT with a device that does not yet have this technology, we have an API to receive the data and redirect it to the MQTT server.
curl --location 'http://127.0.0.1:3001/nomqtt' \ --header 'Content-Type: application/json' \ --data '{ "mqtt_topic": "topic_prueba_nomqtt", "mqtt_client_id": "client_device", "data": { "key1": "value1", "key2": 10 } }'
This POST request provides the functionality to post data to the MQTT broker from devices that do not have MQTT technology built-in. The POST request is sent to a Lambda function that acts as an intermediary to send the data to the specified MQTT broker.
The URL for the POST request is the address of the Lambda function in the cloud.
http://127.0.0.1:3001/nomqtt'
The request body must be in JSON format and must contain two main fields:
The method used to send the request is POST.
Be sure to include the Content-Type header and set it to application/json to indicate that the request body is in JSON format.
The Lambda function processes the request and publishes the data to the MQTT broker. The response from the Lambda function indicates whether the publication was successful or if there were any problems during the process.
Grafana is an open source analytics and visualization platform designed to help users better understand and monitor their data. With its ability to connect to a wide range of data sources, Grafana has become a popular tool for visualizing and monitoring real-time metrics, time series data, and other complex data sets.
It is important to note that while Grafana offers a wide range of functions for visualizing data, there are other similar tools on the market that can also be used for the same purpose.
Grafana provides the ability to integrate MQTT data and effectively visualize it in the form of interactive dashboards and custom graphs. By adding MQTT variables in Grafana, users can select and filter specific data coming from MQTT channels for detailed and contextualized visualization.