Can I install an older platformIO?

Background: I have about 300 product instances in the field containing an Arduino that can be updated with the attached Ubuntu instance over USB with platformIO. Or I thought I did. Many of them work fine. I can pull my latest code and use

platformio run --target upload --environment uno

to compile and update. However, some of them complain that there is no platform ‘Atmelavr’. All of them that I have tried, don’t seem to connect back home. For example ‘Pio account show’ tries to install tool-pioplus, and fails telling me I am not connected to the internet. ‘Pio platform install native’ similarly fails. I do indeed have an internet connection – that’s how I log in to these instances – remotely over ssh.

If I blow it away and try to install the latest, it wants me to install python3.6. This is on Ubuntu 16.04, so installing python 3.6 on 300 devices is a major undertaking. Moreover I have to change my own code to do that, or I have to juggle versions during and after the update, so it snowballs into a complete mess.

I have seen no mechanism to start over and install a version of pio that will work on python2.7, but I’m hoping someone knows a way or, better yet, a way to understand and resolve why it fails in the first place and how to fix it more readily. I doubt this is a network connectivity issue, it’s happening in the field and at my house with no firewall.

What does pio --version return from the CLI?

I think also the same was observed at Error: You are not connected to the Internet - pio 3.6.7 and Cannot install platform espressif32 on docker ubuntu:rolling. PIO 4.3.4-1 - #18 by ivankravets where the answer is basically: Upgrade to the latest core, the projects are backwards compatible. I think it also has something to do that file hosters were shut down that the old software relied on (bintray…), which is much better today with a content distribution network.

Of course for your installation there’s the caveat of getting a newer Python to be able to run PlatformIO at all. But to my knowledge, when installing it in VSCode for example, it does so with a portable Python version in a Python virtual environment, so the machine’s Python version shouldn’t matter too much (except being able to execute the installer).

Maybe @ivankravets has additional thoughts on this.

Thanks maxgerhardt, ‘pio version’ returns 3.6.4. I have tried many things to get this to work but upgrading seems to require Python 3.6. Perhaps I did it incorrectly. In this environment there is no IDE, just the core.

That’s correct, that’s a documented requirement.

I’ve grabbed myself the Ubuntu 16.04 image and installed in a virtual machine. Ran a full update (sudo apt update && sudo apt dist-upgrade). Noticed it does have Python 3.5.2 preinstalled then, but that’s still not high enough to run the latest PIO version.

I’ve used these commands to install Python 3.9 from the deadsnakes PPA, then pip, then PlatformIO. Here’s a general script you can adapt.

#!/bin/bash

# ask for root access now, so that it doesn't ask again
sudo true 

# check if PlatformIO already exists and uninstall it
if [ -x "$(command -v pio)" ]; then
	echo 'Detected PlatformIO installation, attempt to uninstall.'
	# CUSTOMIZE THIS and remove exit, not done by default
	exit 1
	# assume it was originally installed with packet manager
	#pip uninstall platformio
	# remove entire old PlatformIO directory 
	#rm -rf ~/.platformio
else
	echo 'Detected no previous PlatformIO installation.'
fi

# install Python 3.9
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9

# check
echo "Python version is:" $(python3.9 -V)

# install pip3.9
sudo apt install python3.9-distutils
wget -O get-pip.py https://bootstrap.pypa.io/get-pip.py 
sudo python3.9 get-pip.py
# check 
echo "pip3.9 version:" $(pip3.9 -V)

# install PlatformIO via installer script, isolated environment.
# https://docs.platformio.org/en/latest/core/installation.html#super-quick-mac-linux
# could also do sudo -H pip3.9 install platformio, but this is cleaner
wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -O get-platformio.py
python3.9 get-platformio.py

# put PlatformIO in PATH to be globally accessible
echo "export PATH=\$PATH:\$HOME/.platformio/penv/bin" >> ~/.bashrc
source ~/.bashrc

# check PlatformIO 
echo "PIO version:" $(pio --version)

Works nicely.

1 Like

On a different note, even on PIO 3.6.4, there is PlatformIO Remote available, per release notes. Haven’t used it much myself, but you may be able to use your host machine as the main compile thing, then just use the existing old PlatformIO installation on the hosts to start the remote agent there, so that they just accept the firmware binary and push them to the boards. Not an expert on that though, or even if it’s interoperatable between a newer and older PlatformIO version.

As a fallback, if upgrading Python + PlatformIO is just not feasable even with a script, you might want to look into other solutions, like building the firmware.bin locally with PlatformIO, copying it over to the older Ubuntu machines (SSH etc.), and invoking the locally installed ~/.platformio/packages/tool-avrdude/avrdude program to burn it to the Arduino. The commandline invocation for that can be seen with the Advanced → Verbose Upload project task. That would bypass PlatformIO for the remote machines and make them a dumb accept-firmware-and-burn-it machine.

Again, maybe @ivankravets has thoughts on reviving PIO 3.x (and PIO 4.x?) from the server-side, if a large fleet of devices is already in the field.

@maxgerhardt I don’t know how to thank you for all this! Very helpful. You’ve found a way to reduce the pain of a python3.6+ upgrade, but across 300 devices it is still painful and expensive. I didn’t tell you also that these are on vehicles and not on all the time, and they are behind a proxy so there is no direct inbound protocol capability, but the “build locally and avrdude it” idea is my favorite. I’m going to try that right now.

@maxgerhardt Spot on advice, works beautifully, thanks a million, seriously. I’ll check the .hex into my git repo, when I pull the code I’ll get the hex and I can avoid the build and go straight to avrdude. About the same level of pain as pio run --target upload

We don’t support PlatformIO Core 4 and the previous versions. We keep full compatibility with the projects created with PlatformIO Core 1.0-4.0. Please use the latest PlatformIO Core 5.

If there is no Python 3 package available in your OS registry, please use GitHub - pyenv/pyenv: Simple Python version management.