Why does this code work different on Arduino IDE vs PlatformIO?

JaKe101

Member
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();
}
 
Last edited:
Thanks CorBee for your response!

I added the libraries in the platformio.ini but that did not make any difference.

Inspired by your suggestion, I reinstalled the Teensy platform which solved the problem.

Thanks CorBee :)
 
Thats unfortunate, I havent used this code myself so I cant help you with the code. But its a well known "issue" that libraries used for Arduino IDE and platformIO are not always in sync and might lead to differences. You could also download the library onto your system in the lib directory of your platformIO project. If I am not wrong PlatformIO always tries to use libraries from the lib-directory (in your project !!) before trying system-based platformIO libs.
 
Back
Top