1.1.18.8 Connection
To connect to a MQTT broker the application should:
Configure the broker with
WDRV_WINC_MQTTBrokerSet
optionally applying a TLS context if secure connections are required.Configure the client credentials with
WDRV_WINC_MQTTClientCfgSet
.Register a user property callback with
WDRV_WINC_MQTTUserPropCallbackSet
.Establish a Will Message with
WDRV_WINC_MQTTLWTSet
.Initialize connection properties, if required.
Connect to the broker with
WDRV_WINC_MQTTConnect
.
WDRV_WINC_MQTT_CONN_PROP connProp; /* Initialize the connection property structure to default values. */ WDRV_WINC_MQTTConnPropDefaultSet(&connProp); /* Set the Topic Alias Maximum property to 100. */ WDRV_WINC_MQTTConnPropTopicAliasMaxSet(&connProp, 100); /* Broker address is mqtts://mqtt.example.com:8883. */ WDRV_WINC_MQTTBrokerSet(wdrvHandle, "mqtt.example.com", 8883, tlsHandle); /* Set the client ID and username/password for the user account. */ WDRV_WINC_MQTTClientCfgSet(wdrvHandle, "clientID", "username", "password"); /* Set the user property callback. */ WDRV_WINC_MQTTUserPropCallbackSet(wdrvHandle, mqttUserPropCallback); /* Connect to broker using a clean session, keep alive = 0 and protocol version 5. */ WDRV_WINC_MQTTConnect(wdrvHandle, true, 0, WDRV_WINC_MQTT_PROTO_VER_5, &connProp, mqttConnCallback, 0);