Remote run with custom target that uses custom board


I am trying to do a remote upload of a custom board (A variation of arduino-due board that i call duelow).
This board is already added to the arduino-sam framework list of boards, and the linker scripts locally. So if I do a pio run -t upload everything works.
But I would like to be able to upload a project to a remote computer that only has default platformio installed. If i simply do a pio remote run -t upload -e release I get the Error: Unkown board ID 'duelow'
I am seeing this may be fixed with a Custom target that uses my board.
Here they talk about a custom target for a board, but it never creates target. It only declares the board.

I am getting confused with what would the term “Target” be in these two contexts.
This is my project.ini

platform = atmelsam
board = duelow
framework = arduino
lib_ldf_mode = deep
lib_extra_dirs = ../../libs, ../../external
lib_deps = 
  adafruit/Adafruit DRV2605 Library@^1.2.0
  adafruit/Adafruit BusIO @ ^1.11.5
  adafruit/Adafruit GFX Library @ ^1.11.0
monitor_speed = 115200

I tried adding a script that creates this target

env.AddCustomTarget("remoteenv", None, 'pio remote run -t upload')

But of course it didn’t work. What am I missing?

You need to make the project more portable – requiring to make local modifications to PlatformIO packages or platforms is not good practice and can lead to problems like these.

E.g., instead of copying the board JSON to the .platformio/platforms/atmelsam/boards folder, you can locally create a boards in the project and have the board JSON file in there. Same effect.

Further instead of copying the variant folders into .platformio/packages/framework-arduino-sam/variants, take advantage of the possibility of specfiying a custom variants directory in the platformio.ini, since the builder scripts supports this.

See e.g. an example at GitHub - maxgerhardt/pio-samd51n19-test

Lastly, it may help to turn on the “force fully remote” switch in the pio remote command, that is -r.

>pio remote --help
  -r, --force-remote

Thank you for your help, I waited to test the solution to mark it as such. I leave here all I did for future users

In all the subprojects that I need to remotely install I created a boards folder and a custom_variants folder. The first one had my custom boards json files, and the second I just copied the arduino_due_x folder I had in .platformio/packages/framework-arudino-sam
only code I changed was adding the board_build.variants_dir = custom_variants line in my platformio.ini file

Thanks again!