esp8266-react icon indicating copy to clipboard operation
esp8266-react copied to clipboard

Framework support to disable Serial.print from production build

Open tichaonax opened this issue 2 years ago • 0 comments

One way we can reduce the build size is to add support to disable Serial.print(), Serial.println() or anything to do with Serial.print. This can save additional space. I have seen this code on the web and it does the trick I tested it works.

#define DEBUG 0

#if DEBUG == 1
  #define debug(x) Serial.print(x)
  #define debugln(x) Serial.println(x)
#else
  #define debug(x)
  #define debugln(x)
#endif // DEBUG

Then in the use case:

Serial.print(F("WiFi Disconnected. Reason code="));

becomes:

debug(F("WiFi Disconnected. Reason code="));

However it needs support in the Framework so we can turn Serial printing ON/OFF through desired features.ini or the platform.ini.

There is significant Serial print in the framework we could save that and user has option to turn ON/OFF like we do other features.

If there are libraries that can do that without large footprint the better. I just liked the simplicity of that approach.

tichaonax avatar Sep 11 '21 13:09 tichaonax