Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

ESP-Now

Hi
I am trying to use ESP-Now in a C++ program. Unfortunately it seems that even though the required header file is present, the lib (.a) is not:
"/app/src/main.cpp:96: undefined reference to `esp_now_init'"
I suspected this to be a problem with the makefile, but I cannot find out how to fix it, as I don't see where the libs are stored. Are they inside the docker container?
Thanks, Sean

Comments

  • atmegaatmega Schweiz

    Also, adding libespnow.a to the src path doesn't help either (which it should, because libpaths contains /src...)

  • rojerrojer Dublin, Ireland

    yes, libs are inside the docker container. we do not link with espnow as we had no luck getting it to work before (it seems to have a memory corruption bug which is exposed by our allocator).

  • atmegaatmega Schweiz

    Damn it :(
    I already tried with sending raw packets, and I get crashes all the time (when switching to promiscuous mode) So it seems I'll have to use WiFi, or build using Arduino for this project (I don't like it, and now that I know mongoose I hate it :smiley: )?

  • rojerrojer Dublin, Ireland

    i have never tried sending raw packets, but i don't see why that wouldn't work. can you share the code? maybe i can help.

    not much to be done about espnow unfortunately, it just fails to initialize with what looks like a double-free memory error. and since it's a binary blob - good luck fixing it...

  • atmegaatmega Schweiz

    When I use the following code:
    Callback:
    static void ICACHE_FLASH_ATTR
    promisc_cb(uint8 *buf, uint16 len)
    {
    printf("got packet!");
    }

    Init:
    wifi_set_opmode(STATION_MODE);
    wifi_set_promiscuous_rx_cb(promisc_cb);
    wifi_promiscuous_enable(1);
    uint8 mac[6] = {1,2,3,4,5,6};
    wifi_promiscuous_set_mac(mac);
    wifi_set_opmode(0x1);
    wifi_set_channel(11);

    It only works when I either comment out wifi_promiscuous_enable (nothing happens) or I set a MAC address which isn't present anywhere. If I set no MAC, or one which receives traffic on channel 11, I get about 20 "got packet!" and then a core dump. Looks like a memory leak, too. Maybe callbacks work differently? Shouldn't be the case though.

  • rojerrojer Dublin, Ireland

    ok, i'll take a look a bit later.

  • atmegaatmega Schweiz

    Thank you very much!

  • rojerrojer Dublin, Ireland

    sorry for taking so long, this is certainly not "a little bit" as promised, but still - i have good news.
    i looked at the issue and found a problem with our memory allocator: it was not properly locked. somehow this evaded detection up until today, and promiscuous mode exposed this. with fd1feba the following code no longer crashes:

    static void promisc_cb(uint8 *buf, uint16 len) {
      printf("got packet: %d bytes\n", (int) len);
      (void) buf; 
    }         
    
    enum mgos_app_init_result mgos_app_init(void) {
      wifi_set_opmode(STATION_MODE);
      wifi_set_channel(8);
      wifi_promiscuous_enable(0);
      wifi_set_promiscuous_rx_cb(promisc_cb);
      wifi_set_channel(8);
      wifi_promiscuous_enable(1);
      return MGOS_APP_INIT_SUCCESS;
    }
    

    i no longer think there's a problem with espnow, looks like i was wrong to blame it after all.

  • atmegaatmega Schweiz

    WOW that's really great news! I'll test ESP-Now thoroughly as soon as I can. Would there be demand for a JS API for ESP-Now and/or Raw Packet TX/RX? I could write one so everyone can profit :smile:

  • rojerrojer Dublin, Ireland
    edited March 28

    i haven't heard any reuquests for it - as you can probably tell, not many people were using promisc mode up until today, since it was basically non-functioning :)
    that said, have a go at it and share the result, if it works and looks good i see no reason to not integrate it.

    i added libespnow to the list of libraries we link with, so you can start experimenting without any changes to mOS. however, i have not tested it myself. let me know how it goes.

Sign In or Register to comment.