Skip to content

Instantly share code, notes, and snippets.

@lin-ycv
Created November 14, 2024 11:06
Show Gist options
  • Save lin-ycv/14a8b091ed5d16ed9d519fa3ebc0caf7 to your computer and use it in GitHub Desktop.
Save lin-ycv/14a8b091ed5d16ed9d519fa3ebc0caf7 to your computer and use it in GitHub Desktop.
Simple python script that sends a pause command to a Bambu printer over local MQTT
import ssl
import paho.mqtt.client as mqtt
user = 'bblp'
printer={'ip': '<LAN-IP>', 'sn': '<SERIAL-NUMBER>', 'ac': '<ACCESS-CODE>'}
}
port = 8883
command = '{"print": {"sequence_id": "0", "command": "pause"}}'
def topic(sn):
return f'device/{sn}/request'
client = mqtt.Client(client_id='ThisCanBeAnything',transport='tcp',protocol=mqtt.MQTTv311,clean_session=True)
client.username_pw_set(user,printer['ac'])
client.tls_set(tls_version=ssl.PROTOCOL_TLS, cert_reqs=ssl.CERT_NONE)
client.tls_insecure_set(True)
client.connect(printer['ip'],port)
client.publish(topic(printer['sn']), command)
client.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment