Issues with Concurrent HTTP and MQTT Connections on Controllino Ethernet Shield (W5100)

Hello everyone,

I'm currently working on a project using an Arduino with the Ethernet Shield (W5100) and running into issues when trying to manage both HTTP and MQTT connections concurrently.

Here are the libraries I'm using:

#include <Controllino.h>
#include <Ethernet.h>
#include <SPI.h>
#include <ArduinoHttpClient.h>
#include <PubSubClient.h>

I set up my clients like this:

EthernetClient ethClient;
PubSubClient clientMQTT(ethClient);
HttpClient clientHTTP(ethClient, "example.com", 80);

The problem I'm facing is that the connection to the MQTT broker drops whenever I make an HTTP request. I am aware that the W5100 chip can handle up to 4 sockets simultaneously, so theoretically, this shouldn’t be an issue. Or am I wrong?

What I've Tried

  • Separate Ethernet Clients: I've considered using separate EthernetClient instances for HTTP and MQTT, but I’m not sure if this is the best approach. Furthermore it didn't work.
EthernetClient ethClientMQTT;
EthernetClient ethClientHTTP;

PubSubClient clientMQTT(ethClientMQTT); //MQTT Client wird erstellt
HttpClient clientHTTP = HttpClient(ethClientHTTP, PROXY_SERVER, PORT);

Questions

  1. Is it feasible to use two separate EthernetClient instances for HTTP and MQTT? I'v found the following thread simultaneous-mqtt-and-http-post where exactly this was the solution
  2. Are there any best practices for managing multiple network connections with the W5100 chip?
  3. Could there be a library-related issue that’s causing this conflict?

Any help or suggestions would be highly appreciated. Thank you!

Best regards,
CJ

EthernetClient ethClient1;
PubSubClient clientMQTT(ethClient1);
EthernetClient ethClient2;
HttpClient clientHTTP(ethClient2, "example.com", 80);

Thanks for your reply! Finally it works. The reason was another mistake in my code (wrong IP definition). Both versions work:

EthernetClient ethClientMQTT;
EthernetClient ethClientHTTP;

PubSubClient clientMQTT(ethClientMQTT); //MQTT Client wird erstellt
HttpClient clientHTTP = HttpClient(ethClientHTTP, PROXY_SERVER, PORT);
EthernetClient ethClient1;
PubSubClient clientMQTT(ethClient1);
EthernetClient ethClient2;
HttpClient clientHTTP(ethClient2, "example.com", 80);

The order doesn't make any difference.

THANKS!