I have used Arduino IDE for many years, and tinkered with PlatformIO during that time. But I have now decided to invest the time to make the switch fully to Platform IO and continue my projects in it going forward.
For my first project to convert, I have added the libraries to the platform.ini file and it compiles fine at that point and I can even call most of the libraries (I still need to working out OTA), but when calling pubsubclient, I start getting many errors including with ArduinoSTL.
I have tried some different platform versions, and libraries, but I do not feel I am on the right path yet and could use some help getting there.
Here is what compiles fine.
[env:esp32dev]
platform = espressif32
;platform = espressif32 @ 6.8.1
board = esp32dev
framework = arduino
;framework = arduino,
monitor_speed = 115200
lib_deps =
knolleary/PubSubClient@^2.8
;PubSubClient
adafruit/Adafruit Unified Sensor@^1.1.14
adafruit/Adafruit BME280 Library@^2.2.4
fabianoriccardi/Dimmable Light for Arduino@^1.6.0
adafruit/Adafruit BusIO@^1.16.2
Wire
SPI
;mike-matera/ArduinoSTL@^1.3.3
#include <Arduino.h>
//#include <WiFi.h> // WiFi module
//#include <PubSubClient.h> // MQTT
///#include <WebServer.h> // for OTA
///#include <ESPmDNS.h> // for OTA
//#include <Update.h> // for OTA
#include <Wire.h> // for BME280
#include <Adafruit_Sensor.h> // for BME280
#include <Adafruit_BME280.h> // for BME280
#include "dimmable_light.h" // for Dimmer
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.9.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20017.0 (2.0.17)
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 39 compatible libraries
Scanning dependencies...
Dependency Graph
|-- PubSubClient @ 2.8.0
|-- Adafruit Unified Sensor @ 1.1.14
|-- Adafruit BME280 Library @ 2.2.4
|-- Dimmable Light for Arduino @ 1.6.0
|-- Adafruit BusIO @ 1.16.2
|-- Wire @ 2.0.0
|-- SPI @ 2.0.0
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 6.4% (used 21032 bytes from 327680 bytes)
Flash: [== ] 17.8% (used 233241 bytes from 1310720 bytes)
=========================================================== [SUCCESS] Took 12.81 seconds ===========================================================
Now if I add the pubsubclient library call
#include <Arduino.h>
//#include <WiFi.h> // WiFi module
#include <PubSubClient.h> // MQTT
///#include <WebServer.h> // for OTA
///#include <ESPmDNS.h> // for OTA
//#include <Update.h> // for OTA
#include <Wire.h> // for BME280
#include <Adafruit_Sensor.h> // for BME280
#include <Adafruit_BME280.h> // for BME280
#include "dimmable_light.h" // for Dimmer
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
^~~
In file included from C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:196,
from .pio/libdeps/esp32dev/ArduinoSTL/src/ArduinoSTL.h:12,
from .pio/libdeps/esp32dev/ArduinoSTL/src/ArduinoSTL.cpp:1:
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:217:20: error: 'OnReceiveCb' has not been declared
void onReceive(OnReceiveCb function, bool onlyOnTimeout = false);
^~~~~~~~~~~
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:220:25: error: 'OnReceiveErrorCb' has not been declared void onReceiveError(OnReceiveErrorCb function);
^~~~~~~~~~~~~~~~
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:308:5: error: 'OnReceiveCb' does not name a type
OnReceiveCb _onReceiveCB;
^~~~~~~~~~~
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:309:5: error: 'OnReceiveErrorCb' does not name a type
OnReceiveErrorCb _onReceiveErrorCB;
^~~~~~~~~~~~~~~~
In file included from .pio/libdeps/esp32dev/ArduinoSTL/src/ArduinoSTL.h:12,
from .pio/libdeps/esp32dev/ArduinoSTL/src/ArduinoSTL.cpp:1:
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:202:12: error: 'std::isinf' has not been declared
using std::isinf;
^~~~~
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:203:12: error: 'std::isnan' has not been declared
using std::isnan;
^~~~~
C:/Users/User/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:206:12: error: 'std::round' has not been declared
using std::round;
^~~~~
*** [.pio\build\esp32dev\lib4c0\ArduinoSTL\ArduinoSTL.cpp.o] Error 1
=========================================================== [FAILED] Took 19.24 seconds ===========================================================
Now the interesting part… If I enable only pubsubclient in the platform.ini file and call only it in the main.cpp then it compiles fine too.
Here is the link to the pubsubclient doc
https://registry.platformio.org/libraries/knolleary/PubSubClient