I’m trying to figure out how to access the MQTT provided by my P1S printer so I can view the print time. I know Bambu Lab has an API however I cannot access it without getting the MQTT to work. Any thoughts?
will get you started. I knew nothing about mqtt, but with the help there I got it working on my P1s exactly as I wanted it.
The only thing is that I’m trying to use Python to access this data, and even when trying to use MQTT explorer I constantly get disconnected from the server.
my solution was written in Python, with the aid of chatgpt. I’m not sure if I gave enough detail back in that thread, maybe you go through it word by word. I was using it with p1s in Lan mode.
My printer is in Lan mode and I have read through that entire thread. Whenever I run the code in python I just get this error ERROR:root:Not connected to the MQTT server. It also says my printer status is unknown. I’m just at a loss at what to do here
I don’t know if this affects what you’re looking for, but Bambu effectively killed MQTT access a while back. Things like X-touch and Panda Touch have to migrate to cloud mode.
Now that’s all I know about it, just didn’t know if you were aware or even if it could be affecting you.
I heard they would be stopping the un-encrypted access to mqtt, but that they were first releasing an api. I have not connected to bbl ‘cloud’ for a very long time, and my x-touch and my mqtt code works fine. There may be a mention on the x-touch discord. I’ll check.
not sure if the following snips of python helps (some values anonymized)
import os
import tkinter as tk
from tkinter import scrolledtext
import paho.mqtt.client as mqtt
import json
import ssl
import threading
import time
import pygame
#Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(file))
#Change the working directory to the script’s directory
os.chdir(script_dir)
#Initialize pygame mixer
pygame.mixer.init()
#MQTT broker details
BROKER_ADDRESS = “xxx.xxx.x.xxx” #your printer ip
BROKER_PORT = 8883
TOPIC_TO_SUBSCRIBE = “device/01P00A392000494/report” # can’t remember where this is from
USERNAME = “bblp” # Replace with your username
PASSWORD = “40918761” # Replace with your password (printer access code from lcd on printer)
#etc,etc
No mention of unusual problems on x-touch discord, afaik. They may answer my question, but it would have been announced when/if bbl screwed it up.
I use it to tell me (text to speech) what the printer is doing. I know little about python script, but manage quite complex results with chatgpt (free version). It was back in June when I was doing this, iirc, so can’t remember much about it. I have no idea of the functions in the imports, I do it on a need to know basis. My trials to get to that point are pretty well documented in that thread I linked to before.
If you can’t get the mttx working, it took me some time, then I’ve no idea.
did you ever figure this out? Im having the same problem with mqtt
MQTT Explorer:
Name: Anything Here
Host: Printer IP
Port: 8883
Username: bblp
Password: Lan Mode Access Code
(I was able to disable lan mode and still read mqtt data. not sure that writing works though.)
click advanced.
delete the topics that are preadded.
In the topic bar type device/Printer Serial/report
Click add. Qos is fine at 0.
after some testing you can still write with Lan Mode disabled on A1 for certain things i believe…
Led ON:
{
“system”: {
“sequence_id”: “312”,
“command”: “ledctrl”,
“led_node”: “chamber_light”,
“led_mode”: “on”,
“led_on_time”: 500,
“led_off_time”: 500,
“loop_times”: 1,
“interval_time”: 1000
}
}
I would expect ‘#’ (without quotes) would work since there is only one broker connected so all topics would be from the single printer.
Two reasons this might be a bad idea. 1. the broker doesn’t support wildcards, or, 2. there is a ton of useless messages that you don’t want to see in any case.
I don’t believe wild cards work. Although it does provide you with a mqtt output every few seconds and nothing seems to be missed. I think bambu made it follow the format containing serial # as an additional safety measure as you can’t read/write without physically knowing the serial.
I can confirm that wild cards do not work, however:
mosquitto_sub -h <ip address> -p 8883 --cafile ./blcert.pem --insecure -u bblp -P <acces code> -t device/<serial number>/status
does work. My problem is that I can’t connect over mqtt in a python3 script. I am using
import paho.mqtt.client as mqtt
and
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,
client_id=SERIAL_NUMBER, protocol=mqtt.MQTTv311)
any help/suggestions would be gratfully appreciated
this worked for me with my P1S
import ssl
import json
import paho.mqtt.client as mqtt
BROKER = "<ip address>"
PORT = 8883
CAFILE = "./blcert.pem"
USERNAME = "bblp"
PASSWORD = "<access code>"
TOPIC = "device/<serial number>/report"
captured_messages = [] # store parsed JSON
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("✅ Connected to broker")
client.subscribe(TOPIC)
else:
print(f"❌ Connection failed with code {rc}")
def on_message(client, userdata, msg):
raw = msg.payload.decode()
try:
data = json.loads(raw) # parse JSON payload
pretty = json.dumps(data, indent=4, sort_keys=True)
print(f"\n📩 MQTT JSON Message ({msg.topic}):\n{pretty}")
captured_messages.append(data)
except json.JSONDecodeError:
print(f"\n⚠️ Non-JSON message received:\n{raw}")
client = mqtt.Client()
client.username_pw_set(USERNAME, PASSWORD)
client.tls_set(
ca_certs=CAFILE,
certfile=None,
keyfile=None,
cert_reqs=ssl.CERT_NONE,
tls_version=ssl.PROTOCOL_TLSv1_2,
)
client.tls_insecure_set(True)
client.on_connect = on_connect
client.on_message = on_message
client.connect(BROKER, PORT, keepalive=60)
print("🚀 Listening for formatted JSON MQTT messages...\n")
client.loop_forever()
I’ve connected to mine using node js. I run a daemon with pm2 that parses the messages and sends me a txt when the print is finished.
However, I do not use the latest firmware that requires Bambu Connector and operate in LAN only mode.
I use this technique on my X1C as well.
As I was busy building my micropython based Raspberry Pico RGB connected leds to connect with MQTT to my P1S. I had a world of trouble finding the right way to connect to it. So I thought I would share my succes.
Using umqtt.simple module on 1.27.0 MicroPython pico W firmware.
This is my code:
def connect_mqtt():
global mqtt_client, mqtt_connected
if not printer_config.get("serial") or not printer_config.get("access_code"):
print("MQTT: No printer configured")
return False
try:
client_id = b'bblp_pico_rgb' + machine.unique_id()
mqtt_client = MQTTClient(
client_id,
printer_config["ip"],
port=8883,
user=b"bblp",
password=printer_config["access_code"].encode(),
keepalive=60,
ssl=True,
ssl_params={}
)
gc.collect()
mqtt_client.set_callback(mqtt_callback)
mqtt_client.connect()
# Subscribe to printer status topics
topic_prefix = b"device/" + printer_config['serial'] + "/report"
print(topic_prefix)
mqtt_connected = True
print("MQTT: Connected to printer")
print("Connected, socket =", mqtt_client.sock)
time.sleep(0.3)
mqtt_client.subscribe(topic_prefix)
return True
print(mqtt_client.__dict__)
except Exception as e:
print("MQTT connection error:", e)
sys.print_exception(e)
mqtt_connected = False
return False
here is the full code I made.
I got everything working for my lights.
And terminal output only shows printer states and percentage.
github .com/wishmaster86/Raspberry-Pi-Pico-W-Bambulab-P1S-MQTT-RGB-lights