Generating a Connection Configuration File for a C Application

Before you run your C application, you must generate the configuration files that contain the information required to connect your application to your organization in Device Cloud.

The instructions in this section are for Linux distributions. For information about creating the file for VxWorks 7, see Device Cloud Quick Start for VxWorks 7.

You use the iot-control script to generate the base connection configuration file, iot-connect.cfg. It contains the Device Cloud endpoint, port, an application token, optional proxy settings. Specify the application token of the device manager application in this file.

Each application requires a connection configuration file with the name app_id.cfg, where app_id is the value you specified for the id parameter in your application initialization code. The file contains only the associated application token, which overrides the value in the iot-connect.cfg file. For more information, see Initializing Your C Application.

Note:

If the /etc/iot directory already contains the iot-connect.cfg file when you run iot-control, it is overwritten.

If you already generated the /etc/iot/iot-connect.cfg with the base connection information, go to step 9.

You need the following:

  • 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

  • the C agent built on your device

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

  • super user privileges on the 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 the application (your client application or the device manager) to copy the application token to the clipboard.
  5. Run the program to generate the configuration file and specify the required information.

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

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

    Valid values for the port are MQTT 8883 (secure) or MQTT 1883 (insecure).

    $ cd /path/to/device-cloud-lib-release/build/bin
    $ sudo iot-control
    cloud host address: host address of the cloud server
    Enter a value for cloud host address:
    endPoint
    cloud port number: port number of the cloud server
    Enter a value for cloud port number:
    8883
    application token: token to use when registering with the cloud
    Enter a value for application token:
    appToken
    
  6. Leave the default setting for cloud certification validation.
    validate cloud certificates: verify that cloud certificates are valid and signed by a known certificate authority
    Enter a value for validate cloud certificates:
  7. (Optional) Specify proxy information.
    proxy type: type of proxy server (blank for none)
    Enter a value for proxy type:
    http
    proxy server address: host address of the proxy server
    Enter a value for proxy server address:
    192.168.24.23
    proxy server port number: port number of the proxy server
    Enter a value for proxy server port number:
    3128
    proxy server user name: user name for the proxy server
    Enter a value for proxy server user name:
    iot
    proxy server password: password for the proxy server
    Enter a value for proxy server password:
    
    
  8. (Optional) Specify the log level.
    log level: default log level
    Enter a value for log level:
    

    The iot-connect.cfg file is created in the /etc/iot directory.

  9. To create an application-specific configuration file, open a text editor and specify the application token.

    Use the following template.

    For appToken, specify the value you noted on the Management Portal Applications page for your application.

    {
      "cloud": {
        "token": "appToken"
      } 
    }
    
  10. Save the file as app_id.cfg, where app_id is the value you specified for the id parameter in your application initialization code, and then copy the file to the /etc/iot directory.
    $ sudo cp app_id.cfg /etc/iot/.

When you run the device manager, it connects to Device Cloud based on the settings in the iot-connect.cfg file.

When you run your application, it connects to Device Cloud based on the settings in the iot-connect.cfg file and the token in the application-specific connection file.

The first time any application runs, the device_id file is created in the /var/lib/iot directory and is used as a prefix for the thing key. On the Management Portal, you can search for the prefix to find the applications that run on your device.