cancel
Showing results for 
Search instead for 
Did you mean: 

Connect to MQTT Broker with STM32F746G Discovery

HPham.1590
Senior

Hi, I'm trying to connect to my MQTT Broker with STM32F7 Discovery kit.

Firstly, I used MQTT Client in LwIP stack.

When I call this function: mqtt_client_connect()

the Error return ERR_RTE, mean Routing Error

/** Routing problem.     */

 ERR_RTE    = -4,

So anybody can give me some advice about this problem? I make sure that the IP Address and topic is right.

Many thanks.

Below is my function:

void example_do_connect(mqtt_client_t *client, const char *topic)
{
  struct mqtt_connect_client_info_t ci;
  err_t err;
 
  /* Setup an empty client info structure */
  memset(&ci, 0, sizeof(ci));
 
  /* Minimal amount of information required is client identifier, so set it here */
  ci.client_id = "ExampleClientPub";
  //ci.client_user = "mosquitto";
  //ci.client_pass = "chupasangre"; /* Tiempo en mi caso */
 
 
  /* Initiate client and connect to server, if this fails immediately an error code is returned
     otherwise mqtt_connection_cb will be called with connection result after attempting
     to establish a connection with the server.
     For now MQTT version 3.1.1 is always used */
  ip_addr_t mqttServerIP;
  IP4_ADDR(&mqttServerIP, 46, 145, 85, 31);
//  err = mqtt_client_connect(client, &mqttServerIP, MQTT_PORT, mqtt_connection_cb, 0, &ci);
  err = mqtt_client_connect(client, &mqttServerIP, MQTT_PORT, mqtt_connection_cb, &topic, &ci);
 
  /* For now just print the result code if something goes wrong */
  if(err != ERR_OK) {
    LCD_UsrLog("mqtt_connect return %d\n", err);
  }
	else
	{
		LCD_UsrLog("Connected");
	}
}
 
/* Called when publish is complete either with sucess or failure */
static void mqtt_pub_request_cb(void *arg, err_t result)
{
  if(result != ERR_OK) {
    printf("Publish result: %d\n", result);
  }
}

2 REPLIES 2
Guillaume K
ST Employee

are the client and server on different networks ?

in the LwIP initialisation code, is there a call to netif_set_default(&netif) ? without this call, there is no default interface for routing to servers outside client's local network.

ex:

https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32F769I-Discovery/Applications/mbedTLS/SSL_Client/Src/net_sockets.c#L83

Many thanks for your reply, I investigated this Issue.

Problem come from my STM32F7 kit's IP address.

I need to set a static IP address.

BR,

Hieu