da4id / OctoPrint-MyStromSwitch

4 stars 4 forks source link

Turn relais OFF on Octoprint shutdown not not working #17

Open hobbes68 opened 4 years ago

hobbes68 commented 4 years ago

Hello, I try to use your command Turn relais OFF on Octoprint shutdown but the shutdown system command (sudo shutdown -h now) in octoprint didn't start the countdown in Mystrom Wifiswitch 3.82. But the resart Octoprint command (sudo service octoprint restart) start the countdown (60sec in my case). So the power supply of the raspi is switch off without shutdown! I hope it's clear enough. Did I something wrong? Best regards

da4id commented 4 years ago

Hi Thanks for reporting this bug. I faced the same issue on my Octopi installation yesterday night. Ive testet this feature only on an octoprint installation on my computer. Ive checked the logs of the Octoprint 2019-12-16 22:15:34,819 - octoprint.plugins.automaticshutdown - INFO - Shutting down system with command: sudo shutdown -h now 2019-12-16 22:15:35,318 - octoprint.server - INFO - Shutting down... 2019-12-16 22:15:35,829 - octoprint.events - INFO - Processing shutdown event, this will be our last event 2019-12-16 22:15:36,128 - octoprint.events - INFO - Event loop shut down 2019-12-16 22:15:36,136 - octoprint.plugin - ERROR - Error while calling plugin hardwarepwm Traceback (most recent call last): File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/__init__.py", line 219, in call_plugin result = getattr(plugin, method)(*args, **kwargs) File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_hardwarepwm/__init__.py", line 51, in on_shutdown self.stopPWM(self.IOpin); File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_hardwarepwm/__init__.py", line 32, in stopPWM self.GPIO.write(pin, 0) File "/home/pi/oprint/local/lib/python2.7/site-packages/pigpio.py", line 1429, in write return _u2i(_pigpio_command(self.sl, _PI_CMD_WRITE, gpio, level)) File "/home/pi/oprint/local/lib/python2.7/site-packages/pigpio.py", line 994, in _pigpio_command dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN)) error: unpack requires a string argument of length 16 2019-12-16 22:15:36,137 - octoprint.plugins.mystromswitch - INFO - Turn off Relais on Shutdown Delayed 2019-12-16 22:15:36,147 - octoprint.plugins.mystromswitch - INFO - Error during powerCycle Relais 2019-12-16 22:15:36,158 - octoprint.plugins.mystromswitch - INFO - Error during powerCycle Relais 2019-12-16 22:15:36,170 - octoprint.plugins.mystromswitch - INFO - Error during powerCycle Relais 2019-12-16 22:15:36,171 - octoprint.server - INFO - Goodbye!

It seems that the Powercycle command was issued by the plugin, but the command get lost somewhere.

kirtapatrik commented 4 years ago

Same problem here. OctoPrint 1.3.12 auf OctoPi 0.17.0 on Raspberry Pi 4

da4id commented 4 years ago

It seems that the network connection is shutted down before the Plugin gets the on shutdown event. Therefore it cannot send the command to the Switch. If you shut down your System over the Websurface -> Shutdown System it works. If you use automatic shutdown Plugin it wont work.

I will try to change the shutdown order of the services

da4id commented 4 years ago

The quick fix is to change the following line in the /etc/init.d/octoprint file on your raspberry pi difference The file should then look like whole file

I started a Pull Request that this change is default on Octopi

hobbes68 commented 4 years ago

Hello i spend 3 hours to change this scrips file! Finaly it's working. I'm not used for programing... My notepad++ plugin was not uptodate for connecting my pi, i had to change the permission for the scrip file, install the desktop on my octopi... I learned so much this evening! Thanks a lot and happy Christmas

Le mar. 17 déc. 2019 à 22:22, da4id notifications@github.com a écrit :

The quick fix is to change the following line in the /etc/init.d/octoprint on your raspberry pi difference https://github.com/da4id/OctoPi/commit/33217ff0b1a40e3ed656abb6b8276202e0a1f118 The file should then look like link https://github.com/da4id/OctoPi/blob/devel/src/modules/octopi/filesystem/root/etc/init.d/octoprint

I started a Pull Request that this change is default on Octopi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/da4id/OctoPrint-MyStromSwitch/issues/17?email_source=notifications&email_token=AOCCTEKAG2L4Y5EFREHO77TQZE7K7A5CNFSM4J4APOQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHD74EA#issuecomment-566754832, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOCCTEMIYQRGKOYDRTDQ4JDQZE7K7ANCNFSM4J4APOQA .

da4id commented 4 years ago

Change is now available in the official OctoPi image. At the moment there is no new release available. But you can use Nigthly Builds instead. These are not tested, but have all new features and improvements enabled. When you do this please Backup your SD Card bevore updating. You also need to export and import all Octoprint settings.

If you wont use Nightly Builds you can change the file manually. The easiest way is to log in to your OctoPi over ssh (Google ssh Raspberry Pi, default login user: pi, password: raspberry). Then type sudo nano /etc/init.d/octoprint. Then use Cursor arrows to navigate to the corresponding line and change it. Press CTRL + o followed by Enter and then CTRL + x

I'm closing this Issue now

kirtapatrik commented 4 years ago

Is it possible that this fix has no effect on a Raspberry Pi 4?

With the plugin AutomaticShutdown, the switch is not switched off after the print is finished. When I shutdown my system via the websurface -> "Shutdown System", it does not work either.

When I press the button on the web interface, the switch switches without any problems.

hobbes68 commented 4 years ago

Hello, It doesn’t work for me anymore with the shutdown system… or just « sometimes » it’s works, but usually not. Best regards

Le 6 janv. 2020 à 10:39, Patrik Ulmann notifications@github.com a écrit :

Is it possible that this fix has no effect on a Raspberry Pi 4?

With the plugin AutomaticShutdown, the switch is not switched off after the print is finished. When I shutdown my system via the websurface -> "Shutdown System", it does not work either.

When I press the button on the web interface, the switch switches without any problems.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/da4id/OctoPrint-MyStromSwitch/issues/17?email_source=notifications&email_token=AOCCTEN7JJ4ULLF5XZOLII3Q4L355A5CNFSM4J4APOQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIE5WCY#issuecomment-571071243, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOCCTEMRYMZBLFXOTYVYA23Q4L355ANCNFSM4J4APOQA.

da4id commented 4 years ago

Hi thanks for feedback

I need some more time to find the problem. I improved the logging of the Plugin. the command to turn off the switch fails with this error Message. It seems that the networking dependency is not always working. ERROR - HTTPConnectionPool(host='192.168.1.52', port=80): Max retries exceeded with url: /timer?mode=on&time=60 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x67611d10>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

da4id commented 4 years ago

I have added a new feature in #21 to make it work Use these settings Bildschirmfoto vom 2020-06-28 17-13-44

and dont forget to enable it! Bildschirmfoto vom 2020-06-28 17-14-04