--- title: MQTT Module hide_title: true --- import CopyToClipboardButton from '../../../src/components/copytoclipboardbutton' # MQTT Module This module contains basic nodes for communicating with an MQTT broker. This is for example useful when communicating with multiple devices or when building an IoT project. In this guide we will create a small MQTT communication example using the _Send Message_ and _Receive Message_ nodes available in the MQTT module. ## Overview MQTT is a very popular communication protocol between IoT devices. It's based on a simple publisher/subscriber architecture where all messages pass through an MQTT broker, who directs messages from publishers to subscribers. As a subscriber, you subscribe to _topics_, which are typically made up of different subpaths. As a publisher of messages, you publish your messages to these topics. A message can contain a _payload_, i.e. a data object with one or more pieces of data. As an example, an IoT thermometer, called "thermometer1", may publish temperature and pressure data to "/thermometer1/thermometer" topic with a payload containing a time, a temperature and a pressure reading. MQTT is a very capable protocol and we will only cover parts of it in this guide. You can read more about it [here](https://en.wikipedia.org/wiki/MQTT); ## Using the the MQTT module First, let's create a new project using the minimal "Hello" template. Give the project a name, for example "MQTT Messaging". Since the MQTT nodes are not part of the default node set in Noodl, we need to enable the MQTT module. Find the module tab in the sidebar and add the "MQTT" module. Now two more nodes are available in your project, the [**Send Message**](/library/modules/mqtt/send-message) and [**Receive Message**](/library/modules/mqtt/receive-message) nodes.  Try adding a **Send Message** and **Receive Message** node to the project, to see that they are now available. ## Connecting to an MQTT broker For the MQTT messaging to work, we need to connect to an MQTT broker. Setting up and hosting a commercial, secure MQTT broker is a bit of a hassle. So for this guide we will instead use the open MQTT broker "Shiftr". It's being hosted in the cloud so we don't need to worry about hosting it. Another good alternative is the open source broker [Mosquitto](https://mosquitto.org/) that you can run locally or host yourself. Go to [shiftr.io](http://shiftr.io) and sign up for an account if you don't already have one. Also create a new "Name space" and a "Token" for the namespace. In the end you should have created an MQTT endpoint to use, similar to the one below.  Now go into your project settings and paste in the URL (beginning with "mqtt:") into the "Broker URL" field.  ## Testing our MQTT broker Ok, now we have everything to get started to send MQTT messages. Let's try it! Start by adding a "Send Message" node. Set its topic to "mytopic" and add a payload called "myvalue".  Now let's send our first message to the topic "mytopic". So we assign a value to the input "myvalue", using a **Number** node and connect the _Send_ signal to the click event of the background **Group**. Any value is fine, we just want to see if it's working.  When you start clicking the background rectangle, you should now be sending messages to the MQTT broker. If you bring up you web browser with your Shiftr name space topology you should be seeing some events entering the system everytime you click. Again, remember that the MQTT messages are being sent to a router hosted somewhere in the cloud, which means that any device with an internet connection can now connect to your Noodl app, or vice versa, by sending messages to the router.