Remove udev
This commit is contained in:
parent
89e6e9d893
commit
4253f81f8c
|
@ -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.
|
|
|
@ -1,2 +0,0 @@
|
||||||
ACTION=="add", KERNEL=="ttyUSB*", SUBSYSTEM=="tty", RUN+="/somewhere/printer-connected"
|
|
||||||
ACTION=="remove", KERNEL=="ttyUSB*", SUBSYSTEM=="tty", RUN+="/somewhere/printer-disconnected"
|
|
|
@ -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()
|
|
||||||
|
|
|
@ -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()
|
|
||||||
|
|
Loading…
Reference in New Issue