iOS MQTT Client Setup

Text Copied

Introduction

MQTT (Message Queuing Telemetry Transport) is a lightweight publish/subscribe messaging protocol widely used in IoT applications. On iOS, you can integrate MQTT into your apps using frameworks like CocoaMQTT or Moscapsule if you want to build from scratch.

For quick testing and practical use, however, you don’t need to write any code. Instead, you can use the IoT MQTT Panel app, available on the App Store. This app provides an easy way to connect to an MQTT broker, subscribe to topics, publish messages, and visualize IoT data directly from your iPhone or iPad.

Pre-requisites

Before you begin, make sure you have:

  • An iPhone or iPad with IoT MQTT Panel installed (from the App Store).

MQTT Connect

Make sure you have the broker details (hostname, port, username/password, CA certificate) handy.

  • Open IoT MQTT Panel.
  • Tap “+” to add a new connection.
  • Fill in the following fields:
    • Connection Name: Any friendly name (e.g., Test1).
    • Client ID: A unique identifier (e.g., Testclient-104).
    • Broker Address: (e.g., crystalmq.bevywise.com)
    • Port: 1883 (default for non-TLS).
    • Network Protocol: Usually TCP.
    • Additional Options: Enter Username & Password if required.
  • Tap Create to save the connection.
  • Select the connection and tap Connect Status will change to Connected if successful.
  • Create a Dashboard for this device.
Add connection


Add dashboard

MQTT Subscribe

  • Once connected, open your connection’s dashboard.
  • Tap “+” Add Panel → Choose Line Graph Panel.
  • Fill in the fields:
    • Panel Name: e.g., TempTrend.
    • Topic: sensor/temp.
    • Label: e.g., Temperature.
    • Graph Options: Configure time window, axis scaling, and auto-scroll as needed.
  • Tap Save.
  • The panel will now plot all numeric values published on sensor/temp.
Select Panel Type


Edit Panel

MQTT Publish

  • On the dashboard, tap “+” Add Panel → Choose Text Input Panel.
  • Fill in the fields:
    • Panel Name: e.g., PublishTemperature.
    • Topic: sensor/temp.
    • QoS: Select QoS level (default = 0).
    • Retain: Toggle ON if you want the broker to retain the last published value.
    • Payload Options:
      • Timestamp: Auto-insert current time.
      • JSON: Wrap input as JSON.
      • Or leave as plain text for numeric input.
  • Tap Save.
  • To publish: enter a value (e.g., 25) and press Send.
  • The Line Graph Panel will instantly update with the new data point.
Edit Panel


Dashboard

MQTT Disconnect

Clean disconnection ensures the broker releases resources tied to the session and avoids lingering socket connections.


  • From the main connection list, tap your broker connection.
  • Select Disconnect (Cloud Icon).
  • The app will stop publishing/subscribing until reconnected.

Troubleshooting

  • Can’t connect to broker

    • Check broker IP/hostname, port, and network protocol.
    • Verify network connectivity.
    • Ensure Client IDs are unique.
  • Not receiving messages

    • Confirm topic matches exactly (sensor/temp is case-sensitive).
    • Ensure data is numeric for Line Graph panel to display correctly.
    • Check QoS mismatch (try QoS 0 first).
  • Can’t connect to broker

    • Double-check username/password.
    • Some brokers require TLS/SSL – use port 8883 and proper certificates.

Monitor MQTT Messages!

Real-Time MQTT on iOS

Subscribe, publish, and monitor MQTT broker messages directly from
your iOS device, enabling instant insights and control.