Simpler than your ex, smarter than PubSubClient.
InitMQTT is a π₯ firestarter MQTT wrapper for ESP8266/ESP32 that gets rid of the boring boilerplate.
No more client.setCallback(...), loop(), reconnect(), and what-do-I-even-do-with-this-payload[].
We've done the heavy lifting, so you can vibe and code.
- β
connect(server, port, user, pass)β dead simple - β
put(topic, value)β forString,int,float - β
putRetain(...)β because memory is good - β
get(topic)β cached last message like your browser tabs - β
subscribe(topic)β easy, no drama - β
setCallback(fn)β get your messages without stress - β
onReconnect(fn)β auto-sync like a king - β
refresh()β your newloop(), but cooler - π Uses SSL by default (yes, we care about your security)
- π‘ Works with HiveMQ, Mosquitto, AWS β anything MQTT
β Built over
PubSubClient, but we made it feel like you're using an API from 2025.
#include <InitMQTT.h>
InitMQTT mqtt;
void onMsg(const char* topic, const char* msg) {
if (String(topic) == "device/led") {
digitalWrite(LED_BUILTIN, String(msg) == "1" ? LOW : HIGH);
}
}
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
WiFi.begin("YourSSID", "YourPassword");
while (WiFi.status() != WL_CONNECTED) delay(500);
mqtt.setCallback(onMsg);
mqtt.connect("broker.hivemq.com", 1883);
mqtt.subscribe("device/led");
}
void loop() {
mqtt.refresh();
}
Yeah, we use it under the hood β but:
- β Setting up callbacks is messy
- β You have to track subscriptions manually
- β You keep copy-pasting reconnect boilerplate
- β You lose retained messages on reboot (unless you fight it)
We fixed that. Like an adult.
Check out examples/usages/ for:
BasicConnect.inoβ Hello MQTTControlLED.inoβ LED dance partyPutRetain.inoβ Because state mattersGetLatestMessage.inoβ Read last message like your chat logsWithAuth.inoβ Secure like your password managerOnReconnect.inoβ Sync up when MQTT ghosted you
Siam Rayhan instagram.com/thesiamrayhan
- π¬ DM friendly
- π» Built it for my own projects, open-sourcing for the homies
- βοΈ Future-ready IoT libraries are coming π
MIT β Use it, fork it, make millions with it. Just donβt sell it back to me π
This ain't just another wrapper. This is InitMQTT β where your ESP talks like it knows what it's doing.
π§ Less code, more control. You're welcome.