Managed MQTT Cloud

MQTT Broker for Students and Classrooms: Running IoT Labs Without Servers

A practical guide for teachers and students: use a public broker for live demos, give each team an isolated free broker for graded work, and avoid the classic classroom pitfalls.

MQTT broker for students illustration showing a classroom of teams with ESP32 boards and laptops publishing to a shared cloud broker
Run this on your own MQTT brokerGet a private, managed MQTT broker on the Free plan and start from ready-made code samples.
Try it free Code samples No card required

Choosing an MQTT broker for students is mostly about removing friction: nobody should lose a lab session to installing Mosquitto, fighting a campus firewall or tracking down which team's sensor is flooding a shared topic. This guide shows teachers how to run IoT labs with broker.connectmq.com for live demos and an isolated free ConnectMQ Serverless broker per team for graded projects, with a lesson sequence, ready-to-run code and classroom rules that prevent the usual chaos.

What a Classroom Needs from a Broker

Teaching MQTT has different priorities from running production systems:

  • Zero setup on lab machines. Students should be publishing in the first ten minutes.
  • Reachable from anywhere. Lab PCs, students' laptops at home and ESP32 boards on campus Wi-Fi all need the same endpoint.
  • Visible traffic. Seeing messages flow is the "aha" moment; a topic explorer helps enormously.
  • Isolation for assessment. A graded project must not be broken by another team publishing to the same topic.
  • No cost. Most courses have no budget for per-student infrastructure.

A self-hosted broker on a lab server can work, but someone has to maintain it, open ports and fix it when it breaks at 9 a.m. on lab day. A hosted service avoids that. For the background concept, students can start with what an MQTT broker does.

Two-Tier Setup: Public for Demos, Private for Projects

Use Broker Authentication Isolation Why
Lecture demos, first labs broker.connectmq.com (public area) None, any unique client ID None, world-readable Instant start, everyone sees everything
Team projects, graded work ConnectMQ Serverless (Free), one per team Generated username, password, client ID Isolated tenant Teams cannot interfere, credentials teach good practice

The Public Broker for Demos

The public MQTT test broker accepts anonymous connections on 1883, 8883, 8083 and 8084. Its limits suit teaching well: 64 KB per message, 10 messages per second per client, 10 subscriptions per client, 8 topic levels, QoS 0 to 2 and sessions up to 30 minutes. Those limits also prevent a runaway loop in a student's code from overwhelming anything.

The public area is readable by everyone on the internet. Make that a teaching point rather than a footnote: never publish names, student numbers, locations or anything else personal there.

Private Serverless Brokers for Graded Projects

Each team signs up for a free ConnectMQ Serverless broker. They get a username, password and client ID, up to 25 connections, QoS up to 1 and 256 KB messages, which is ample for a project with several sensors, a dashboard and a Node-RED flow. Teams can show their work in the portal's in-browser client, live topic explorer and dashboard, and configure threshold alert rules, which makes for a good demonstration during assessment.

A Five-Lab Sequence

Lab 1: Publish and Subscribe from the Command Line

Each student picks a short random ID, for example their initials plus four random characters. Two terminals:

# Terminal 1
mosquitto_sub -h broker.connectmq.com -p 1883 -i sub-ab7k2q -t 'connectmq/demo/ab7k2q/#' -v

# Terminal 2
mosquitto_pub -h broker.connectmq.com -p 1883 -i pub-ab7k2q \
  -t 'connectmq/demo/ab7k2q/hello' -m 'my first MQTT message'

Then the teacher subscribes to connectmq/demo/+/hello and the class watches messages arrive. This one command teaches topics, wildcards and decoupling better than a slide.

Lab 2: QoS, Retained Messages and Last Will

Publish a retained message, disconnect, reconnect and observe it arrive immediately. Kill a client with a Last Will registered and watch the will appear. Pair this lab with MQTT QoS levels explained.

Lab 3: A Python Sensor Simulator

import json
import random
import time
import uuid

import paho.mqtt.client as mqtt

STUDENT_ID = "ab7k2q"  # change to your own random ID
BASE = f"connectmq/demo/{STUDENT_ID}/room"

client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,
                     client_id=f"py-{STUDENT_ID}-{uuid.uuid4().hex[:4]}")
client.will_set(f"{BASE}/status", "offline", qos=1, retain=True)


def on_connect(client, userdata, flags, reason_code, properties):
    print("Connected:", reason_code)
    client.publish(f"{BASE}/status", "online", qos=1, retain=True)
    client.subscribe(f"{BASE}/setpoint")


def on_message(client, userdata, msg):
    print("New setpoint:", msg.payload.decode())


client.on_connect = on_connect
client.on_message = on_message
client.connect("broker.connectmq.com", 1883, keepalive=60)
client.loop_start()

while True:
    reading = {"temp": round(random.uniform(19.0, 24.0), 1), "ts": int(time.time())}
    client.publish(f"{BASE}/temperature", json.dumps(reading), qos=1)
    print("Sent", reading)
    time.sleep(2)

Install with pip install paho-mqtt. Students then publish a setpoint from the command line and see their script react.

Lab 4: Hardware

Move to ESP32 boards. The ESP32 MQTT tutorial gets a board publishing in one session; teams then add a real sensor. Campus Wi-Fi with a captive portal or WPA2-Enterprise often blocks embedded boards, so test the network before the lab or bring a dedicated access point.

Lab 5: Team Project on a Private Broker

Teams create their own Serverless broker, switch to port 8883 with TLS and credentials, and build something end to end: sensors, a Node-RED or web dashboard, and an alert. The jump from anonymous to authenticated connections is itself a security lesson; point teams to MQTT security best practices.

Classroom Rules That Prevent Chaos

  1. Every client ID must be unique. Two students using esp32 as their client ID will disconnect each other endlessly; this is the single most common lab problem.
  2. Every topic starts with your own prefix. On the public broker, connectmq/demo/<your-random-id>/.... No publishing to someone else's prefix.
  3. No personal data on the public broker. Treat it as a public noticeboard.
  4. Add a delay to every publish loop. A while True without sleep hits the rate limit instantly.
  5. Credentials never go into a public Git repository. Use a config file listed in .gitignore or environment variables.
  6. Keep topic depth sensible. The public broker allows 8 levels.

Troubleshooting in the Lab

Symptom Likely cause Fix
Client connects then disconnects repeatedly Duplicate client ID Use a unique random ID
Nothing arrives Topic typo or case mismatch Topics are case-sensitive; subscribe to prefix/# to see everything
Connection refused on campus Port blocked Try 8883, or WebSocket on 8084 from a browser
Messages stop after a burst Rate limit on public broker Add a delay between publishes
ESP32 never joins Wi-Fi Enterprise or captive-portal network Use a lab access point or phone hotspot
TLS error on private broker Wrong port or missing CA Use 8883 with the system CA store

Managing Credentials for a Whole Class

Private brokers mean credentials, and credentials in a classroom go astray. Ask each team to nominate one member who creates the broker and shares credentials only within the team through the course platform, not in a public chat. Encourage teams to keep a small config.example file in their repository with placeholder values and the real file excluded from version control. At the end of the course, teams can delete or regenerate their credentials, which doubles as a short lesson in credential rotation.

Assessment Ideas

Assessing MQTT work is easiest when it is observable. Ask teams to present a topic tree in the topic explorer and justify its design, demonstrate a Last Will turning a device offline on the dashboard, show an alert rule firing, and explain their QoS choices. A short written reflection on what would change for production, such as per-device credentials, TLS everywhere or capacity, rounds it off. Our MQTT tutorial works well as pre-reading, and the cloud MQTT broker guide gives advanced students the bigger picture of hosting choices.

Start Your IoT Lab with ConnectMQ

Run your first demo on broker.connectmq.com today with no sign-up, then have each team create a free Serverless broker at app.connectmq.com with no credit card. ConnectMQ is a managed MQTT broker, so you teach MQTT instead of server administration.

Frequently Asked Questions

Is there a free MQTT broker for students?

Yes. broker.connectmq.com offers a free public area for demos, and each student or team can create a free ConnectMQ Serverless broker with private credentials and up to 25 connections.

Can students use the public broker for their final project?

It works technically, but everything there is world-readable and another student could publish to the same topics. Use a private Serverless broker for graded work.

Do students need to install a broker locally?

No. Clients such as mosquitto_pub, paho-mqtt or the portal's in-browser client are enough, which saves lab setup time.

Why do students keep getting disconnected?

Almost always because two clients share a client ID. Each connection needs its own unique ID.

Can we use ESP32 boards on campus Wi-Fi?

Often only on networks with simple WPA2 passwords. Enterprise authentication and captive portals usually block boards, so a dedicated lab access point is the reliable option.

Related articles

BYOC MQTT Broker: Bring Your Own Cloud Explained

A BYOC MQTT broker runs in your cloud account but is operated by a provider. Learn how the model works, the responsibility split, and how to prepare your account for it.

7 min read

All articles →

Your private MQTT broker is a few clicks away

Create an account, get your broker credentials and connect your first device — no servers to install, patch or scale.