Application Configuration
Application configuration can be broken down into required and optional configuration:
Required Configuration
identity.appIdYour unique application ID.auth.keyAn API key authentication token to securely connect your application to Watson IoT Platform.auth.tokenThe authentication token for the API key you are using.
Optional Configuration
options.domainA boolean value indicating which Watson IoT Platform domain to connect to (e.g. if you have a dedicated platform instance). Defaults tointernetofthings.ibmcloud.comoptions.logLevelControls the level of logging in the client, can be set toerror,warning,info, ordebug. Defaults toinfo.options.http.verifyAllows HTTP certificate verification to be disabled if set toFalse. You are strongly discouraged from using this in any production usage, this primarily exists as a development aid. Defaults toTrueoptions.mqtt.instanceIdOptional instance ID, use if you wish create a multi-instance application which will loadbalance incoming messages.options.mqtt.portA integer value defining the MQTT port. Defaults to auto-negotiation.options.mqtt.transportThe transport to use for MQTT connectivity -tcporwebsockets.options.mqtt.cleanStartA boolean value indicating whether to discard any previous state when reconnecting to the service. Defaults toFalse.options.mqtt.sessionExpiryWhen cleanStart is disabled, defines the maximum age of the previous session (in seconds). Defaults toFalse.options.mqtt.keepAliveControl the frequency of MQTT keep alive packets (in seconds). Details to60.options.mqtt.caFileA String value indicating the path to a CA file (in pem format) to use in verifying the server certificate. Defaults tomessaging.peminside this module. Use the special string"_os_"to use default python/OS truststore.
The config parameter when constructing an instance of wiotp.sdk.application.ApplicationClient expects to be passed a dictionary containing this configuration:
myConfig = {
"identity": {
"appId": "app1"
}.
"auth" {
"key": "orgid-h798S783DK"
"token": "Ab$76s)asj8_s5"
},
"options": {
"domain": "internetofthings.ibmcloud.com",
"logLevel": "error|warning|info|debug",
"http": {
"verify": True|False
},
"mqtt": {
"instanceId": "instance1",
"port": 8883,
"transport": "tcp|websockets",
"cleanStart": True|False,
"sessionExpiry": 3600,
"keepAlive": 60,
"caFile": "/path/to/certificateAuthorityFile.pem"
}
}
}
client = wiotp.sdk.application.ApplicationClient(config=myConfig, logHandlers=None)
In most cases you will not manually build the config dictionary. Two helper methods are provided to make configuration simple:
YAML File Support
wiotp.sdk.application.parseConfigFile() allows one to easily pass in application configuration from environment variables.
import wiotp.sdk.application
myConfig = wiotp.sdk.application.parseConfigFile("application.yaml")
client = wiotp.sdk.application.ApplicationClient(config=myConfig, logHandlers=None)
Minimal Required Configuration File
identity:
appId: app1
auth:
key: orgid-h798S783DK
token: Ab$76s)asj8_s5
Complete Configuration File
This file defines all optional configuration parameters.
identity:
appId: app1
auth:
key: orgid-h798S783DK
token: Ab$76s)asj8_s5
options:
domain: internetofthings.ibmcloud.com
logLevel: debug
http:
verify: True
mqtt:
instanceId: instance1
port: 8883
transport: tcp
cleanStart: true
sessionExpiry: 7200
keepAlive: 120
caFile: /path/to/certificateAuthorityFile.pem
Environment Variable Support
wiotp.sdk.application.parseEnvVars() allows one to easily pass in device configuration from environment variables.
import wiotp.sdk.application
myConfig = wiotp.sdk.application.parseEnvVars()
client = wiotp.sdk.application.ApplicationClient(config=myConfig, logHandlers=None)
Minimal Required Environment Variables
WIOTP_IDENTITY_APPIDWIOTP_AUTH_TOKENWIOTP_AUTH_KEY
Optional Additional Environment Variables
WIOTP_OPTIONS_DOMAINWIOTP_OPTIONS_LOGLEVELWIOTP_OPTIONS_HTTP_VERIFYWIOTP_OPTIONS_MQTT_INSTANCEIDWIOTP_OPTIONS_MQTT_PORTWIOTP_OPTIONS_MQTT_TRANSPORTWIOTP_OPTIONS_MQTT_CAFILEWIOTP_OPTIONS_MQTT_CLEANSTARTWIOTP_OPTIONS_MQTT_SESSIONEXPIRYWIOTP_OPTIONS_MQTT_KEEPALIVE