Auto-connect on server startup... doesn't

What is the problem?
Applying a check in the checkbox next to "Auto-connect on server startup" in the Connection side panel does not seem to work for me. The server starts up without connecting.

What did you already try to solve it?
I looked at the ~/.octoprint/config.yaml file and it includes the expected settings under the serial section.

serial:
  autoconnect: true

Pressing the Connect button works as expected. What's unfortunate is that I have some pretty good away-from-home ability to control the printer but it's not auto-connecting on startup so that's a drag.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)
OctoPrint 1.3.8 running on OctoPi 0.15.0
Robo C2
Marlin 1.1.7-C2
octoprint.log (9.5 KB)
There's nothing in the serial.log.

That's odd. I just fixed it by...

  1. pressing the Disconnect button
  2. choosing the Save Connection Settings button
  3. pressing the Connect button again

It will now auto-connect on server start. I note that the config.yaml now indicates:

serial:
  autoconnect: true
  baudrate: 0
  port: AUTO

It feels like a bug to me since it should have connected without the other settings, methinks.

1 Like

Hey guys. I´m playing a little bit with a few plugins, and between them there is one that powers on or off the printer. When I power off, there is an option that powers off and disconnect, but when it is turned on, it doesn´t reconnect.
I uderstand that this is the expect behavior, and the "auto connect" is for connecting the printer to octoprint when it´s already powered on when I start octoprint.
Is there a way to add a command to a script, to force this connection a few seconds after it´s powered on, once octoprint is already running?

Personally, the script I'd do would probably be JavaScript since that's my preference but I'm thinking that one could create the following shell script.

~/scripts/connect

#!/usr/sh

sleep 5
curl -k -H "X-Api-Key: vvvvvvvvvvvvvvvvvvvvvvvvvv" -H "Content-Type: application/json" -F "command=connect" http://localhost/api/connection
chmod a+x ~/scripts/connect

You'd then call this near the end of the /etc/rc.local perhaps (but before the exit command).

Thanks once more for helping me. I´ve tryed the above and didn´t work.

I´ve got this:

400 Bad Request
Bad Request
The browser (or proxy) sent a request that this server could not understand.

But, if I remove the -F option, I´ve got this information, so maybe there is something with the "command=connect" part.

"current": {
"baudrate": null,
"port": null,
"printerProfile": "_default",
"state": "Closed"
},
"options": {
"baudratePreference": 115200,
"baudrates": [
250000,
230400,
115200,
57600,
38400,
19200,
9600
],
"portPreference": "/dev/ttyUSB0",
"ports": [
"/dev/ttyUSB0"
],
"printerProfilePreference": "_default",
"printerProfiles": [
{
"id": "_default",
"name": "JW Tarantula"
}
]
}

I´ve researched a little bit, and found the answer. Thank you once more for pointing me in the right direction.

I´ve did:

curl -k -H "X-Api-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d '{"command":"disconnect"}' http://localhost/api/connection

So, it´s not over. LOL.

It runs ok from command line, but if I call the script from the GUI, curl freezes.

My script is like this:

#!/bin/bash
sudo hub-ctrl -h 0 -P 2 -p 1
sleep 5
curl -k -H "X-Api-Key: xxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d '{"command":"connect"}' http://localhost/api/connection

The same thing happens to my disconnect script. I can successfully run it from command line with pi user, but won´t run from GUI shortcut.

#!/bin/bash
sudo hub-ctrl -h 0 -P 2 -p 1
sleep 5
curl -k -H "X-Api-Key: xxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d '{"command":"connect"}' http://localhost/api/connection

Any tips on that?

On the -F thing, I got that one from one of foosel's examples. I'm more of a -d sort of guy myself; I like to just create the body and send it like you did in your last example.

If it freezes from the GUI, then it's either not running (unlikely) or it's running but not returning immediately and it's faking out OctoPrint.

Try adding an ampersand to the end of the command that calls the script. In Bash terms this means "run this in the background".

Well, I´ve already tried that, and didn´t work. Ive found a temporary solution that I´m not proud of, once it´s creepy, but it´s workin for now. When I have more time I´ll investigate a little bit more.

Monitoring the processes, I´ve found that when running the script called from the GUI, curl freezes. I also realized, that killing that process after a few seconds, it works. So, I´ve created a 3rd script, that I´ke called kill.sh and did the following:

#printer_on.sh

#!/bin/bash
sudo hub-ctrl -h 0 -P 2 -p 1
sleep 5
/usr/local/bin/scripts/kill.sh &
curl -k -d '{"command":"connect"}' -H "X-Api-Key: AAD8E9C1A5574A979164818E414483EA" -H "Content-Type: application/json" -X POST http://localhost/api/connection

#kill.sh

#/bin/bash
sleep 5
ps -ef | grep "curl -k" | awk '{print ($2)}' | xargs kill

As I´ve said, it´s not something to get proud of, but it´s working... :stuck_out_tongue:

I think Raspbian includes pkill which is slightly easier, as in pkill curl.

I´m not familiarized with raspian yet. Tryed this pkil and worked. It´s stil ugly, but it´s working.
I feel like I owe you a beer for all the help you gave me.
My printer is now almost the way I want. Just thinking about some firmware mods.

:laugh: Don't worry, that feeling will go away when you notice something else that needs to be modded. Honestly, I've completely changed my Robo 3D printer from the ground up. The only software that remains is the forked Marlin but I'll replace that as soon as I figure out how to successfully back that up and can restore it if I want to.

  • Replaced the TFT menu system with a Conky-based theme
  • Cantilever stability for the print bed platform
  • Filament run-out block replacement
  • Manual print bed leveling addition
  • About three filament-delivery upgrades from stock
  • Removed PTFE tubing
  • Added sound events
  • Samba
  • Node JS subsystem
  • Styrofoam boxing for heat control
  • Temperature monitoring in the box
  • Two additional webcams
  • (Touchless) Alexa control of almost all printer functions
  • TP-Link power control over printer and the octo-proxy for remotely controlling it
  • Repurposing the print spool passthrough for the stereo cable

It never ends. I'd like to make a pretty version of the styrofoam boxing but I'm still thinking about how to do this. And I've got the parts in hand for an upgrade to turn it into a 3D scanner as well. It just lacks the time for me to build that out.


I teach software development in case you were wondering. :cheers:

yeah following your solution solves this problem

this is definitely a bug
and will confuse everyone who tries to get it to autoconnect
but then it won't..unless they do what you did in the solution