Skip to content

Trigger-45/Very-Basic-MQTT-Broker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Very Basic MQTT Broker

Language Protocol Platform License

A lightweight MQTT broker in C for learning and experimentation.

Overview

This project implements a minimal MQTT v3.1.1 broker with multi-client handling via POSIX threads. It is intentionally simple and focused on core publish/subscribe behavior.

Features

  • MQTT v3.1.1 handshake (CONNECT/CONNACK)
  • Multi-client support using one thread per client
  • SUBSCRIBE and topic-based message forwarding
  • PUBLISH routing to matching subscribers
  • Keep-alive via PINGREQ/PINGRESP
  • Configurable broker limits in header files

Requirements

  • GCC (or compatible C compiler)
  • POSIX-compatible system (Linux/Unix)
  • pthread
  • make

Quick Start

Build:

make

Run:

./build/bin/mqtt_broker

The broker listens on port 1883 by default.

Optional Local Test

If mosquitto_pub and mosquitto_sub are installed:

Terminal 1:

./build/bin/mqtt_broker

Terminal 2:

mosquitto_sub -h 127.0.0.1 -p 1883 -t demo/topic

Terminal 3:

mosquitto_pub -h 127.0.0.1 -p 1883 -t demo/topic -m "hello broker"

Supported MQTT Packets

  • CONNECT
  • CONNACK
  • PUBLISH
  • SUBSCRIBE
  • SUBACK
  • PINGREQ
  • PINGRESP
  • DISCONNECT

Project Structure

.
├── include/
│   ├── broker.h             # Broker API and limits
│   └── mqtt.h               # MQTT constants and packet handlers
├── src/
│   ├── main.c               # TCP server and client threading
│   ├── broker.c             # Client/subscription registry and routing
│   └── mqtt.c               # MQTT packet parsing and handlers
├── build/                   # Generated build output
├── Makefile                 # Build targets: all, run, clean
├── README.md
└── LICENSE

Configuration

Defined in source headers:

  • MAX_CLIENTS in include/broker.h
  • MAX_SUBSCRIPTIONS in include/broker.h
  • MAX_TOPIC_LEN in include/broker.h
  • MQTT_PORT in include/mqtt.h

Current Limitations

  • No authentication/authorization
  • No TLS support
  • No retained messages
  • No wildcard topic matching (+, #)
  • Simplified QoS behavior intended for learning

License

Licensed under the MIT License. See LICENSE for details.

About

A lightweight MQTT broker implementation written in pure C, supporting basic pub/sub messaging for IoT applications and learning purposes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors