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

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.