PlatformIO hangs when installing packages

These days, I am back with embedded programming. At AgriConnect, we use PlatformIO to setup and build embedded projects. This time, I want to evaluate a new chip and new software framework, so I tell PlatformIO to install new packages with the command pio pkg install, but it hangs.

Turn out that it is because of network problem between Vietnamese ISP and the CDN services that PlatformIO Labs use to mirror its package repositories.

The solution is to quickly setup a temporary SOCKS proxy, and let PlatformIO tool reach those CDN through the proxy. The requirement is that you have a server that is outside Viet Nam, and you can access it via SSH. The steps is simple:

  • First, make a SSH connection to our server, activating its SOCKS proxy feature. Assume that we use port 1337 for proxy.

    $ ssh -D 1337 -N my-server
    
  • Second, in another Terminal tab, do changing PlatformIO settings via environment variable, enabling proxy and running PlatformIO:

    $ PLATFORMIO_SETTING_ENABLE_PROXY_STRICT_SSL="false" ALL_PROXY=socks5://127.0.0.1:1337 pio pkg install
    

There is chance that you encouter this error:

Tool Manager: Error: Please read https://bit.ly/package-manager-ioerror
Tool Manager: Warning! Package Mirror: Missing dependencies for SOCKS support.
Tool Manager: Looking for another mirror... 

If it happens, it is because your PlatformIO tool was installed without proxy support. We can complement it by:

  • Determine where PlatformIO Core (the command line) is installed. By default, it is ~/.platformio/penv.

  • In the installation folder, we can see a bin folder, which contains python3 file and more.

  • Run that Python file like this command, to install a Python module called pysocks:

    $ ./bin/python3 -m pip install pysocks
    

Now, pio pkg install can use proxy and install packages.