jneilliii / OctoPrint-PrintScheduler

MIT License
10 stars 2 forks source link

Job doesn't start if the printer is off. #12

Closed Gleb1982 closed 3 years ago

Gleb1982 commented 3 years ago

Hi, I using a PSU plugin and am turning printer off when it's idle for 15 minutes. PSU is set to trigger the printer by a system command "gpio write 2 0" and to automatically connect after power on command with a 10 sec delay (for the USB port to appear). Also PSU is listening for M81 and M80 Gcode commands.

PrintScheduler doesn't start the print when the printer is off, I tried to set system command "gpio write 2 0" before print, also tried Gcode M80. Nothing helped.

For example when I start printing from Cura, the printer turns on automatically.

Would be great to have an integration with PSU in this plugin, this should not be hard to do via PSU API.

thanks!

jneilliii commented 3 years ago

I think it should work with PSU Control. Did you see the wiki examples that in theory are functional. I know the Tasmota one is.

https://github.com/jneilliii/OctoPrint-PrintScheduler/wiki/Helpful-System-Commands

Gleb1982 commented 3 years ago

I trued running command from SSH, it didn't change state of PSU. here is what I got on the screen. FYI Am using OrangePi Zero 2

root@Climber7:~# /home/octoprint/python_venvs/octoprint1/bin/octoprint plugins psucontrol:on
Initializing settings & plugin subsystem...
Error loading plugin smartfilamentsensor
Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 1264, in _import_plugin
    module = _load_module(module_name, spec)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 69, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 238, in load_module
    return load_package(name, filename)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 212, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_smart_filament_sensor/__init__.py", line 5, in <module>
    import RPi.GPIO as GPIO
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Initializing GcodePositionProcessor V1.0.1 - Copyright (C) 2019  Brad Hochgesang...Python 3+ Detected...complete
2021-09-02 00:16:26,551 - octolapse.__init__ - INFO - Release mode detected.
Error loading plugin OctoBuddy
Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 1264, in _import_plugin
    module = _load_module(module_name, spec)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 69, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 238, in load_module
    return load_package(name, filename)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 212, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_OctoBuddy/__init__.py", line 5, in <module>
    import RPi.GPIO as GPIO
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Error loading plugin filamentsensorsimplified
Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 1264, in _import_plugin
    module = _load_module(module_name, spec)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/plugin/core.py", line 69, in _load_module
    return imp.load_module(name, f, filename, details)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 238, in load_module
    return load_package(name, filename)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/vendor/imp.py", line 212, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_filamentsensorsimplified/__init__.py", line 8, in <module>
    import RPi.GPIO as GPIO
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connection.py", line 170, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
    chunked=chunked,
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.7/http/client.py", line 1260, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1306, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1255, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output
    self.send(msg)
  File "/usr/lib/python3.7/http/client.py", line 970, in send
    self.connect()
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connection.py", line 200, in connect
    conn = self._new_conn()
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connection.py", line 182, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f96c387b8>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /api/plugin/psucontrol?command=turnPSUOn (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f96c387b8>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/octoprint/python_venvs/octoprint1/bin/octoprint", line 8, in <module>
    sys.exit(main())
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/__init__.py", line 948, in main
    octo(args=args, prog_name="octoprint", auto_envvar_prefix="OCTOPRINT")
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_psucontrol/cli.py", line 41, in turnPSUOn_command
    r = _api_command('turnPSUOn', apikey, host, port, httpuser, httppass, https, prefix)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_psucontrol/cli.py", line 28, in _api_command
    r = client.post_command("plugin/psucontrol", command)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_client/__init__.py", line 278, in post_command
    return self.post_json(path, data, params=data, timeout=timeout)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_client/__init__.py", line 272, in post_json
    return self.post(path, data, encoding="json", params=params, timeout=timeout)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_client/__init__.py", line 268, in post
    "POST", path, data=data, encoding=encoding, params=params, timeout=timeout
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint_client/__init__.py", line 260, in request
    response = s.send(request, timeout=timeout)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /api/plugin/psucontrol?command=turnPSUOn (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f96c387b8>: Failed to establish a new connection: [Errno 111] Connection refused'))
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 2039, in shutdown
    h.close()
  File "/home/octoprint/python_venvs/octoprint1/lib/python3.7/site-packages/octoprint/logging/handlers.py", line 31, in close
    self._executor.shutdown(wait=True)
AttributeError: 'OctolapseConsoleHandler' object has no attribute '_executor'
root@Climber7:~#
jneilliii commented 3 years ago

That would be an issue with PSUControl. With that plugin it should work fine on orange pi if I'm not mistaken, but you don't use the Rpi.GPIO module add-on, just use the built in periphery implementation. Once you get that plugin working, then this should work as a system command before. You might need to add users to the dialout rules, etc. I just don't have much experience with GPIO stuff to assist you further. Possibly look into that plugin's repo for assistance or possibly ask in OctoPrint's Discord under the support-plugins channel for someone that may have your specific setup.

au-mikey commented 3 years ago

I'm having a similar issue where Print Scheduler is not starting jobs when the printer is off. I have commented out lines 36 to 38 to get it to power on the printer and added "/home/pi/oprint/bin/octoprint plugins psucontrol:on && sleep 10" to the System Command Before Each Print section. Seems to have fixed the issue as the lines 36 to 38 pretty much say "do nothing if the printer is off".

au-mikey commented 3 years ago

I also moved the line which runs the system commands to the beginning of the next loop so that the printer can power on before the file is loaded to print

jneilliii commented 3 years ago

I see now. A PR would have been nice...

jneilliii commented 3 years ago

I just pushed the above commit and it will be available as 0.0.4rc1 shortly. Moved the exit logic into the for loop, after the system command being run. This way, at most you would have one repeated timer miss if your command didn't include a sleep and the print job would be picked up on the next cycle.