# Connect an External MQTT Client

## Initial Setup and Sending Data (Ingest)

{% stepper %}
{% step %}

#### Sign up for Heisenware

If you haven't done so yet, [sign up and create your account](https://heisenware.cloud/manager/authentication/sign-up) first.
{% endstep %}

{% step %}

#### Generate Client Credentials

Navigate to the App Manager > Integrations page. [Add a new MQTT integration](https://docs.heisenware.com/app-manager/app-manager-overview/integrations-inbound-connections#connecting-mqtt-and-vrpc-clients) to generate the specific username and password for your external MQTT client.
{% endstep %}

{% step %}

#### Configure your MQTT Client

Configure your external client using the connection details and instructions provided in the [MQTT integration guide](https://docs.heisenware.com/app-builder/build-backend/functions-library/connectors/mqtt-client#connecting-an-external-client-to-heisenware). You will need the username and password generated in Step 2.
{% endstep %}

{% step %}

#### Start Publishing Data

Publish some test data on a topic from your external client to Heisenware. This ensures there is data to visualize in the next step.
{% endstep %}

{% step %}

#### Subscribe using the Internal MQTT Client

Your Heisenware tenant includes a default internal MQTT client.

* Open the App Builder for your app.
* Use the [`onJsonMessage`](https://docs.heisenware.com/app-builder/build-backend/functions-library/connectors/mqtt-client#onjsonmessage) (or [`onStringMessage`](https://docs.heisenware.com/app-builder/build-backend/functions-library/connectors/mqtt-client#onstringmessage)) function belonging to the internal client.
* Enter the topic you are publishing on into the function.
* Trigger the function manually. You are now subscribed.&#x20;
* Enable [Test Mode](https://docs.heisenware.com/app-builder/manage-app-lifecycle#app-testing-test-mode) to see incoming data appear inside the event handler.
  {% endstep %}

{% step %}

#### Work with the Incoming Data (Optional)

To process the data, we recommend connecting the event handler to a [memory](https://docs.heisenware.com/app-builder/backend/functionality/utilities/data-processing#memory) function.

* The memory makes the incoming data available as a regular function output.
* From here, you can modify, store, forward, or visualize the data as needed.

<figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FcuPkdVlYh1KI8EiJXnpP%2Fimage.png?alt=media&#x26;token=741dc69c-aaa2-40e4-8735-12cfeb1ecc49" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

## Receiving Data on Your Client (Egress)

{% hint style="info" %}
You must complete the Initial Setup (steps 1–3 above) before proceeding.
{% endhint %}

{% stepper %}
{% step %}

#### Publish Data to the Internal Broker

Use the [`publishJson`](https://docs.heisenware.com/app-builder/build-backend/functions-library/connectors/mqtt-client#publishjson) or [`publishString`](https://docs.heisenware.com/app-builder/build-backend/functions-library/connectors/mqtt-client#publishstring) function in the App Builder to publish data to a specific topic.

You can manually fill the message input box or use dynamic data.

{% hint style="info" %}
The [Data Simulation](https://docs.heisenware.com/app-builder/build-backend/functions-library/utilities/data-simulation) class is a great way to create dynamic data for testing. You can prepare this simulated data using a [modifier](https://docs.heisenware.com/tutorials/integration-guides/broken-reference) before publishing.
{% endhint %}
{% endstep %}

{% step %}

#### Subscribe with your External Client

Configure your external MQTT client to subscribe to the topic you defined in Step 1. You will now receive the data published by Heisenware.
{% endstep %}
{% endstepper %}
