Git Product home page Git Product logo

bambuhmi's Introduction

hmi_interface

BambuHMI_v2

Dedicated HMI for Bambu printers running on HA and X1Plus firmware.

PreReqs:

  1. X1C Printer connected to a HA instance (https://github.com/greghesp/ha-bambulab)
  2. X1Plus Firmware installed on your X1C Printer (https://github.com/X1Plus/X1Plus/wiki/Installation-Guide)

How to use:

  1. Use pip to install the necessary dependencies from the requirements.txt file (pip install -r requirements.txt)
  2. Launch setup.py and configure the HA and X1C printer settings and credentials.
  3. Click 'Save Config' then 'Install Files to Printer'.
  4. Optional - Create single app with "pyinstaller main_wCamera.py --icon geometric.ico", be sure to move the fonts & functions folder to the root of the newly built exe.

*Make sure to set static addresses for both your printer and HA instance.

Quick Code References:

The mechanism used to send G-code commands to the printer involves several methods, primarily through MQTT and SSH commands. The process is initiated in different parts of the codebase, depending on the context and the specific action being performed.

  1. MQTT for G-code Commands: G-code commands are sent using MQTT in various macros. This is evident in the send_gcode function within macros like homexyz.py, x_travel_10.py, and others. The mqtt_pub function is called with a JSON payload containing the G-code command.

def send_gcode(gcode_line):

json_payload = {

    "print": {

        "command": "gcode_line",

        "sequence_id": "2001",

        "param": gcode_line

    }

}

mqtt_pub(json.dumps(json_payload))

def mqtt_pub(message):

command = f"source /usr/bin/mqtt_access.sh; mqtt_pub '{message}'"

try:

    subprocess.run(command, shell=True, check=True, executable='/bin/bash')

except subprocess.CalledProcessError as e:

  1. SSH for Remote Command Execution: SSH is used in the BambuHMI SSH Commander to execute Python scripts on the printer, which in turn send G-code commands. This is seen in the commands.py file where SSH commands are used to execute macros like x_travel_-10.py.

def MoveXNegative(self):

    cmd = "/opt/python/bin/python3 /mnt/sdcard/x1plus/macros/x_travel_-10.py"

    if self.ssh_client:

        command_thread = threading.Thread(target=self.execute_command, args=(cmd,))

        command_thread.start()

    else:

        self.append_output("Not connected to any server.")

  1. Direct G-code Command Sending: Direct sending of G-code commands is also facilitated through a DDS (Data Distribution Service) publisher in send_gcode.py, where commands are sent over a DDS network.

def send_command(pub, cmd):

"""Sends a command using DDS publisher."""

msg = {"command": "gcode_line", "param": cmd, "sequence_id": 0}

json_msg = json.dumps(msg)

pub(json_msg)

print(f"Command sent: {cmd}")

def main():

pub = dds.publisher('device/request/print')

time.sleep(3) 

while True:

    cmd = input("Enter the gcode command you want to send or type 'exit' to quit: ")

    if cmd.lower() == 'exit':

        print("Exiting command input.")

        break

    send_command(pub, cmd)

  1. Shell Scripts: Shell scripts like heatbed_set.sh are used to send G-code commands via MQTT, which can be triggered through SSH or other mechanisms.

function set_heatbed_temp() {

temp=$1

json="{ \

    \"print\":{\"command\":\"gcode_line\", \"sequence_id\":\"2002\", \"param\":\"M140 S$temp\"} \

}"

bambuhmi's People

Contributors

christophergault198 avatar scooterthedev avatar jphannifan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.