[SOLVED] Error building ESP32 node: multiple definition of `app_main'

  • I am trying to build a simple MySensors node based on an ESP32 board (WEMOS LOLIN32). When compiling/linking I get this error:

    /var/folders/kp/0pvgxrnd3jn33s22hqwphrw00000gn/T/arduino_cache_624989/core/core_efeb97a62522d93e012a29bee7d9532f.a(main.cpp.o): In function `app_main':
    /Users/willem/Library/Arduino15/packages/esp32/hardware/esp32/1.0.1/cores/esp32/main.cpp:30: multiple definition of `app_main'
    sketch/test1.ino.cpp.o:/Users/willem/Documents/Arduino/libraries/MySensors/hal/architecture/ESP32/MyMainESP32.cpp:44: first defined here
    collect2: error: ld returned 1 exit status

    Can someone explain this error?
    BTW: I can successfully build other sketches for this board; it's just when I #include mysensors.h when things go wrong. I get the same results building on Arduino or PlatformIO.
    It's this simple test sketch that I'm trying to build:

    #define MY_DEBUG
    #define MY_RADIO_RF24
    #define MY_NODE_ID 42
    #include <SPI.h>
    #include <MySensors.h>
    #define CHILD_ID 3
    #define BUTTON_PIN 12
    MyMessage msg(CHILD_ID, V_TRIPPED);
    void setup() {
        pinMode(BUTTON_PIN, INPUT);
        digitalWrite(BUTTON_PIN, HIGH);
    void presentation() {
        present(CHILD_ID, S_DOOR);
    void loop() {
        static int oldValue = 0;
        int value = digitalRead(BUTTON_PIN);
        if (value != oldValue) {
            send(msg.set(value == HIGH ? 1 : 0));
            oldValue = value;

  • Hardware Contributor


    Do you use MySensors master branch??
    If so, try to use the development branch, it should work.

    Side note:

    • you don't need to add spi.h
    • I'm not sure if you can use esp as a node in MySensors. As nodes, if I'm not wrong, people use esp as gateways+sensors connected (when you need), but not as nodes.
      I never tried esp as mysensors nodes; in that case I usually use direct mqtt or http api. I get it why using them as simple mcus for nodes, but I prefer better lowpower mcus for nodes.. so I can't tell you more on this point.
    • for a simple esp32 gw sketch you can take a look in your Arduino IDE/Examples/MySensors, and of course in MyConfig.h for others defines.

    I hope this helps.

  • You can also try to use esp32 board definition v1.0.0. I guess you are now using 1.0.1

  • I am using the latest stable version (2.3.1).
    I want to use the ESP32 board because I am building a rather huge sketch (lots of UI and data RAM requirements) and I also need a WiFi connection. I did not know that the ESP32 support in MySensors is only meant to build gateways.
    I have also tried building the ESP32 Gateway example, but this produces the same error.
    (BTW: I have successfully built the ESP8266 + MQTT gateway).

  • @electrik : downgrading the board definition to 1.0.0 worked. I can now build the ESP32 gateway.
    However, I'm not quite there yet, because I get an endless series of "Brownout detector" messages:

    Brownout detector was triggered
    ets Jun  8 2016 00:22:57
    rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    mode:DIO, clock div:1
    entry 0x400802e4
    17 MCO:BGN:INIT GW,CP=RNNGF---,REL=255,VER=2.3.1
    21 TSF:LRT:OK
    23 TSM:INIT
    24 TSF:WUR:MS=0
    34 TSM:READY:ID=0,PAR=0,DIS=0
    Brownout detector was triggered

  • My simple sketch is now working fine. So it appears that you can use the ESP32 support in MySensors to build non-gateway nodes too.
    (For the moment, I am not going to investigate the "Brownout" problem in the ESP32 gateway example any further, because I have a perfectly working ESP8266 MQTT gateway...)
    Thank you both for your help!

  • One more update:
    Because I mostly use PlatformIO as my IDE and I don't know how to downgrade board versions there,
    as @scalz suggested, I tried the development version of MySensors.
    I am happy to report that this also solves the problem.

  • as a newbie to Mysensors and platformio this took me a while with the same problem.

    The solution (like described above, but not understandable for me at first) is:

    platformio.ini add 
    lib_deps =    https://github.com/mysensors/MySensors.git#development

    which currently links to Mysensors 2.3.2-beta #ea093e5

    and the errror is gone 🙂