How do I deploy Python code from VSCode to the BB-400?

FAQs

This FAQ will explain how you can set up Python on Visual Studio Code (VSCode) and deploy your files from VSCode to your BB-400.

Install VSCode

Firstly, download VSCode using the following link: https://code.visualstudio.com/.

Install Python

If you do not already have Python downloaded on your PC then please install it using this link: https://www.python.org/downloads/.

Configure VSCode to use Python

Once VSCode has downloaded, open it so that you can configure it for Python. Please note that VSCode 2019 already has the Python extension preconfigured so you will not need to add it to your VSCode.

If you have an older version of VSCode or do not already have Python installed, click on the Extension icon, type in Python and click on the green install box:

Install Python

Create a new file and name it with the extension .py so that it is a Python file.
You will notice that at the bottom right of your VSCode the language mode is Python. Having Python set up on your VSCode means that features such as linting, debugging, code formatting, IntelliSense, etc are easily available. For more information about the Python extension please refer to https://marketplace.visualstudio.com/items?itemName=ms-python.python.

Install Deploy (Reloaded) extension

Now that we are set up to write Python code on VSCode, how do we then run that code on our BB-400?
The simplest way is by using the Deploy (Reloaded) extension (https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-deploy-reloaded).

To install the Deploy (Reloaded) extension click on the extension icon, type in deploy reloaded and click on install:

Deploy Python

In your .vscode folder create a new file called settings.json and copy and paste the following information into it:

Edit settings.json file

{
    "deploy.reloaded": {
        "packages": [
            {
                "button": true,
                "name": "NAME_OF_BB_PACKAGE",
                "description": "ADD_DESCRIPTION",
                "files": [
                    "**/*"
                ],
                "deployOnChange": true,
                "exclude": [
                    "**/__pycache__/**",
                    "examples/**",
                ]
            }
        ],
        "targets": [
            {
                "type": "sftp",
                "name": "BB-400 00c0",
                "description": "BB-PACKAGE Folder",
                "dir": "/usr/share/brainboxes/ADD_PACKAGE_DIRECTORY_NAME",
                "host": "IP_ADDRESS_OF_BB_400",
                "port": 22,
                "user": "BB_400_USERNAME, default is bb",
                "password": "BB_400_PASSWORD, default is last 4 digits of the MAC address",
                "modes": {
                    "/usr/share/brainboxes/bb-core/bb-core": 755,
                    "/usr/share/brainboxes/bb-core/scripts/*": 755,
                }
            }
        ]
    }
}

The first section “Packages” describes the files that you will deploy to your BB-400.
Add the name of the BB-400 package you are working on and want to deploy the code to, and add a description of the package.

The next section, “Targets”, deals with the location your files will be transferred to. Here, add the IP address and password of your BB-400. Please edit the sections that have been capitalised accordingly.

If, for example you want to work on the BB-CORE package then your deploy reloaded section will look like:

Deploy your code

Now that we have written come code and we want to run it on our BB-400, we will first deploy the file(s) to our BB-400.

Right click on the file/folder you are working on in VSCode and select “Select Deploy Operation …”:

Deploy Code

The command palette will give the following options:

Select “Deploy Selected File” and you should see the Deploy Reloaded icon on the bottom right of your VSCode:

Deploy Files

To check that your code has been successfully deployed click on View > Output and select Deploy Reloaded from the drop down bar menu, alternatively CTRL+SHIFT+U will bring up the output section also:

Output

If the output shows a tick then your code has been successfully deployed:

Success!

Alternatively you can use the shortcut CTRL+ALT+F to deploy the file you currently have open to your BB-400.

This FAQ has explained how you can install VSCode, set it up with Python, and deploy code from Windows to your BB-400.

FAQs