[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;
        }
        wait(200);
    }
    

  • Hardware Contributor

    Hi.

    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
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:808
    load:0x40078000,len:6084
    load:0x40080000,len:6696
    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
    30 TSM:INIT:TSP OK
    32 TSM:INIT:GW MODE
    34 TSM:READY:ID=0,PAR=0,DIS=0
    39 MCO:REG:NOT NEEDED
    
    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 🙂



  • Just to add for those using Arduino IDE, downloading the latest development version of MySensors fixes the same issue. Just go to https://github.com/mysensors/MySensors and hit "Clone/Download Zip", Download the zip then add to Arduino (Sketch -> Include Library -> Add .Zip Library then select the zip you downloaded). You may need to delete the old library folder from Documents\Arduino\libraries to ensure the new version is used. This will be fixed with MySensors 2.3.2.


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 2
  • 3
  • 2
  • 1

53
Online

11.4k
Users

11.1k
Topics

112.7k
Posts