Arksine / moonraker

Web API Server for Klipper
https://moonraker.readthedocs.io
GNU General Public License v3.0
1.05k stars 404 forks source link

A recent update broke my tasmota style config #634

Open sprior opened 1 year ago

sprior commented 1 year ago

What happened

I have the following power config in moonraker.conf: [power Printer Power] type: tasmota address: localhost:8000/PrinterPower

The Tasmota REST API is implemented by a Java webapp hosted by Tomcat on my Voron which actually controls a relay module hooked to a pin on the Raspberry Pi. So the following local URL would power on the printer:

http://localhost:8000/PrinterPower/cm?cmnd=Power1%20on

This was working until the last few weeks when I updated Moonraker, now I see the following in the log:

2023-03-19 20:28:46,704 [power.py:init_state()] - Device Init Error: Printer Power Traceback (most recent call last): File "/home/pi/moonraker/moonraker/components/http_client.py", line 114, in request resp = await asyncio.wait_for(fut, timeout) File "/usr/lib/python3.7/asyncio/tasks.py", line 416, in wait_for return fut.result() File "/home/pi/moonraker-env/lib/python3.7/site-packages/tornado/simple_httpclient.py", line 346, in run source_ip=source_ip, File "/home/pi/moonraker-env/lib/python3.7/site-packages/tornado/tcpclient.py", line 265, in connect addrinfo = await self.resolver.resolve(host, port, af) File "/home/pi/moonraker-env/lib/python3.7/site-packages/tornado/netutil.py", line 434, in resolve host, port, family=family, type=socket.SOCK_STREAM File "/usr/lib/python3.7/asyncio/base_events.py", line 789, in getaddrinfo None, getaddr_func, host, port, family, type, proto, flags) File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/pi/moonraker/moonraker/components/power.py", line 441, in init_state state = await self._send_status_request() File "/home/pi/moonraker/moonraker/components/power.py", line 962, in _send_status_request res = await self._send_tasmota_command("info") File "/home/pi/moonraker/moonraker/components/power.py", line 959, in _send_tasmota_command return await self._send_http_command(url, command) File "/home/pi/moonraker/moonraker/components/power.py", line 474, in _send_http_command f"Error sending '{self.type}' command: {command}") File "/home/pi/moonraker/moonraker/components/http_client.py", line 312, in raise_for_status raise ServerError(msg, code) from self._error moonraker.utils.ServerError: Error sending 'tasmota' command: info

I'm not sure but I think additional validation doesn't like either having the port number or the additional path info in the configuration.

I'd really appreciate fixing that validation or providing an additional option to allow it.

Client

Fluidd

Browser

Firefox

How to reproduce

Add the following config to moonraker.conf:

[power Printer Power] type: tasmota address: localhost:8000/PrinterPower

Try to boot, look for the error in the moonraker.log

Additional information

Note that this was working fine as is for about the last year. It was only recently that it broke. I think that some validation was added for this config item recently that no longer allows a config like this.

Arksine commented 1 year ago

This likely stopped working when the address was escaped to resolve issues with special characters. It was never intended that the address should contain a port or path, and indeed will not work with the aforementioned bugfix. Put differently, your previous configuration took advantage of a bug in the power module and it no longer works because the bug has been fixed.

The tasmota implementation is currently intended to run on real devices which have a predictable url path, always hosted on port 80. I'll have to consider what the best approach would be for supporting an "emulated" tasmota device. FWIW, Moonraker can control GPIOs directly, so it that should be an option if you want to toggle a pin.