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
EthernetClientinstances 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
- Is it feasible to use two separate
EthernetClientinstances for HTTP and MQTT? I'v found the following thread simultaneous-mqtt-and-http-post where exactly this was the solution - Are there any best practices for managing multiple network connections with the W5100 chip?
- 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