cancel
Showing results for 
Search instead for 
Did you mean: 

NXD_MQTT_CONNECT_FAILURE over local network with B-U585I-IOT02A and NetX Duo

David_RDM
Visitor

I am trying to setup a local MQTT over a local network with port 1883 and B-U585I-IOT02A using the Nx_MQTT_Client example project. 
I have followed the steps in :
https://community.st.com/t5/stm32-mcus-embedded-software/how-to-connect-stm32u5-b-u585iot02a-using-mqtt-to-local-mqtt/td-p/62128

However I still get error: 
x10005 NXD_MQTT_CONNECT_FAILURE

I have tried modifying the generation of code in CubeMX to not require crypto and TLS for the example project however the compiler screamed even more at me. Anybody managed to succsesfully setup MQTT over local network?

I disabled firewall on my broker and attempted the communication across other networks, still same error.
in my app_nextduo.h file I have set: 

#define MQTT_PORT NXD_MQTT_PORT // defined as 1883 non-tls in the client .h file

#define MQTT_BROKER_NAME "" /* MQTT Server */ // I put the IP here in the form "192,xxx,xxx,xxx" have also tried using construct IP(192, XXX, XXX..)

#define USER_DNS_ADDRESS IP_ADDRESS(1, 1, 1, 1) /* User should configure it with his DNS address */

// configured the DNS however I don't use it (see below)

static VOID App_MQTT_Client_Thread_Entry(ULONG thread_input)
{
  UINT ret = NX_SUCCESS;
  NXD_ADDRESS mqtt_server_ip;
  ULONG events;
  UINT aRandom32bit;
  UINT topic_length, message_length;
  UINT remaining_msg = NB_MESSAGE;
  UINT message_count = 0;
  UINT unlimited_publish = NX_FALSE;

  mqtt_server_ip.nxd_ip_version = 4;

//  /* Look up MQTT Server address. */
//  ret = nx_dns_host_by_name_get(&DnsClient, (UCHAR *)MQTT_BROKER_NAME,
//                                &mqtt_server_ip.nxd_ip_address.v4, DEFAULT_TIMEOUT); // NOT needed for local

//  /* Check status.  */
//  if (ret != NX_SUCCESS)
//  {
//    Error_Handler();
//  }
//

  /* Create MQTT client instance. */
  ret = nxd_mqtt_client_create(&MqttClient, "my_client", CLIENT_ID_STRING, STRLEN(CLIENT_ID_STRING),
                               &IpInstance, &AppPool, (VOID*)mqtt_client_stack, MQTT_CLIENT_STACK_SIZE,
                               MQTT_THREAD_PRIORTY, NX_NULL, 0);

  if (ret != NX_SUCCESS)
  {
    Error_Handler();
  }

  /* Register the disconnect notification function. */
  nxd_mqtt_client_disconnect_notify_set(&MqttClient, my_disconnect_func);

  /* Set the receive notify function. */
  nxd_mqtt_client_receive_notify_set(&MqttClient, my_notify_func);

  /* Create an MQTT flag */
  ret = tx_event_flags_create(&mqtt_app_flag, "my app event");
  if (ret != TX_SUCCESS)
  {
    Error_Handler();
  }

  /* Changed params for non-TLS func */
  ret = nxd_mqtt_client_connect(&MqttClient, &mqtt_server_ip, MQTT_PORT,
                                   MQTT_KEEP_ALIVE_TIMER, CLEAN_SESSION, NX_WAIT_FOREVER);

  if (ret != NX_SUCCESS)
  {
    printf("\nMQTT client failed to connect to broker \n",MQTT_BROKER_NAME);
    Error_Handler();
  }
  else
  {
    printf("\nMQTT client connected to broker < %s > at PORT %d :\n",MQTT_BROKER_NAME, MQTT_PORT);
  }

  /* Subscribe to the topic with QoS level 1. */
  ret = nxd_mqtt_client_subscribe(&MqttClient, TOPIC_NAME, STRLEN(TOPIC_NAME), QOS1);

  if (ret != NX_SUCCESS)
  {
    Error_Handler();
  }

  if (NB_MESSAGE ==0)
    unlimited_publish = NX_TRUE;

  while(unlimited_publish || remaining_msg)
  {
    aRandom32bit = message_generate();

    snprintf(message, STRLEN(message), "%u", aRandom32bit);

    /* Publish a message with QoS Level 1. */
    ret = nxd_mqtt_client_publish(&MqttClient, TOPIC_NAME, STRLEN(TOPIC_NAME),
                                  (CHAR*)message, STRLEN(message), NX_TRUE, QOS1, NX_WAIT_FOREVER);
    if (ret != NX_SUCCESS)
    {
      Error_Handler();
    }

    /* wait for the broker to publish the message. */
    tx_event_flags_get(&mqtt_app_flag, DEMO_ALL_EVENTS, TX_OR_CLEAR, &events, TX_WAIT_FOREVER);

    /* check event received */
        if (events & DEMO_MESSAGE_EVENT)
    {
      /* Get messages from the broker. */
      do
      {
        ret = nxd_mqtt_client_message_get(&MqttClient, topic_buffer, sizeof(topic_buffer), &topic_length, message_buffer, sizeof(message_buffer), &message_length);
        if (ret  == NXD_MQTT_SUCCESS)
        {
          printf("Message %d received: TOPIC = \"%s\", MESSAGE = \"%s\"\n", message_count + 1, topic_buffer, message_buffer);
        }
      }
      while (ret == NXD_MQTT_SUCCESS);

      if ( ret != NXD_MQTT_NO_MESSAGE)
      {
        Error_Handler();
      }
    }
0 REPLIES 0