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

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.

I recently use a simpler method to toggle the PSUcontrol
here is my script

#!/usr/bin/env python
import time
import RPi.GPIO as GPIO
import requests

GPIO.setmode(GPIO.BCM)
GPIO.setup(26,GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
  state = GPIO.input(26)
  if state == False:
   headers = {'Content-Type': 'application/json','X-Api-Key':'***********************',}
   data = '{ "command":"togglePSU" }'
   response = requests.post('http://octopi.local/api/plugin/psucontrol', headers=headers, data=data)
  time.sleep(0.2)

It does work as well in one single file. :smiley:

Do you have an Alexa?

You won't need to know any code really, just configure some variables....

I actually played around with togglePSU. It was a matter of simply changing the command in the PSUOn.sh to togglePSU. However, I never did get around to testing it while printing and I didn't know what PSU Control's behavior is when turning the printer off when not using the Octoprint UI. Have you tried toggling it while printing?

Hello @TerryB,

what a nice work!

Is it possible to drive a relay with the command "get" : i try the PSU control, but i just think i can put a esp8266 on the relay (x2) to control ON/OFF with 2 GPios of a Wemos D1 Mini...

But i am not good enough to modify your code...can you help a bit please?

The goal is to clic on the PSU Control button in Octoprint and activate the gpio of the Wemos D1 Mini, who activate the relay.

Dont know if its possible or not?

Thanks!

Hi Oli_vier,

Sure, I'll try to help you out. But I don't understand what you're trying to do just yet. What are you trying to turn on/off with the relay? You do know PSU control can use a relay to turn the printer on and off, don't you? That's what this code does. Help me understand what you're trying to do.

Terry

Thanks for your quick answer!

I think my need is a little bit useless because the Rpi has to be close of the printers because of USB cable....

What i wanna do is use a ESP8266 to put 2 relay on/off for 2 printers with Octoprint, so i dont need to wired the GPios of the Rpi...

But because the Rpi has to be close of the printer i think i dont need at all...

Hope you understand?

There is such a thing as "remote GPIO", for what it's worth.

2 Likes

hello @OutsourcedGuru,

thanks for the info,

but what i want is use a esp8266 to control one or more relay (easy, no problem) but remote commands buy the RPi in octoprint.

The example above is for 2 input button on esp8266 that give info to Rpi on Octoprint, i just want to do the inverse : RPi command the esp8266 to put a Gpio High and down...

That why i ask if i have to use the "GET" command in the arduino program above?

Thanks

You might look at this to see if anything's useful.

Yeah you're right. You need the RPi by the printer anyway.

That's awesome. Thanks for the info. I'm sure it'll come in handy.

thanks, really interesting, but no info about use of LAMP instead of a cloud, i hate cloud...no internet, nothing work, and i dont even think about privacy...lol

no change there is a pluging in Octoprint to do that...

Thanks anyway

I personally don't know of a turn-key plugin solution but that doesn't mean it doesn't exist. You might want to search the forum here, this is a popular topic I'm sure.

I know that I did a "big red switch" project (BRB) to solve a problem I had. My advice is for you to create a personalized solution to your problem.