I often use the "user stop" function
M0; user stop
to insert something into my prints on a Prusa MK3. But for resuming the print, I had to access Octoprint's webinterface (on another floor). Is it possible to resume the print with a switch over a GPIO-PIN?
Thx for help - Carsten
I'm not sure about the gpio part - but you know that you can use a smartphone app to resume, right?
Had nearly the same needs same time ago. Needed a button to (re)start the next batch after clearing the buildplate. Maybe it's helpful for you - you just have to change the command to fit your needs.
from time import sleep
import RPi.GPIO as GPIO
import requests
GPIO.setmode(GPIO.BOARD)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
headers = {
"Content-Type": "application/json",
"X-Api-Key": "your-api-key-here"
}
data = '{"command": "start"}'
url = 'http://127.0.0.1/api/job'
while True:
if ( GPIO.input(10) == True ):
#print("Button pressed")
response = requests.post(url, headers=headers, data=data)
#print(response)
sleep(0.2)
The discussion about it is here:
I have installed the Python requests and changed
data = '{"command": "start"}'
to
data = '{"command": "resume"}'
inserted my API-Key.
The pythonScript is running, The button has a function, The request is been sent, but the result I get:
Button pressed
<Response [400]>
is not functioning as expected.
Has anybody an idea? - Carsten
It might be necessary to turn on CORS in Settings -> API... or the api_key is wrong.
here my code
headers = {
"Content-Type": "application/json",
"X-Api-Key": "hereinismyapikeyfromoctoprintsettings2"
}
data = '{"command": "resume"}'
url = 'http://127.0.0.1/api/job'
print("Button pressed")
response = requests.post(url, headers=headers, data=data)
print(response)
if my API-Code is not correct the RESPONSE is [403]
if API-Code is correct RESPONSE is [400]
CORS now is checked (on) but nothing changed.
The expected response is 401 or so say the docs.
Actually, this is what is expected:
{
"command": "pause",
"action": "resume"
}
Great Guru,
that is the solution! The response I get is [204] when it worked
and [409], if Octoprint is not paused, and it is not possible to resume a print.
Thank you very much for your help - Carsten