I made a simple test program due to issues when connection to a MQTT broker. The problem is that when I connect to the MQTT broker when it is offline I get not the expected false but the system hangs.
So I made a small test, ran it in the Arduino IDE and it works great, but in PlatformIO it fails (same code!). I have no clue what the problem is and I am completely stuck :-(
Only when the broker is not online I get the difference between Arduino IDE and PlatformIO. PlatformIO hangs but Arduino IDE returns a 0 (failed to connect). When the broker is online they both work as expected.
Seems in the NativeSocket.cpp (line 196) it is stuck in this loop where s == 0:
fnet_socket_close(socket_ptr);
while(Ethernet.socketStatus(s) != 1){
}
socket_ptr = nullptr;
Suggestions are very welcome!
#include <Arduino.h>
#include <SPI.h>
#include <NativeEthernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient testcl;
void connectMQTT3()
{
char sIp[15] = "192.168.2.44";
IPAddress MQTTbrokerIP(192,168,2,44);
Serial.println("initMQTT");
int result = testcl.connect(MQTTbrokerIP, 1883);
delay(200);
Serial.print("result: ");
Serial.println(result);
}
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
}
void loop() {
auto link = Ethernet.linkStatus();
Serial.print("Link status: ");
switch (link) {
case Unknown:
Serial.println("Unknown");
break;
case LinkON:
Serial.println("ON");
break;
case LinkOFF:
Serial.println("OFF");
break;
}
delay(1000);
connectMQTT3();
}
So I made a small test, ran it in the Arduino IDE and it works great, but in PlatformIO it fails (same code!). I have no clue what the problem is and I am completely stuck :-(
Only when the broker is not online I get the difference between Arduino IDE and PlatformIO. PlatformIO hangs but Arduino IDE returns a 0 (failed to connect). When the broker is online they both work as expected.
Seems in the NativeSocket.cpp (line 196) it is stuck in this loop where s == 0:
fnet_socket_close(socket_ptr
while(Ethernet.socketStatus(s) != 1){
}
socket_ptr
Suggestions are very welcome!
#include <Arduino.h>
#include <SPI.h>
#include <NativeEthernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient testcl;
void connectMQTT3()
{
char sIp[15] = "192.168.2.44";
IPAddress MQTTbrokerIP(192,168,2,44);
Serial.println("initMQTT");
int result = testcl.connect(MQTTbrokerIP, 1883);
delay(200);
Serial.print("result: ");
Serial.println(result);
}
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
}
void loop() {
auto link = Ethernet.linkStatus();
Serial.print("Link status: ");
switch (link) {
case Unknown:
Serial.println("Unknown");
break;
case LinkON:
Serial.println("ON");
break;
case LinkOFF:
Serial.println("OFF");
break;
}
delay(1000);
connectMQTT3();
}
Last edited: