Keep your broker, add a remote dashboard

Send MQTT sensor data to an online dashboard

SensorConsole runs on web hosting, which serves web requests but cannot run an always-on MQTT broker. That does not stop MQTT sensors from using it. A small script next to your broker subscribes to your topics and forwards the latest values to SensorConsole once a minute. Your devices stay untouched, and you gain remote charts, a permanent history and silent-device alerts.

Connect MQTT — free

What you can monitor

How to connect MQTT online

  1. Create a generic push device In SensorConsole, choose Connect a sensor, pick Generic/DIY push, and copy the token.
  2. Install the library Run pip install paho-mqtt on the machine that will run the script. Version 2 or newer.
  3. Save the script below Set your broker address, the topic pattern and YOUR_TOKEN.
  4. Run it After a minute the script prints a line ending in 200 and the readings appear on the device page. Use a systemd service to keep it running after reboots.
import json
import threading
import time
import urllib.request

import paho.mqtt.client as mqtt

BROKER_HOST = "localhost"
BROKER_PORT = 1883
TOPIC = "greenhouse/#"
TOKEN = "YOUR_TOKEN"
PUSH_URL = "https://sensorconsole.com/ingest-generic-push.php?token=" + TOKEN
SEND_EVERY_SECONDS = 60

latest = {}
lock = threading.Lock()


def on_connect(client, userdata, flags, reason_code, properties):
    print("Connected to the broker:", reason_code)
    client.subscribe(TOPIC)


def on_message(client, userdata, msg):
    # greenhouse/temp_c with payload 21.4 becomes {"temp_c": 21.4}
    name = msg.topic.split("/")[-1]
    try:
        value = float(msg.payload.decode())
    except ValueError:
        return
    with lock:
        latest[name] = value


def send_latest():
    with lock:
        data = dict(latest)
        latest.clear()
    if not data:
        return
    request = urllib.request.Request(
        PUSH_URL,
        data=json.dumps(data).encode(),
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urllib.request.urlopen(request, timeout=15) as response:
            print("Sent", data, "->", response.status)
    except Exception as error:
        print("Send failed:", error)


def main():
    client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect(BROKER_HOST, BROKER_PORT)
    client.loop_start()
    while True:
        time.sleep(SEND_EVERY_SECONDS)
        send_latest()


if __name__ == "__main__":
    main()

YOUR_TOKEN is the device token shown on your device page after you create a generic push device.

Use cases

Home automation on Mosquitto

Look at your sensors from outside the house without opening your broker to the internet.

Zigbee sensors through Zigbee2MQTT

Long-term history for temperature and humidity sensors.

Mixed devices

Tasmota, ESPHome and homemade boards on one dashboard.

Questions about MQTT and SensorConsole

Does SensorConsole accept MQTT directly?

No. It receives web requests. A forwarder script bridges your broker to it, and the script on this page does that.

Do I have to open my broker to the internet?

No. The script runs inside your network and only makes outgoing web requests.

Can I use Node-RED or Home Assistant instead of Python?

Yes. Both can subscribe to MQTT and send a web request. See the Node-RED and Home Assistant pages.

How often are readings sent?

The script sends the newest values once a minute. SensorConsole accepts one reading per device every 10 seconds at most.

Guides

Technical · 3 min read Send MQTT sensor data to an online dashboard Technical · 4 min read What is MQTT? A plain explanation for sensor projects Technical · 3 min read HTTP or MQTT for sensor data: which should you use?

How the data gets there

MQTT broker → forwarder script → HTTP request → SensorConsole

See how every supported device connects →

Also works with