Hi,
I'm half way through the Cellular course on the dev academy and although I am able to connect to the Nordic and Hivemq publich brokers, when I attempt to connect to my serverless Hivemq cluster, I receive the mqtt_connect error 12.
My client_init is as below (username and password removed).
int client_init(struct mqtt_client* client)
{
int err;
/* Initializes the client instance. */
mqtt_client_init(client);
/* Resolves the configured hostname and initializes the MQTT broker structure */
err = broker_init();
if (err) {
LOG_ERR("Failed to initialise broker connection");
return err;
}
char password[] = "xxxxxxxxx";
char username[] = "xxxxxxxxxx";
struct mqtt_utf8 pass = {
.utf8 = (uint8_t*)password,
.size = strlen(password)
};
struct mqtt_utf8 uname = {
.utf8 = (uint8_t*)username,
.size = strlen(username)
};
/* MQTT client configuration */
client->broker = &broker;
client->evt_cb = mqtt_evt_handler;
client->client_id.utf8 = client_id_get();
client->client_id.size = strlen(client->client_id.utf8);
client->password = &pass;
client->user_name = &uname;
client->protocol_version = MQTT_VERSION_3_1_1;
/* MQTT buffers configuration */
client->rx_buf = rx_buffer;
client->rx_buf_size = sizeof(rx_buffer);
client->tx_buf = tx_buffer;
client->tx_buf_size = sizeof(tx_buffer);
/* STEP 5 - Modify the client client_init() function to use Secure TCP transport instead of non-secure TCP transport. */
client->transport.type = MQTT_TRANSPORT_SECURE;
struct mqtt_sec_config* tls_cfg = &(client->transport).tls.config;
static sec_tag_t sec_tag_list[] = { CONFIG_MQTT_TLS_SEC_TAG };
LOG_INF("TLS enabled");
tls_cfg->peer_verify = CONFIG_MQTT_TLS_PEER_VERIFY;
tls_cfg->cipher_list = NULL;
tls_cfg->cipher_count = 0;
tls_cfg->sec_tag_count = ARRAY_SIZE(sec_tag_list);
tls_cfg->sec_tag_list = sec_tag_list;
tls_cfg->hostname = CONFIG_MQTT_BROKER_HOSTNAME;
tls_cfg->session_cache = IS_ENABLED(CONFIG_MQTT_TLS_SESSION_CACHING) ? TLS_SESSION_CACHE_ENABLED : TLS_SESSION_CACHE_DISABLED;
return err;
}
Project conf is:
# C++
CONFIG_CPP=y
CONFIG_STD_CPP20=y
CONFIG_REQUIRES_FULL_LIBCPP=y
# Logging
CONFIG_LOG=y
# Button and LED support
CONFIG_DK_LIBRARY=y
# Newlib
CONFIG_NEWLIB_LIBC=y
# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_POSIX_API=y
# Memory
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=4096
# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_MODEM_KEY_MGMT=y
# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_NBIOT=y
# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_CLEAN_SESSION=y
CONFIG_MQTT_LIB_TLS=y
# Application
CONFIG_MQTT_PUB_TOPIC="alcsystems/publish/topic"
CONFIG_MQTT_SUB_TOPIC="alcsystems/subscribe/topic"
CONFIG_BUTTON_EVENT_PUBLISH_MSG="Hi from nRF91 Series device"
# CONFIG_MQTT_BROKER_HOSTNAME="mqtt.nordicsemi.academy"
CONFIG_MQTT_BROKER_HOSTNAME="033cdd1462f949a2b4812c18f4ca9d13.s1.eu.hivemq.cloud"
# STEP 2.2 - Change the MQTT broker port
CONFIG_MQTT_BROKER_PORT=8883
# CONFIG_MQTT_BROKER_PORT=1883
As you can see, I have increased the memory and also increased the buffer sizes to 512.
Any help would be gratefully received.
Thanks,
Andy