diff --git a/udev/README.md b/udev/README.md deleted file mode 100644 index b7955e6..0000000 --- a/udev/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# udev Rules and Commands - -This directory contains the commands and rules I add to udev to make turning the printer on and off go smoothly, including re-connecting (my Docker container runs 24x7, however I turn off the printer when not in use). - -The `okmd-udev.rules` file should be copied to `/etc/udev/rules.d/`, and updated to have the correct paths and device names for your environment. - -The commands (`printer-*`), should also be updated to match your device names, and include your OctoPrint API key. diff --git a/udev/okmd-udev.rules b/udev/okmd-udev.rules deleted file mode 100644 index 827362f..0000000 --- a/udev/okmd-udev.rules +++ /dev/null @@ -1,2 +0,0 @@ -ACTION=="add", KERNEL=="ttyUSB*", SUBSYSTEM=="tty", RUN+="/somewhere/printer-connected" -ACTION=="remove", KERNEL=="ttyUSB*", SUBSYSTEM=="tty", RUN+="/somewhere/printer-disconnected" diff --git a/udev/printer-connected b/udev/printer-connected deleted file mode 100755 index 513f115..0000000 --- a/udev/printer-connected +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -import time -import os - -logf = open('/var/tmp/printer-connected.log', 'a') - -DEVNAME = os.environ['DEVNAME'] - -def log(msg): - logf.write('%s\n' % (msg,)) - -def main(): - log(time.asctime()) - log(DEVNAME) - os.system('chmod a+wr %s' % (DEVNAME,)) - -if __name__ == '__main__': - main() - diff --git a/udev/printer-disconnected b/udev/printer-disconnected deleted file mode 100755 index e5a9e54..0000000 --- a/udev/printer-disconnected +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python - -import time -import os -import requests -import sys - -logf = open('/var/tmp/printer-connected.log', 'a') - -DEVNAME = os.environ['DEVNAME'] - -RESTART_STATES = [ - 'Offline', - 'Cancelling', - 'Operational', - ] - -OCTOPRINT_URL = 'http://localhost:5000/' -API_KEY = 'XXX' - -def log(msg): - logf.write('%s\n' % (msg,)) - -def currentstate(): - headers = {'X-Api-Key': API_KEY} - url = OCTOPRINT_URL + '/api/job' - r = requests.get(url, headers=headers) - return r.json()['state'] - -def main(): - log(time.asctime()) - log("Disconnecting: {}".format(DEVNAME)) - - state = currentstate() - if state not in RESTART_STATES and DEVNAME != '/dev/ttyUSB0': - log("Not restarting. State: {} DEVNAME: {}".format(state, DEVNAME)) - # Don't reset the firmware if not in a known safe state - return - - headers = {'X-Api-Key': API_KEY} - json = { - "command": "FIRMWARE_RESTART", - } - - url = OCTOPRINT_URL + '/api/printer/command' - r = requests.post( - url, - json=json, - headers=headers - ) - - if (r.status_code == 204): - log("Disconnected OK") - sys.exit(0) - else: - log("Error disconnecting: %s" % (r,)) - sys.exit(1) - -if __name__ == '__main__': - main() -