Support for Smart Plug commands like TP-LINK (either directly or via HTTP POST request)
Hi,
I have my printer setup hooked up to a TP-LINK smartplug which i use to power of the printer after successfull prints. As the current repetier-server does not support sending event based commands (or HTTP requests) i have it working but its a bit fussy and ideally i would love to have a more direct solution out of the repetier-server if possible.
Basically atm it works like this: If a print is completed i get a notification on the repetier infoermer app on android. I then use Automagic app to trigger a HTTP POST request to my TP-LINK smartplug to switch it off.
Ideally i would love to have such a feature (either TP-LINK support or HTTP requests) from within Repetier-Server to issue this command directly without having to resort to my above method which is prone to possible issues (if the phone is off etc).
Octoprint for instance has a dedicated plugin for the TP-LINK smartplug (https://github.com/jneilliii/OctoPrint-TPLinkSmartplug) which has the option to issue the on/off command triggered by GCODE M80 ip address / M81 ip address.
Either solution would be fine for me if possible.
Cheers
I have my printer setup hooked up to a TP-LINK smartplug which i use to power of the printer after successfull prints. As the current repetier-server does not support sending event based commands (or HTTP requests) i have it working but its a bit fussy and ideally i would love to have a more direct solution out of the repetier-server if possible.
Basically atm it works like this: If a print is completed i get a notification on the repetier infoermer app on android. I then use Automagic app to trigger a HTTP POST request to my TP-LINK smartplug to switch it off.
Ideally i would love to have such a feature (either TP-LINK support or HTTP requests) from within Repetier-Server to issue this command directly without having to resort to my above method which is prone to possible issues (if the phone is off etc).
Octoprint for instance has a dedicated plugin for the TP-LINK smartplug (https://github.com/jneilliii/OctoPrint-TPLinkSmartplug) which has the option to issue the on/off command triggered by GCODE M80 ip address / M81 ip address.
Either solution would be fine for me if possible.
Cheers
Comments
None th eless, it is not impossible. That is what the extcommands.xml file is for, please read manual for details. This allows you to add menu entries in printer menu to execute on your pc. It also allows starting a script with @execute server command. So you can even add it in your end event script. Only thing you need to consider is that printer might not be finished when this command gets executed. Typical solution is to add 30 M400 before the @execute line then so printer is finished with everything before that line. The called script should none the less add a 5s pause before turning off power so server can cleanly finish job before printer disconnects.
I also though about the extcommands.xml solution but honestly the documentation on how exactly that works is a bit sparse for me. I am not a linux or python guru so writing a script that creates json or http post commands from scratch is a bit beyond my knowledg. I usually reverse engineer such things if they have been developed for similar purposes and make my own adjustments but i don't know how to write something like this from scratch.
#!/bin/bash
sleep 5
curl .....
thats it. Just needs to check curl syntax. Extcommands is just calling the script file then. Only make sure the user repetierserver is allowed to execute it.
I have managed to get a script (hs100.sh) that works if i run it manually from ssh. I have added the following command to extcommands but it does not trigger the script no matter if i use it with @execute TPLINKOFF in the event based gcode tab or if i try to run it directly from the menu. What am i missing?
Thanks again for your support and tips!
But in essence with setting a few parameters with that script you can tell your switch to turn on or off. You then build it into repetier server either as a switch or to be triggered with an @execute command using the event dependant g-code settings.
So what you need to do is following:
1. Download the script ( i put it up on dropbox here: https://www.dropbox.com/s/00nt6lsma7mbf73/hs100B.sh?dl=0 ). Check the script as it has some instructions in it on how to use it. Basically you run it with passing 3 parameters and then it does its thing.
2. Copy the script onto your RPI or whatever you are running your repetier server on into a folder.
3. Open and edit your extcommands.xml file on your repetier server.
4. Add following line at the very end just before the </config>: <execute name="TPLINKOFF" allowParams="true">/pathtoyourscript/hs100B.sh ipofyourTPLinkswitch 9999 off</execute>
You can name your command whatever you want. I named mine TPLINKOFF as seen above.
5. In the repetier server webgui go to Printer Settings->G-Codes->Event Dependent and in the Run after job section add: @execute TPLINKOFF
Now whenever repetier server has finished your print it will trigger this script as entered with the parameters in the extcommands.xml file. So in this case it will tell the switch to turn itself off.
Now since i usually also make timelapses of my prints and repetier server does some compiling still even after the print is finished i personally also added a timer into the script to wait for 180 seconds after being activated before it turns off the switch. This gives repetier enough time to finish up the timelapse. If you want to do a similar delay then you need to edit the script. Open it up in notepad++ and search for the line: cmd_switch_off(){
I added command sleep 180 (this tells the script to wait for 180 seconds at this point before proceeding with the next command which is the actual command it sends to the TP LINK switch to turn itself off) which takes care of the delay.
And thats it.
Can you confirm that the steps are all correctly executed?
1-Download script - ok
2-Copy the script onto my RPI. The folder can be "/home/pi/"?
3, 4 an 5- Does the attached images seems correct?
Thanks!
But like that? anything incorrect because it didn't work
Many thanks for your help
TP-Link and this script also let report the actual Watt consumption .
Any one does have an idea to set this report as an status symbol in the top nav bar of the printer? That this work I tested with Node-Red.
The emergency stop will not show it. There is no way at the moment to add anything there. Maybe we allow in future to have a montor script that returns values in special format to be shown on a page. Then we cadd anything users want to see in one place.
Than you geht the value.
the ip is 100% right. but why 9999 ? is this right or must i change it ? THX
Ich schreib es mal schnell auf Deutsch.
Ich wollte einfach einen Button für den TP-Link einsetzen der mir die Befehle An/Aus gibt und im Symbol selber den aktuellen Watt Verbrauch einblendet wie die Temperaturanzeigen auch.