Install DWC2

Now we're going to install DWC and Tornado to serve it.

cd ~ 
PYTHONDIR="${HOME}/klippy-env"
virtualenv ${PYTHONDIR} --no-setuptool
${PYTHONDIR}/bin/pip install tornado==5.1.1
git clone https://github.com/Stephan3/dwc2-for-klipper.git
ln -s ~/dwc2-for-klipper/web_dwc2.py ~/klipper/klippy/extras/web_dwc2.py 

Now we in install DWC

mkdir -p ~/sdcard/dwc2/web 
cd ~/sdcard/dwc2/web 
wget https://github.com/chrishamm/DuetWebControl/releases/download/2.0.7/DuetWebControl-SD.zip
unzip *.zip && for f_ in $(find . | grep '.gz');do gunzip ${f_};done 

Then we'll need to update klipper/klippy/gcode.py with the patch below. Save the patch as ~/klipper/gcode.patch

diff --git a/klippy/gcode.py b/klippy/gcode.py
index b679dc63..10acecce 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -30,6 +30,8 @@ class GCodeParser:
         self.partial_input = ""
         self.pending_commands = []
         self.bytes_read = 0
+        self.respond_callbacks = []
+        self.respond_callbacks = []
         self.input_log = collections.deque([], 50)
         # Command handling
         self.is_printer_ready = False
@@ -301,7 +303,8 @@ class GCodeParser:
             self._process_commands(script.split('\n'), need_ack=False)
     def get_mutex(self):
         return self.mutex
-    # Response handling
+    def register_respond_callback(self, callback):
+        self.respond_callbacks.append(callback)
     def ack(self, msg=None):
         if not self.need_ack or self.is_fileinput:
             return
@@ -318,6 +321,10 @@ class GCodeParser:
             return
         try:
             os.write(self.fd, msg+"\n")
+            for callback in self.respond_callbacks:
+                callback(msg+"\n")
+            for callback in self.respond_callbacks:
+                callback(msg+"\n")
         except os.error:
             logging.exception("Write g-code response")
     def respond_info(self, msg, log=True):

Then run the following command

cd ~/klipper 
git apply gcode.patch

Finally we'll want to restart klipper.

sudo service klipper restart

Last updated