Generating a Connection Configuration File for a Python Application

Before you can run your Python application, you must generate the application-specific configuration file that contains the information required to connect your application to your organization in Device Cloud.

The configuration file name you specify must match either the configuration file name in your application initialization code or must follow the convention app_id-connect.cfg, where app_id is the value you specified for the app_id parameter in your application initialization code. For more information, see Initializing Your Python Application.

For the device manager, specify the file name iot-connect.cfg.

By default, the script stores the file in the current directory. Ensure that you run the script from a directory to which you have write permissions.

You need the following:

  • the connection configuration file name or the application identifier you specified in your application initialization code

  • your user name, password, and URL for Device Cloud

  • the corresponding application defined in Device Cloud

  • if you connect through a proxy server, proxy configuration information

  • the Python agent from the Python repository installed on your device

  1. In your browser's address bar, type the URL you were given when you received your Device Cloud account, and then on the Sign In page, type your user name and password in the boxes.
  2. On the LaunchPad, click Development Tools, and then on the Management Portal, click Developer.
  3. Take note of the URL shown in the Endpoints section.

    In the following example, the endpoint is api.devicecloud.windriver.com. Do not include the /api portion of the URL.

    Device Cloud - Management Portal Endpoints Section
  4. Click Applications and on the Applications page, click the Copy icon on the right side in the row of your client application to copy the application token to the clipboard.
  5. Run the program to generate the configuration file and specify the required information.

    For agentShareDir, specify /usr/local/share/device_cloud for Linux and pythonInstallDir\share\device_cloud on Windows.

    For appToken, paste the token you copied from the Applications page.

    For endPoint, specify the endpoint you noted in step 3.

    Note:

    The Python agent on Windows does not support the use of port 443 to connect to Device Cloud.

    $ cd localDir
    $ agentShareDir/generate_config.py
    
    Generating config. Please enter connection information for the config file.
    
    Name of config file to write (eg. appname-connect.cfg) (Required)
    # app_id-connect.cfg
    Cloud host address (Required)
    # endPoint
    Cloud port (eg. 1883/8883/443) (Required)
    # 8883
    Cloud token (Required)
    # appToken
  6. (Optional) Specify proxy information.
    Route all traffic through a proxy (default false) (Optional)
    # true
    
    Proxy type (eg. SOCKS4/SOCKS5/HTTP)
    # HTTP
    
    Proxy host address
    # 192.168.24.23
    
    Proxy port
    # 3128
    
    Proxy username (Optional)
    # iot
    
    Proxy password (Optional)
    # iot

The file is created in the localDir directory with the file name you specified.

Before you run your application, ensure that you copy the configuration file to either the directory from which you run your application or the configuration directory you specified in your application initialization code.