diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c index bf8f9cb0..0a078035 100644 --- a/src/apps/mqtt/mqtt.c +++ b/src/apps/mqtt/mqtt.c @@ -55,6 +55,7 @@ #include "lwip/pbuf.h" #include "lwip/altcp.h" #include "lwip/altcp_tcp.h" +#include "lwip/apps/altcp_tls.h" #include #if LWIP_TCP && LWIP_CALLBACK_API @@ -1284,6 +1285,16 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, if (client->conn == NULL) { return ERR_MEM; } +#if LWIP_ALTCP_TLS + if (client_info->tls_config) { + struct altcp_pcb *pcb_tls = altcp_tls_new(client_info->tls_config, client->conn); + if (pcb_tls == NULL) { + altcp_close(client->conn); + return ERR_MEM; + } + client->conn = pcb_tls; + } +#endif /* Set arg pointer for callbacks */ altcp_arg(client->conn, client); diff --git a/src/include/lwip/apps/mqtt.h b/src/include/lwip/apps/mqtt.h index 988525d2..52471a5c 100644 --- a/src/include/lwip/apps/mqtt.h +++ b/src/include/lwip/apps/mqtt.h @@ -48,8 +48,11 @@ extern "C" { typedef struct mqtt_client_t mqtt_client_t; /** @ingroup mqtt - * Default MQTT port */ -#define MQTT_PORT 1883 + * Default MQTT port (non-TLS) */ +#define MQTT_PORT 1883 +/** @ingroup mqtt + * Default MQTT TLS port */ +#define MQTT_TLS_PORT 8883 /*---------------------------------------------------------------------------------------------- */ /* Connection with server */ @@ -71,6 +74,9 @@ struct mqtt_connect_client_info_t { const char* will_msg; u8_t will_qos; u8_t will_retain; +#if LWIP_ALTCP && LWIP_ALTCP_TLS + struct altcp_tls_config *tls_config; +#endif }; /**