does MQTT library support 2 brokers?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

does MQTT library support 2 brokers?

ソリューションへジャンプ
2,658件の閲覧回数
ping1
Contributor V

Dear all

I am using MQTT library under lwip example, I wonder whether it supports two brokers at same time. If so, how to do it?

Regards!

Ping

ラベル(1)
タグ(2)
0 件の賞賛
返信
1 解決策
2,636件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @ping1 ,

  Sorry for my misleading previously!

    SDK LWIP can support more than one MQTT broker at one time, you just need to define more MQTT broker, attached code is for your reference, and it has been tested, you can refer to it.

uint8_t *serverName[MAXMQTT_NUM] = {EXAMPLE_MQTT_SERVER_HOST, MQTT_SERVER_HOST2}; 
uint32_t serverPort[MAXMQTT_NUM] = {EXAMPLE_MQTT_SERVER_PORT, MQTT_SERVER_PORT2}; 

for(uint32_t i=0; i<MAXMQTT_NUM; i++)
{
mqtt_client[i] = mqtt_client_new(); 
}

 

for(uint32_t i=0; i<MAXMQTT_NUM; i++)
{
if (ipaddr_aton(serverName[i], &mqtt_addr[i]) && IP_IS_V4(&mqtt_addr))
{
/* Already an IP address */
err = ERR_OK;
}
else
{
/* Resolve MQTT broker's host name to an IP address */
PRINTF("Resolving \"%s\"...\r\n", serverName[i]);
err = netconn_gethostbyname(serverName[i], &mqtt_addr[i]);
}
}

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
2,622件の閲覧回数
mjbcswitzerland
Specialist V

Hi

MQTT operates over a TCP socket or a secure TCP socket and so any number of instances should be possible. This has nothing to do with Ethernet or the number of Ethernet controllers available but is restricted only by the resources available (mainly RAM).

Each MQTT client can have its own MQTT broker settings and behave independently of other MQTT clients that are operating on the top of the same TCP/IP stack.

I don't know details of the LWIP MQTT implementation but with the uTasker MQTT client any number can be used, whereby it is to note that the TLS layer, when using secure MQTT connections is where the most RAM is required and so is more of the practical limit if multiple secure sessions are used in parallel.

Regards

Mark

 

0 件の賞賛
返信
2,637件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @ping1 ,

  Sorry for my misleading previously!

    SDK LWIP can support more than one MQTT broker at one time, you just need to define more MQTT broker, attached code is for your reference, and it has been tested, you can refer to it.

uint8_t *serverName[MAXMQTT_NUM] = {EXAMPLE_MQTT_SERVER_HOST, MQTT_SERVER_HOST2}; 
uint32_t serverPort[MAXMQTT_NUM] = {EXAMPLE_MQTT_SERVER_PORT, MQTT_SERVER_PORT2}; 

for(uint32_t i=0; i<MAXMQTT_NUM; i++)
{
mqtt_client[i] = mqtt_client_new(); 
}

 

for(uint32_t i=0; i<MAXMQTT_NUM; i++)
{
if (ipaddr_aton(serverName[i], &mqtt_addr[i]) && IP_IS_V4(&mqtt_addr))
{
/* Already an IP address */
err = ERR_OK;
}
else
{
/* Resolve MQTT broker's host name to an IP address */
PRINTF("Resolving \"%s\"...\r\n", serverName[i]);
err = netconn_gethostbyname(serverName[i], &mqtt_addr[i]);
}
}

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

0 件の賞賛
返信