I need to make a simple proof of concept, having an Arduino or ESP32 with a couple of LEDs than can be turned on/off via browser.

There are a lot of examples about having a small server in the Arduino and accessing it via browser. However for my project I want to use an MQTT broker.

The part where the Arduino updates the LED when a value is changed in the MQTT server is done and works well.

However what I need now it a way of posting a message to the MQTT server just by accessing a website.

Something like: if you open the following link the LED will turn ON: www.mymqttserverdomain.com?LED1=1

  • 1
    I'm not sure I understand the issue? You just need a script that will connect to your MQTT broker and post a message. Just have to pick a web server and a language to write your script in. Of course once you go beyond the POC phase you'll probably need to add some authentication or other security...
    – jcaron
    Aug 27, 2021 at 15:28
  • use an MQTT client
    – jsotola
    Aug 27, 2021 at 22:48
  • One other option is to have a static web page which has a javascript mqtt client. In the page, you can connect to that MQTT server and publish an MQTT message. Of course, beyond poc and even beyond local network for poc, you'll have to put in some security Aug 28, 2021 at 2:26

2 Answers 2


Assuming your broker supports MQTT over WebSockets, just run a MQTT client in the webpage and have it send the messages directly.

There is a Paho JavaScript client and nearly all brokers support WebSockets these days


You can, but you must use port 1883 to connect your client with a broker. Here I uploaded a Python code for that

from flask import Flask

import paho.mqtt.client as mqtt

app = Flask(__name__)

def on_message(client, userdata, message) :
    print("Received message: ", str(message.payload.decode("utf-8","ignore")))

mqttBroker = "broker.emqx.io"

client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, "Webpage")
client.on_message = on_message


def send(msg):
    if msg == '1':
        client.publish("abc", "ON")
    elif msg == '0':
        client.publish("abc", "OFF")
    return "ok"

if __name__ == '__main__':

Note - To turn on your LED1 You have to use this link "<your_gateway>/LED1/1"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.