NetXDuo with MQTT on STM32F4 Multihome Applications

Kirsten Jens 1 Reputation point
2023-01-23T08:42:11.4233333+00:00

A STM32F4 client is supposed to work as multiple MQTT client on:

a) multiple IP addresses (up to three) where each IP connection uses the same port number or maybe different ones.

b) one IP address but then with three different port numbers.

Questions:

  1. in case a) and b), can the same tls_setup_callback function be used, how should the certificate management be approached?
  2. in case a) multiple IP instances are created (either with or without DHCP) and each IP instance will run in an own thread, correct?
  3. in case b) one instance of IP is created (either with or without DHCP) and each MQTT connection is running in a different thread, correct?
Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
397 questions
Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
331 questions
{count} votes

5 answers

Sort by: Most helpful
  1. AndresMlinar 256 Reputation points
    2023-01-23T22:06:29.32+00:00

    a. yes, correct

    b. yes, you will use the same IP instance to initiate three different connections on three different sockets

    1. Will be answered in a separate reply
    2. Yes, you are correct
    3. there is on thread associated with an IP instance, but you can have several clients running on the same thread. If you have one IP instance but several sockets, then you will have one thread for the IP instance and one (or more) for your application.
    4. Yes, you are correct
    0 comments No comments

  2. Kirsten Jens 1 Reputation point
    2023-01-26T16:45:45.09+00:00

    Thank you for your answer.

    We understand, that we create one Internet connection on one IP instance.

    We create either one OR three MQTT client threads.

    A) If we create one MQTT thread we go for one after another of the connections and publish and/or subcribe in each connection as required.

    B) If we create three MQTT threads we manage the publishing and/or subscription of each connection in a separate thread, but all on the same IP instance.

    Both A) and B) is possible. We would prefer B). Everything correctly understood?

    At a later stage, we might have one HTTPS connection and two MQTT, then we follow the same principle on one IP instance and again in three threads. This works the same, does it not?

    0 comments No comments

  3. Kirsten Jens 1 Reputation point
    2023-01-26T16:46:15.9466667+00:00

    Thank you for your answer.

    We understand, that we create one Internet connection on one IP instance.

    We create either one OR three MQTT client threads.

    A) If we create one MQTT thread we go for one after another of the connections and publish and/or subcribe in each connection as required.

    B) If we create three MQTT threads we manage the publishing and/or subscription of each connection in a separate thread, but all on the same IP instance.

    Both A) and B) is possible. We would prefer B). Everything correctly understood?

    At a later stage, we might have one HTTPS connection and two MQTT, then we follow the same principle on one IP instance and again in three threads. This works the same, does it not?

    0 comments No comments

  4. AndresMlinar 256 Reputation points
    2023-01-26T17:29:57.5566667+00:00

    Yes, your understanding is correct. Also later if you want to use HTTPS you can follow the same principle. I hope this helps!

    0 comments No comments

  5. Kirsten Jens 1 Reputation point
    2023-03-21T07:05:45.12+00:00

    Hello,

    in the meantime, we have set up three MQTT Client connections, each in its own thread.
    They all are run on a single IP instance, since there is only one Ethernet connection with one PHY.
    The MQTT Clients run on Ports 8886, 8887 and 8888 respectively.
    They all use the same certificate and key in mutual authentication on TLS1.3.

    The problem that we have now is, that the Broker accepts each of the Clients perfectly well, when they connect and publish singularly, meaning, when there is only one connection at a time.

    As soon as a second connection is established after a previous one, the previous connection is destroyed by the broker and only the new connection is now running. The same applies then to all further connections to the broker. Each new connection destroys the previous one and only the new connection remains running.

    Question(s):

    • We use the same certificates and keys and are using the same tlssetupcallback for this purpose. Is there possibly any other certificate handling required?
    • Is it generally possible, that multiple connections can run simultaneously or do they have to blocked from each other, e.g. by semaphores etc?
    • If we can use the same certificate and key for each MQTT Client, is this certificate and key management efficient if we add them for each MQTT Client again? Or can all of the MQTT Clients refer to the same certificate and key pointer?
    • In one of the next steps, we want to run server and client functionality on the MCU. What is the way to handle or to manage the certificates and keys?

    Thanks for your help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.