Gateway Configuration
Gateway configuration can be broken down into required and optional configuration:
Required Configuration
identity.orgIdYour organization ID.identity.typeIdThe type of the device. Think of the device type is analagous to a model number.identity.deviceIdA unique ID to identify a device. Think of the device id as analagous to a serial number.auth.tokenAn authentication token to securely connect your device to Watson IoT Platform.
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.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.gateway.GatewayClient expects to be passed a dictionary containing this configuration:
myConfig = {
"identity": {
"orgId": "org1id",
"typeId": "raspberry-pi-3"
"deviceId": "00ef08ac05"
}.
"auth" {
"token": "Ab$76s)asj8_s5"
},
"options": {
"domain": "internetofthings.ibmcloud.com",
"logLevel": "error|warning|info|debug",
"mqtt": {
"port": 8883,
"transport": "tcp|websockets",
"cleanStart": True|False,
"sessionExpiry": 3600,
"keepAlive": 60,
"caFile": "/path/to/certificateAuthorityFile.pem"
}
}
}
client = wiotp.sdk.gateway.GatewayClient(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.gateway.parseConfigFile() allows one to easily pass in gateway configuration from environment variables.
import wiotp.gateway.sdk
myConfig = wiotp.sdk.device.parseConfigFile("gateway.yaml")
client = ibmiotf.gateway.Client(config=myConfig, logHandlers=None)
Minimal Required Configuration File
identity:
orgId: org1id
typeId: raspberry-pi
deviceId: 00ef08ac05
auth:
token: Ab$76s)asj8_s5
Complete Configuration File
This file defines all optional configuration parameters.
identity:
orgId: org1id
typeId: raspberry-pi
deviceId: 00ef08ac05
auth:
token: Ab$76s)asj8_s5
options:
domain: internetofthings.ibmcloud.com
logLevel: debug
mqtt:
port: 8883
transport: tcp
cleanStart: true
sessionExpiry: 7200
keepAlive: 120
caFile: /path/to/certificateAuthorityFile.pem
Environment Variable Support
wiotp.sdk.gateway.parseEnvVars() allows one to easily pass in gateway configuration from environment variables.
import wiotp.sdk.gateway
myConfig = wiotp.sdk.gateway.parseEnvVars()
client = wiopt.sdk.gateway.Client(config=myConfig, logHandlers=None)
Minimal Required Environment Variables
WIOTP_IDENTITY_ORGIDWIOTP_IDENTITY_TYPEIDWIOTP_IDENTITY_DEVICEIDWIOTP_AUTH_TOKEN
Optional Additional Environment Variables
WIOTP_OPTIONS_DOMAINWIOTP_OPTIONS_LOGLEVELWIOTP_OPTIONS_MQTT_PORTWIOTP_OPTIONS_MQTT_TRANSPORTWIOTP_OPTIONS_MQTT_CAFILEWIOTP_OPTIONS_MQTT_CLEANSTARTWIOTP_OPTIONS_MQTT_SESSIONEXPIRYWIOTP_OPTIONS_MQTT_KEEPALIVE