CodingTheUnknown / OctoPrint-Tplinkautoshutdown

A plugin designed to be used within OctoPrint and OctoPi to control TP-Link kasa devices.
https://github.com/CodingTheUnknown/OctoPrint-Tplinkautoshutdown.git
9 stars 7 forks source link

Version 1.0.2 not working with HS103 #46

Closed SteveDallas closed 3 years ago

SteveDallas commented 3 years ago

I had the plugin working until I did two things. I set up a host reservation for the Kasa HS103 in my DHCP server on my router and I updated to v1.0.2. The smart plug answers pings on its address and is controllable by the Kasa app on my smartphone.

However, after following the instructions for adding the device to the TPlinkHandler plugin, it doesn't respond to the Show Configuration button, and is not controllable by the On and Off buttons. I have unplugged the HS103 to make sure that it's IP is updated correctly. I have restarted OctoPrint multiple times (and rebooted the Pi). I have removed and reinstalled the plugin from scratch. Nothing seems to be working. I do get this message on startup:

2021-03-11 08:47:30,334 - octoprint.plugins.TpLinkAutoShutdown - INFO - Plugin TpLinkHandler has started 2021-03-11 08:47:30,335 - octoprint.plugins.TpLinkAutoShutdown - INFO - +++++++++++ Aborted on Startup connection +++++++++++

I have attached my full octoprint.log.

octoprint (8).log

CodingTheUnknown commented 3 years ago

Hi with this being a major update, you needed to re-configure your settings. Did you go back into settings > TpLinkHandler and re-follow the instructions. If not i believe this is your issue.

SteveDallas commented 3 years ago

Yes. I followed the instructions on setting the IP address, restarting OctoPrint, then going back in to show the configuration.

As part of my troubleshooting, I removed the plug-in and reinstalled it, then followed the setup instructions again.

CodingTheUnknown commented 3 years ago

Ok let me know how that goes

CodingTheUnknown commented 3 years ago

Looking at the current log it looks as if the configs haven't been saved into the config file. Have a look at the config.yaml file within .octoprint. In there you should see plugins: then under that TpLinkAutoShutdown. This will list all the settings you have set/changed from the defaults

SteveDallas commented 3 years ago

Relevant section of /home/pi/.octoprint/config.yaml:

plugins: TpLinkAutoShutdown: command: update type: '' url: 192.168.2.190

Changing the type from Smart Plug to Smart Strip and saving doesn't seem to write anything to config.yaml.

CodingTheUnknown commented 3 years ago

Ok leave this with me and I’ll look at replicating the problem. Will be tomorrow though

SteveDallas commented 3 years ago

Thanks. No rush.

CodingTheUnknown commented 3 years ago

Hi I have tried to replicate this issue and have not been successful in finding myself in the same position as yourself.

I have noticed similar posts about problems with the way people sometimes setup VLANs though for their network and then don't allow the octoprint server to access the VLAN and as a result, no connection can be made.

The other thing i did notice though within the log is that you didn't ever click the show configuration button within settings. Although not necessary, you would see if it is accessing the plug as the details of the plug would then be populated into a box that appears.

Let me know how you get on.

SteveDallas commented 3 years ago

Looking through init.py, the message "+++++++++++ Aborted on Startup connection +++++++++++", which appears at startup in my octoprint.log, is caused by not having a 'type' parameter in config.yaml, or having a type that doesn't equal 'smartPlug' or 'smartStrip'.

This is my problem, as can be seen in the config.yaml fragment I posted above. I clicked "Uninstall & Clean Up Data", then verified that the TpLinkAutoShutdown section of /home/pi/.octoprint/config.yaml was removed. I then restarted OctoPrint, reinstalled the plugin, and restarted OctoPrint again. On this restart, the plugin reports "+++++++++++ Aborted on Startup connection +++++++++++" in the log because there are no settings yet. So far, this is expected.

I then set the IP address of my HS103 and click "Save". This is the relevant section of /home/pi/.octoprint/config.yaml: TpLinkAutoShutdown: url: 192.168.2.190 Note that there is not a type: setting.

I then restart OctoPrint to force the plugin to re-read the settings. Since no type value was saved, I get the "Aborted" message again in the log. If I open the settings, click "show configuration!", click "Save", then view config.yaml, it now contains: TpLinkAutoShutdown: command: update type: '' url: 192.168.2.190

I suppose something has gotten corrupted, but I can't figure out what.

CodingTheUnknown commented 3 years ago

Never seen that before. Very unusual. The name should have been TpLinkAutoShutdown. If it not has the url, you just need to set the type within the settings and then it will connect. However if you want to set it manually, it will either be smartPlug or smartStrip. Without the type of plug, the plugin aborts the startup as this is where it prepares itself for the type of plug being used. Hence having to restart the server upon making changes to the plug type and the IP address.

CodingTheUnknown commented 3 years ago

I believe there was a bug in the code. Uninstall & cleanup and then reinstall the plugin now version 1.0.3 and this should work

SteveDallas commented 3 years ago

Now, the 'type' field sticks in the preferences, and the octoprint log seems to indicate that it's communicating with my HS103, but the Show Configuration button doesn't do anything after I follow the installation procedure (remove and clean up, restart, install, restart, set IP address in preferences, restart, press Show Configuration in preferences). Nothing displays. octoprint.log attached, showing that the plugin knows the MAC address and other information about my HS103. octoprint (13).log

The Turn on and Turn off buttons are now working, though.

CodingTheUnknown commented 3 years ago

Ok I'll have a little hunt around. If the buttons work, then all the other features will work.