Non-standard platformio-core settings ignored by vscode extension

No matter what I do, I can’t seem to use anything other than the built-in platformio-core.

Granted, my situation is more complex than average, so I don’t expect a “one-click” solution, but I need to understand how the vscode extension interacts with pio to fix this.

So: I’m on NixOS, which means I cannot just use any downloaded binaries. While the nix package could theoretically be made to work, we’d still have problems with the respective toolchain binaries, so I figured I’d directly use a container (from Docker).

Starting it like this basically yields a “native workalike”, as if it was installed as my home user:

podman run --name=piocontainer --rm -it -p8008:8008 -e HOME=${HOME} -v ${HOME}:${HOME} -w $(pwd) shaguarger/platformio pio home --host=0.0.0.0 --port=8008

(It’s of course very insecure to mount ${HOME} entirely into the container, but for now first a PoC, I can always reduce to specific dirs).

So now I can access localhost:8008 with a browser and use all functionality of the web ui.

To actually have the pio command in my user session, I made a small wrapper:

#!/usr/bin/env bash

PC=piocontainer

if [ "$(podman ps --filter="name=$PC" | wc -l)" -lt 2 ]; then
	echo "FATAL: container \"$PC\" not running!"
	exit 1
fi

podman exec -t $PC pio "$@"

which I make sure is in the PATH (also of the vscode session) and which behaves perfectly fine like a “native” pio binary. (I.e. I can type all pio <command> stuff as usual).

My vscode settings point to the correct host:port and the

{
"platformio-ide.useBuiltinPIOCore": false,
"platformio-ide.useBuiltinPython": false,
"platformio-ide.pioHomeServerHttpHost": "127.0.0.1",
"platformio-ide.pioHomeServerHttpPort": 8008,
"platformio-ide.customPATH": "/home/jeroen/.platformio/bin"
}

where the last path contains the above wrapper script.

So the questions are:

  • why this doesn’t work? (Any pio buttons I press in vscode lead to Loading... message and after a while a server timeout error: Error: Could not start PIO Home server: Timeout error at Timeout._onTimeout)
  • how is the extension supposed to communicate with pio: only via the API (localhost:8008) or does it also execute the cli?
  • why does the extension try to install pio and try to start “the server”, even though I explicitly told it I’m not using the builtin ("platformio-ide.useBuiltinPIOCore": false)

Nah. This is the host and port that the PlatformIO extension will instruct pio to open a server at, not connect to. I’m not sure that what you wanna do is possible at all – of course you can point the PlatformIO extension to use an arbitrary pio binary through the path, but it’ll try and execute it in the context of the local machine.

Ah, thanks! (and so fast!)

So, I changed the wrapper script accordingly, meaning if the extension were to start pio home with the pio binary from either PATH or the "platformio-ide.customPATH" setting, it would end up executing the script and logging how it was executed.

However: when the extension states it hasn’t found pio-core it has not tried to execute any pio binary, so it uses a different mechanism to check for “a compatible pio-core” :question:

That’s what I was expecting, but given the above it doesn’t seem to be the case :question:
BTW: the wrapper script and the identical source:target dir mounts in the container should indeed make the local context identical to the container context, so it should work as soon as the extension actually does what it says it is doing?

For background here the script:

#!/usr/bin/env bash
THIS="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

PC=piocontainer
LOG="${THIS}/$(basename "$0").log"

log() {
	if [ $# -lt 1 ]; then
		{ printf "%s: " "$(date -Is)"; cat -; } >>"${LOG}"
	else
		printf "%s: %s\n" "$(date -Is)" "$*" >>"${LOG}"
	fi
}

start() {
	podman run \
		--name=$PC --rm -it -p8008:8008 \
		-e HOME=${HOME} \
		-v ${HOME}:${HOME} \
		shaguarger/platformio pio home --host=0.0.0.0 --port=8008
}

echo "$0: $*" | log
case $1 in
	home)
		start 2>&1 | log "start()"
		;;
	*)
		podman exec -t $PC pio "$@" 2>&1 | log
		;;
esac

Ah, ok, that just replacing the pio cli doesn’t work can be explained by this I guess:

That would mean that the vscode extension calls the python module directly…

@maxgerhardt Thanks, I followed the advice: Using an alternative `platformio-core` with the extension is not feasible for many use cases · Issue #3739 · platformio/platformio-vscode-ide · GitHub

1 Like