Idea for a new plugin - hardware switch on gpio to command

Btw, sorry for the formatting. The forum reply doesn't lend itself very well to code.

--- Short formatting hint: mark the complete text to format and click </> in the icon bar to format --- :wink:

1 Like

I can't get it to compile:(

int httpCode = http.POST("{"command":"turnPSUOn"}"); //Send command to printer

error: expected ')' before 'command'

Have just changed that line to

http.POST("{\"command\":\"turnPSUOn\"}"); //Send command to printer

flashed it to the esp...and it reset ...and I just heard my printer fire up behind me

You are a star,legend and genius!
I owe you a beer

Regards
Rob

Edited a few times because I had a bit of a morris dance trying to get the code to display as code - and I guess the escapes were there in your original post, but the formatting killed them :smiley:

Thanks Rob! Legendary persistence, if anything. lol Yes, that's it. I think pasting into the forum removed the escape characters. Strange. I guess we need to escape the escape characters. lol Glad you figured it out. Let's go grab a beer!

Thanks. Good to know! Let me edit my post.

Funny how I just cut the code and pasted it between the tags and the backslashes just reappeared. Thanks for the tip.

Have just wired in a couple of switches and pulldown resistors, I now have a "quick power on switch" for the 2 octoprinted units via the one ESP8266 (although I only physically have one complete printerat the moment...hoping my corexy project happens soon enough)

Your code was laid out so well that it was completely drama free to add a second octoprint server, so thanks once again

I still need to design a nice case to house the esp and switches...but now thinking I may add some status leds and get it to poll the printer for other stuff ....maybe, I do have some ssd displayes in the arduino kitbox that will otherwise just gather dust

Thanks once again, I am blown away that it all works

Regards
Rob

2 Likes

I have noticed it is using 100% CPU according to 'top' - should this be a concern?

Should be solved if you or @TerryB add a small pause into the loop "sleep 0.05"

Christian

Thanks. I'll try that. How much CPU utilization do you think this will save?

100% :slight_smile:

Without sleep:

With Sleep:

"waiting for edge" is also a good solution to save cpu power.

Christian

2 Likes

Shows how little I know about python. lol Thanks for the tips!

That's awesome Rob! I can already imagine what it'll look like from your description. Post some pics! The LED indicators or a screen is another good idea putting getPSUState to good use.

Oh... it is life changing for me!
Does exactly what I want it to, and expandable to as many inputs as my printer allowance will stretch
(possibly even trivial to have a keypad matrix should I turn my play room into a print farm...LOL)

Video of it in action...(Spoiler alert...Not that exciting, finger appears stage left, pushes button, printer turns on)
Working like a charm

Regards
Rob

1 Like

That's freaking awesome! Are those keyboard switches? Are you powering an ESP8266 setup in there through that USB cable or are the switches hardwired to the RPi through a USB cable?

Switches came with an arduino kit I bought ages ago, simple momentary jobbies
I think they came with snap on colourful button caps which should be in the tin I stashed them in, will see how much room the next printer consumes to decide if this is going to be a final design or if it needs to evolve to fit in

Yes purely using the USB (from one of the PI's) to supply power to the ESP, - I /could/ use a battery and have it truly wireless, but its much 'safer' tethered to the printer so I don't misplace it in the chaotic enviroment I call home

Screen showing stats and wireless charger receptacle by the printers??
It's working great for now, so could well stay as it is :stuck_out_tongue:

Regards
Rob

1 Like

Funny you should mention the screen. I just got some 0.91 inch I2C screens and was wondering if it's possible to get them to work off of the ESP8266, limited as it is.

Hello, both Robocog and TerryB. I'm really new to scriping things, If I want to follow this project. I have to buy ESP8266 and create a button that will run the script above and I have to change "turnPSUOn" to the command i wanted is that correct?

I want to turn on off printer using the button as well.

Yes, it works great!
With the PSU control plugin the printer automatically turns off (if the machine has cooled down and no activity for a certain time)
In theory yes you could add another switch to turn the printer off...but you would need to add the poweroff command ..if you cannot wait for the timeout on the plugin to do this for you (just use with caution as it wouldn't be ideal to turn the machine off with a heated hot end as it is asking for clogs and trouble!)

I think the poweroff command would look similar to this (not entirely sure this would work as I don't know if it asks for verification that you want to power down the machine ..In the web UI it does ask if you REALLY want to power the machine off before it does it)

http.POST("{\"command\":\"turnPSUOff\"}"); //Send command to printer

Let us know how you get on - post pics :smiley:
Regards
Rob

1 Like

Yes, what Rob posted should work and I agree with him to use that with caution. We have not tested what would happen if you pushed that off button while a print is running. I'm guessing Octoprint will still display that warning and confirmation. If you're not there to confirm then it will do nothing.

I'm just starting to read the forums so my comment isn't so timely, but I notice an early comment in this thread asks if the OP tried the enclosure plugin.

I am doing something similar, using the enclosure plugin to watch a hardware button on the pi's gpio, and then trigger a script that will toggle power via another plugin. The problem if anyone else tries this method is that when enclosure calls an external script, it pauses all plugin processing waiting on the script response. The result when you attempt to post to another plugin is that octoprint freezes. The destination plugin can't process the request because the whole system is blocked in enclosure waiting for the response.

I worked around it by wrapping my toggle script in another script that invokes the real one in the background.

If I get a chance I'll post my scripts and config in a new thread in case anyone is interested.

It might be worth reading this post I just did. It's a GPIO pin throwing a relay for some circuit.