So without testing the code:
- If
main.cpp
is compiled, the definition of MQTT_MAX_PACKET_SIZE inmain.h
will be effective inPubSubClient.h
. - However,
PubSubClient.h
is included by other files as well, e.g.PubSubClient.cpp
. So ifPubSubClient.cpp
is compiled,main.h
is not part of the compilation and the definition is not effective. - I haven’t seen the error message, but I guess you’ll find that it’s a message from compiling
PubSubClient.cpp
and is not related tomain.cpp
.
To proceed:
- Remove the definition from
main.cpp
. - Instead add the following lines to
platformio.ini
:
build_flags =
-D MQTT_MAX_PACKET_SIZE=256