Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60ba8ff1d5 | ||
|
|
45557b8260 | ||
|
|
f229c3ec2c | ||
|
|
0e22a0cfe8 | ||
|
|
f2135d7483 | ||
|
|
baf97f8ea4 | ||
|
|
29b89fb87d | ||
|
|
ec7936ee97 | ||
|
|
ceaa4911bb | ||
|
|
f9dcda7ba9 | ||
|
|
0fcae5b6e4 | ||
|
|
dd81beab47 |
No files matched your search
@@ -47,6 +47,13 @@ config_path:
|
||||
# files to this directory. Note that this may not be the system root
|
||||
# (ie: "/") and moonraker must have read and write access permissions
|
||||
# for this directory.
|
||||
temperature_store_size: 1200
|
||||
# The maximum number of temperature values to store for each sensor. Note
|
||||
# that this value also applies to the "target", "power", and "fan_speed"
|
||||
# if the sensor reports them. The default is 1200, which is enough to
|
||||
# store approximately 20 minutes of data at one value per second.
|
||||
gcode_store_size: 1000
|
||||
# The maximum number "gcode lines" to store. The default is 1000.
|
||||
```
|
||||
## authorization
|
||||
|
||||
@@ -192,6 +199,17 @@ output_id:
|
||||
# If your single-relay Tasmota device switches on/off successfully,
|
||||
# but fails to report its state, ensure that 'SetOption26' is set in
|
||||
# Tasmota.
|
||||
address:
|
||||
user:
|
||||
password:
|
||||
output_id:
|
||||
# The above options are used for "shelly" devices. The
|
||||
# address should be a valid ip or hostname for the Shelly device.
|
||||
# Provide a user and password if configured in Shelly (default is empty).
|
||||
# If password is set but user is empty the default user "admin" will be used
|
||||
# Provided an output_id (relay id) if the Shelly device supports
|
||||
# more than one (default is 0).
|
||||
|
||||
|
||||
```
|
||||
Below are some potential examples:
|
||||
@@ -222,6 +240,12 @@ address: 192.168.1.123
|
||||
type: tasmota
|
||||
address: 192.168.1.124
|
||||
password: password1
|
||||
|
||||
[power shelly_plug]
|
||||
type: shelly
|
||||
address: 192.168.1.125
|
||||
user: user2
|
||||
password: password2
|
||||
```
|
||||
|
||||
It is possible to toggle device power from the Klippy host, this can be done
|
||||
|
||||
@@ -15,10 +15,12 @@ class Sentinel:
|
||||
|
||||
class ConfigHelper:
|
||||
error = ConfigError
|
||||
def __init__(self, server, config, section):
|
||||
def __init__(self, server, config, section, orig_sects, parsed={}):
|
||||
self.server = server
|
||||
self.config = config
|
||||
self.section = section
|
||||
self.orig_sections = orig_sects
|
||||
self.parsed = parsed
|
||||
self.sections = config.sections
|
||||
self.has_section = config.has_section
|
||||
|
||||
@@ -43,7 +45,8 @@ class ConfigHelper:
|
||||
def getsection(self, section):
|
||||
if section not in self.config:
|
||||
raise ConfigError(f"No section [{section}] in config")
|
||||
return ConfigHelper(self.server, self.config, section)
|
||||
return ConfigHelper(self.server, self.config, section,
|
||||
self.orig_sections, self.parsed)
|
||||
|
||||
def _get_option(self, func, option, default):
|
||||
try:
|
||||
@@ -55,6 +58,9 @@ class ConfigHelper:
|
||||
if val == Sentinel:
|
||||
raise ConfigError(
|
||||
f"No option found ({option}) in section [{self.section}]")
|
||||
if self.section in self.orig_sections:
|
||||
# Only track sections included in the original config
|
||||
self.parsed.setdefault(self.section, {})[option] = val
|
||||
return val
|
||||
|
||||
def get(self, option, default=Sentinel):
|
||||
@@ -86,6 +92,24 @@ class ConfigHelper:
|
||||
def write_config(self, file_obj):
|
||||
self.config.write(file_obj)
|
||||
|
||||
def get_parsed_config(self):
|
||||
return dict(self.parsed)
|
||||
|
||||
def validate_config(self):
|
||||
for sect in self.orig_sections:
|
||||
if sect not in self.parsed:
|
||||
logging.warn(
|
||||
f"Invalid config section [{sect}] detected. In "
|
||||
"the future this will result in a startup error")
|
||||
continue
|
||||
parsed_opts = self.parsed[sect]
|
||||
for opt, val in self.config.items(sect):
|
||||
if opt not in parsed_opts:
|
||||
logging.warn(
|
||||
f"Invalid option '{opt}' detected in section "
|
||||
f"[{sect}]. In the future this will result in a "
|
||||
"startup error.")
|
||||
|
||||
def get_configuration(server, system_args):
|
||||
cfg_file_path = os.path.normpath(os.path.expanduser(
|
||||
system_args.configfile))
|
||||
@@ -102,11 +126,17 @@ def get_configuration(server, system_args):
|
||||
except KeyError:
|
||||
raise ConfigError("No section [server] in config")
|
||||
|
||||
if server_cfg.get('enable_debug_logging', True):
|
||||
orig_sections = config.sections()
|
||||
try:
|
||||
orig_sections.remove("DEFAULT")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if server_cfg.getboolean('enable_debug_logging', True):
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
config['system_args'] = {
|
||||
'configfile': system_args.configfile,
|
||||
'logfile': system_args.logfile,
|
||||
'software_version': system_args.software_version}
|
||||
return ConfigHelper(server, config, 'server')
|
||||
return ConfigHelper(server, config, 'server', orig_sections)
|
||||
@@ -38,7 +38,7 @@ class Server:
|
||||
error = ServerError
|
||||
def __init__(self, args, file_logger):
|
||||
self.file_logger = file_logger
|
||||
config = confighelper.get_configuration(self, args)
|
||||
self.config = config = confighelper.get_configuration(self, args)
|
||||
# log config file
|
||||
strio = io.StringIO()
|
||||
config.write_config(strio)
|
||||
@@ -76,6 +76,8 @@ class Server:
|
||||
|
||||
self.register_endpoint(
|
||||
"/server/info", ['GET'], self._handle_info_request)
|
||||
self.register_endpoint(
|
||||
"/server/config", ['GET'], self._handle_config_request)
|
||||
self.register_endpoint(
|
||||
"/server/restart", ['POST'], self._handle_server_restart)
|
||||
|
||||
@@ -96,6 +98,7 @@ class Server:
|
||||
self.plugins = {}
|
||||
self.klippy_apis = self.load_plugin(config, 'klippy_apis')
|
||||
self._load_plugins(config)
|
||||
config.validate_config()
|
||||
|
||||
def start(self):
|
||||
hostname, hostport = self.get_host_info()
|
||||
@@ -479,6 +482,11 @@ class Server:
|
||||
'failed_plugins': self.failed_plugins,
|
||||
'registered_directories': reg_dirs}
|
||||
|
||||
async def _handle_config_request(self, web_request):
|
||||
return {
|
||||
'config': self.config.get_parsed_config()
|
||||
}
|
||||
|
||||
class KlippyConnection:
|
||||
def __init__(self, on_recd, on_close):
|
||||
self.ioloop = IOLoop.current()
|
||||
|
||||
@@ -9,17 +9,16 @@ from collections import deque
|
||||
from tornado.ioloop import IOLoop, PeriodicCallback
|
||||
|
||||
TEMPERATURE_UPDATE_MS = 1000
|
||||
TEMPERATURE_STORE_SIZE = 20 * 60
|
||||
|
||||
MAX_GCODE_LINES = 1000
|
||||
|
||||
class DataStore:
|
||||
def __init__(self, config):
|
||||
self.server = config.get_server()
|
||||
self.temp_store_size = config.getint('temperature_store_size', 1200)
|
||||
self.gcode_store_size = config.getint('gcode_store_size', 1000)
|
||||
|
||||
# Temperature Store Tracking
|
||||
self.last_temps = {}
|
||||
self.gcode_queue = deque(maxlen=MAX_GCODE_LINES)
|
||||
self.gcode_queue = deque(maxlen=self.gcode_store_size)
|
||||
self.temperature_store = {}
|
||||
self.temp_update_cb = PeriodicCallback(
|
||||
self._update_temperature_store, TEMPERATURE_UPDATE_MS)
|
||||
@@ -66,11 +65,11 @@ class DataStore:
|
||||
new_store[sensor] = self.temperature_store[sensor]
|
||||
else:
|
||||
new_store[sensor] = {
|
||||
'temperatures': deque(maxlen=TEMPERATURE_STORE_SIZE)}
|
||||
'temperatures': deque(maxlen=self.temp_store_size)}
|
||||
for item in ["target", "power", "speed"]:
|
||||
if item in fields:
|
||||
new_store[sensor][f"{item}s"] = deque(
|
||||
maxlen=TEMPERATURE_STORE_SIZE)
|
||||
maxlen=self.temp_store_size)
|
||||
if sensor not in self.last_temps:
|
||||
self.last_temps[sensor] = (0., 0., 0., 0.)
|
||||
self.temperature_store = new_store
|
||||
|
||||
@@ -34,6 +34,8 @@ class PrinterPower:
|
||||
dev = TPLinkSmartPlug(cfg)
|
||||
elif dev_type == "tasmota":
|
||||
dev = Tasmota(cfg)
|
||||
elif dev_type == "shelly":
|
||||
dev = Shelly(cfg)
|
||||
else:
|
||||
raise config.error(f"Unsupported Device Type: {dev_type}")
|
||||
self.devices[dev.get_name()] = dev
|
||||
@@ -455,6 +457,70 @@ class Tasmota(PowerDevice):
|
||||
raise self.server.error(msg) from None
|
||||
self.state = state
|
||||
|
||||
|
||||
class Shelly(PowerDevice):
|
||||
def __init__(self, config):
|
||||
super().__init__(config)
|
||||
self.server = config.get_server()
|
||||
self.addr = config.get("address")
|
||||
self.output_id = config.getint("output_id", 0)
|
||||
self.user = config.get("user", "admin")
|
||||
self.password = config.get("password", "")
|
||||
|
||||
async def _send_shelly_command(self, command):
|
||||
if command in ["on", "off"]:
|
||||
out_cmd = f"relay/{self.output_id}?turn={command}"
|
||||
elif command == "info":
|
||||
out_cmd = f"relay/{self.output_id}"
|
||||
else:
|
||||
raise self.server.error(f"Invalid shelly command: {command}")
|
||||
if self.password != "":
|
||||
out_pwd = f"{self.user}:{self.password}@"
|
||||
else:
|
||||
out_pwd = f""
|
||||
url = f"http://{out_pwd}{self.addr}/{out_cmd}"
|
||||
data = ""
|
||||
http_client = AsyncHTTPClient()
|
||||
try:
|
||||
response = await http_client.fetch(url)
|
||||
data = json_decode(response.body)
|
||||
except Exception:
|
||||
msg = f"Error sending shelly command: {command}"
|
||||
logging.exception(msg)
|
||||
raise self.server.error(msg)
|
||||
return data
|
||||
|
||||
async def initialize(self):
|
||||
await self.refresh_status()
|
||||
|
||||
def get_device_info(self):
|
||||
return {
|
||||
**super().get_device_info(),
|
||||
'type': "shelly"
|
||||
}
|
||||
|
||||
async def refresh_status(self):
|
||||
try:
|
||||
res = await self._send_shelly_command("info")
|
||||
state = res[f"ison"]
|
||||
except Exception:
|
||||
self.state = "error"
|
||||
msg = f"Error Refeshing Device Status: {self.name}"
|
||||
logging.exception(msg)
|
||||
raise self.server.error(msg) from None
|
||||
self.state = "on" if state else "off"
|
||||
|
||||
async def set_power(self, state):
|
||||
try:
|
||||
res = await self._send_shelly_command(state)
|
||||
state = res[f"ison"]
|
||||
except Exception:
|
||||
self.state = "error"
|
||||
msg = f"Error Setting Device Status: {self.name} to {state}"
|
||||
logging.exception(msg)
|
||||
raise self.server.error(msg) from None
|
||||
self.state = "on" if state else "off"
|
||||
|
||||
# The power plugin has multiple configuration sections
|
||||
def load_plugin_multi(config):
|
||||
return PrinterPower(config)
|
||||
@@ -276,6 +276,7 @@ class WebsocketManager:
|
||||
ws.write_message(msg)
|
||||
except WebSocketClosedError:
|
||||
self.websockets.pop(ws.uid, None)
|
||||
self.server.remove_subscription(ws)
|
||||
logging.info(f"Websocket Removed: {ws.uid}")
|
||||
except Exception:
|
||||
logging.exception(
|
||||
@@ -294,6 +295,7 @@ class WebSocket(WebSocketHandler):
|
||||
self.wsm = app.get_websocket_manager()
|
||||
self.rpc = self.wsm.rpc
|
||||
self.uid = id(self)
|
||||
self.is_closed = False
|
||||
|
||||
async def open(self):
|
||||
await self.wsm.add_websocket(self)
|
||||
@@ -311,7 +313,7 @@ class WebSocket(WebSocketHandler):
|
||||
logging.exception("Websocket Command Error")
|
||||
|
||||
def send_status(self, status):
|
||||
if not status:
|
||||
if not status or self.is_closed:
|
||||
return
|
||||
try:
|
||||
self.write_message({
|
||||
@@ -319,6 +321,7 @@ class WebSocket(WebSocketHandler):
|
||||
'method': "notify_status_update",
|
||||
'params': [status]})
|
||||
except WebSocketClosedError:
|
||||
self.is_closed = True
|
||||
logging.info(
|
||||
f"Websocket Closed During Status Update: {self.uid}")
|
||||
except Exception:
|
||||
|
||||
@@ -271,7 +271,7 @@ class SuperSlicer(PrusaSlicer):
|
||||
}
|
||||
return None
|
||||
|
||||
class Cura(BaseSlicer):
|
||||
class Cura(PrusaSlicer):
|
||||
def check_identity(self, data):
|
||||
match = re.search(r"Cura_SteamEngine\s(.*)", data)
|
||||
if match:
|
||||
@@ -311,6 +311,11 @@ class Cura(BaseSlicer):
|
||||
r"M190 S(\d+\.?\d*)", self.header_data)
|
||||
|
||||
def parse_thumbnails(self):
|
||||
# Attempt to parse thumbnails from file metadata
|
||||
thumbs = super().parse_thumbnails()
|
||||
if thumbs is not None:
|
||||
return thumbs
|
||||
# Check for thumbnails extracted from the ufp
|
||||
thumbName = os.path.splitext(
|
||||
os.path.basename(self.path))[0] + ".png"
|
||||
thumbPath = os.path.join(
|
||||
|
||||
@@ -4,28 +4,25 @@
|
||||
stop_service() {
|
||||
# Stop Moonraker Service
|
||||
echo "#### Stopping Moonraker Service.."
|
||||
sudo service moonraker stop
|
||||
sudo systemctl stop moonraker
|
||||
}
|
||||
|
||||
remove_service() {
|
||||
# Remove Moonraker from Startup
|
||||
echo
|
||||
echo "#### Removing Moonraker from Startup.."
|
||||
sudo update-rc.d -f moonraker remove
|
||||
|
||||
# Remove Moonraker from Services
|
||||
# Remove Moonraker LSB/systemd service
|
||||
echo
|
||||
echo "#### Removing Moonraker Service.."
|
||||
sudo rm -f /etc/init.d/moonraker /etc/default/moonraker
|
||||
|
||||
}
|
||||
|
||||
remove_sudo_fix() {
|
||||
echo
|
||||
echo "#### Removing sudo_fix"
|
||||
sudo gpasswd -d $USER mnrkrsudo
|
||||
sudo delgroup --only-if-empty mnrkrsudo
|
||||
sudo rm -f /etc/sudoers.d/020-sudo-for-moonraker
|
||||
if [ -f "/etc/init.d/moonraker" ]; then
|
||||
# legacy installation, remove the LSB service
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -f /etc/init.d/moonraker
|
||||
sudo rm -f /etc/default/moonraker
|
||||
else
|
||||
# Remove systemd installation
|
||||
sudo systemctl disable moonraker
|
||||
sudo rm -f /etc/systemd/system/moonraker.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
fi
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
@@ -55,6 +52,9 @@ remove_files() {
|
||||
echo
|
||||
echo "The following command is typically used to remove source files:"
|
||||
echo " rm -rf ~/moonraker"
|
||||
echo
|
||||
echo "You may also wish to uninstall nginx:"
|
||||
echo " sudo apt-get remove nginx"
|
||||
}
|
||||
|
||||
verify_ready()
|
||||
@@ -69,4 +69,3 @@ verify_ready
|
||||
stop_service
|
||||
remove_service
|
||||
remove_files
|
||||
remove_sudo_fix
|
||||
Reference in new issue
Block a user