# MQTT protocol

> MQTT is a lightweight publish/subscribe messaging protocol which probably makes it the most suitable for IoT devices&nbsp;Learn more about MQTT.iotBind platform integrates with&nbsp;MQTT.one&nbsp;services to publish messages to Your devices by Your mqtt.one account.what you need:1. Pro iotBind Account&nbsp;To activate the MQTT feature2. Registration&nbsp; in&nbsp;MQTT.one&nbsp;(MQTT Service) to get and use the Broker and Topic&nbsp;Data&nbsp;&nbsp;

> To generate a API key for device, click on the key icon After adding the device And Click on the refresh icon To generate a new key Any time.&nbsp;&nbsp;

After registration in&nbsp;MQTT.one, Add topics you need to use, and back to account in iotBind.com in main menu Click on "MQTT Serviceenter you mqtt.one email and password and Click "link" button, After successful linking Then you'll see all your Broker and topic data&nbsp;&nbsp;

Now your account is ready to publish (messages) and subscribe (topic) by mqtt protocol&nbsp;

connect the device with iotBind by MQTT protocol:- Broker Domain: Same Broker Domain in your&nbsp;MQTT.one&nbsp;account- Port: Same Port in your&nbsp;MQTT.one&nbsp;account- User: Same User in your&nbsp;MQTT.one&nbsp;account- Password: Same Password in your&nbsp;MQTT.one&nbsp;account- Client ID: iotbind-XXXXXXXXX"

publish data from Tank level sensor devices or application to iotBind platform:After link your account with&nbsp;MQTT.one&nbsp;you will see the iotbind/tank/ Topics where you can publish data message to iotBind.

publish Tank level data update from iotBind to any subscribes:iotBind platform can use any topic has permission to publishing a message by your&nbsp;MQTT.one&nbsp;account to Your Any subscribes that subscribe in the same topic After any update of the sensor data&nbsp;&nbsp;

if you need send mqtt data message After any update of the Tank level data go to Tank page and in the Tank device Click in "edit" icon to show the device Setting and enable the "MQTT" publish messages feature and Select the topic you want the iotBind platform to publish messages to

"You can manage your list topics from your&nbsp;MQTT.one&nbsp;account"

Sending and receiving data messages format:Text Message format: json&nbsp;&nbsp;

| Parameter | Value | Description |
| --- | --- | --- |
| uid | UniqueID | Device UniqueIDAlways use it When you want to send an update or get data |
| key | Encrypted key | Device API secret keyAlways use it When you want to send an update or get data |
| cmd | One of these:"on""off""get""ping" | only use one of these commands when you send message to iotbind"on" If you need to send on Command to Device Switch"off" If you need to send off Command to Device Switch"get" If you need get all device data frome iotBind platform"ping" If you need send ping Command to iotBind platform to learn that the device is connectedNote: When the device is connected by MQTT protocol, the connection status will be updated directly by server |
| level | numbers | Use it only for update Tank level |
| temperature | numbers | (optional) Use it only for update Tank temperature |

Examples:After setup your device to contact the MQTT Broker and set publish to Tank Topics in iotBind Platform After any update , For Example:if you need to send the update data by publish MQTT data message to iotBind platform, you need to send a txt json message to the special iotbind/tank/ topic show in your iotBind account&gt;MQTT Service like:&nbsp;&nbsp;

```json
{
    "uid":"Device UniqueID",
    "key":"Device API secret key",
    "level":"Anything",
    "temperature":"Anything"
}
```

if you need to get Tank data by publish MQTT message to iotBind platform, you need to send a txt json massege to the special iotbind/tank/ topic show in your iotBind account&gt;MQTT Service like:

```json
{
     "uid":"Device UniqueID",
     "key":"Device API secret key",
     "cmd":"get"
}
```

iotBind platform publish a json data message to the same topic set on the device Edit page like:&nbsp;&nbsp;

```json
{
     "uid":"UniqueID",
     "name":"DeviceName",
     "type":"Water Level",
     "cmd":"on",
     "level":"67",
     "level_unit":"%",
     "temperature":"21",
     "temperature_unit":"C"
}
```

cmd = "on" the Device is ONcmd = "off" the Device is OFF&nbsp;&nbsp;

if you make switch With tank level sensor and you need to control it ,you can use mobile app to send the "on" or "off" request to the Device, your device get a txt json massege in the same topic devise subscribe like:

```json
{
    "uid":"UniqueID",
    "name":"DeviceName",
    "type":"Water Level",
    "cmd":"on",
    "level":"67",
    "level_unit":"%",
    "temperature":"21",
    "temperature_unit":"C"
}
```

cmd = "on" the Device is ONcmd = "off" the Device is OFF&nbsp;&nbsp;

if you need to send the "on" or "off" request by publish MQTT data message to iotBind platform, you need to send a txt json data message to the special iotbind/tank/ topic show in your iotBind account&gt;MQTT Service like:

```json
{
    "uid":"UniqueID",
    "key":"Device API secret key",
    "cmd":"on"
}
```

cmd = "on" the Device is ONcmd = "off" the Device is OFF&nbsp;&nbsp;

You can send and update all data together like:

&nbsp;&nbsp;

```json
{
    "uid":"UniqueID",
    "key":"Device API secret key",
    "cmd":"on",
    "level":"67",
    "temperature":"21"
}
```

cmd = "on" the Device is ONcmd = "off" the Device is OFF&nbsp;&nbsp;

If you want send ping Command to iotBind platform to learn that the device is connected by publish MQTT message to iotBind platform, you need to send a txt json massege to the special iotbind/tank/ topic show in your iotBind account&gt;MQTT Service like:

```json
{
     "uid":"Device UniqueID",
     "key":"Device API secret key",
     "cmd":"ping"
}
```

Note: When the device is connected by MQTT protocol, the connection status will be updated directly by server&nbsp;&nbsp;

