logo elektroda
logo elektroda
X
logo elektroda

TCP/IP communication of several ESP modules memory crashes when calling client.remoteIP

lotnik95 939 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18764281
    lotnik95
    Level 8  
    Hello

    I think I've been struggling with a problem for about a week now and I can't seem to solve it on my own and it's hard to find similar problems on the internet.... Namely, I want to communicate several ESP32 modules with each other using TCP/IP (one ESP is the server, the rest connect to it). Each ESP wants to differentiate by IP address and, depending on the address, put the incoming data into a specific variable. To read the IP address I use clien.remoteIP() - it returns the IP address, but if I call this function in a loop more than once my ESP gets a memory crash:

    (message: Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
    Core 0 register dump:
    PC : 0x000000 PS : 0x00060e30 A0 : 0x801100ad A1 : 0x3ffb3d30
    A2 : 0x3ffccd7c A3 : 0x3ffccfb0 A4 : 0x3ffcb340 A5 : 0x3ffcb320
    A6 : 0x0204a8c0 A7 : 0x0c04a8c0 A8 : 0x8010ff50 A9 : 0x3ffb3cf0
    A10 : 0x3ffccd8c A11 : 0x3ffccfb0 A12 : 0x3ffb3d3c A13 : 0x00000044
    A14 : 0x00000001 A15 : 0x0000006 SAR : 0x00000010 EXCCAUSE: 0x00000014
    EXCVADDR : 0x000000 LBEG : 0xx4000c349 LEND : 0xx4000c36b LCOUNT : 0x000000

    Backtrace: 0x00000000:0x3ffb3d30 0x401100aa:0x3ffb3d70 0x4011d011:0x3ffb3d90 0x40122019:0x3ffb3dd0 0x401272b6:0x3ffb3df0 0x401109cf:0x3ffb3e10 0x40088b7d:0x3ffb3e40

    I should add that the crash occurs just when trying to connect clients to ESP
    If I connect the modules without recognition everything is fine - I'm able to send a series of data (admittedly it goes slow, several times slower than via UDP because I've already done the same thing using UDP) but recognition is necessary to properly segregate the data - let's assume each esp sends data from a different sensor - the server has to collect it and process it... When I call client.remoteIP() only once, the program works (although not always, sometimes requiring several client resets)

    Would someone be so good as to advise or guide me at least on how to deal with this? Maybe there is an example available somewhere?
    I am also attaching the server code:
    Code: C / C++
    Log in, to see the code
    .

    and client code:
    Code: C / C++
    Log in, to see the code
    .

    Regards

    Added after 44 [minutes]:

    Plus a screen shot of the ESP Exception Decoder:
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #3 18764659
    lotnik95
    Level 8  
    Thank you for your reply

    I have also tried the client.stop but to no avail

    When the main loop looks like this I also get a crash when connecting the client:
    Code: C / C++
    Log in, to see the code
    .

    Added after 10 [minutes]: .

    Reading the address and port of the client right after checking the presence of the client helps, however in this situation I don't know why but I get every other message:
    Code: C / C++
    Log in, to see the code
    .

    Added after 48 [minutes]:

    However, when I try to do it as in the above code, I can't connect more than one client - the client sends, but the server doesn't print it to the serial (it only sees one client)
  • Helpful post
    #4 18764785
    khoam
    Level 42  
    lotnik95 wrote:
    However, when I try to do it as in the above code I am not able to connect more than one client - the client sends while the server does not print it to the serial (it only sees one client)
    .
    You only have one instance of the WiFiClient object in the server code. If you had more, you could handle more clients.
    https://arduino.stackexchange.com/questions/31256/multiple-client-server-over-wifi

    Added after 1 [hour] 2 [minutes]:

    Of course client.setNoDelay(1) should return to code ;) .
  • #5 18765264
    lotnik95
    Level 8  
    That's right, inserting setNoDelay(1) helped and communication is fast - thank you very much! (although still several times slower than over UDP which surprises me, but never mind)

    I still don't understand some things - the code was working fine, both modules were ok, now I restart it and I get crashes again when connecting a single client....
    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • Helpful post
    #6 18765295
    khoam
    Level 42  
    Knock the following line out of the loop().
    Code: C / C++
    Log in, to see the code


    Added after 9 [minutes]:

    and after server.begin() in the setup() function insert:
    Code: C / C++
    Log in, to see the code
  • #7 18765317
    lotnik95
    Level 8  
    the funny thing is that I can reset the client 50 times and nothing happens, I reload another working program, upload the one I uploaded here in the previous post and after 2 client resets it works and then it connects correctly every time, but when I e.g. restart the server module and it's a mess again

    delete
    Code: C / C++
    Log in, to see the code

    it doesn't help and I remember that earlier lack of it also caused crashes, it is hard to understand what is going on there, I have 3 ESP32 modules and on each of them it looks the same
  • #8 18765334
    khoam
    Level 42  
    lotnik95 wrote:
    the funny thing is that I can reset the client and 50 times and nothing,
    .
    What server-side messages then appear in the serial port monitor?

    Added after 4 [minutes]:

    lotnik95 wrote:
    but when i e.g. restart the modul that is the server and it is kaplan again
    .
    And what in this situation? Just before the crash.
  • ADVERTISEMENT
  • #9 18765340
    lotnik95
    Level 8  
    screen: left server, right client
    TCP/IP communication of several ESP modules memory crashes when calling client.remoteIP screen: left server, right client

    and with ESP Exception Decoder:
    Code: C / C++
    Log in, to see the code
    .

    Added after 54 [seconds]: .

    The crash is only when the client connects, if it connects it just keeps sending data indefinitely - on the server I read the data and display it on the serial monitor.
  • #10 18765374
    khoam
    Level 42  
    Most likely malfunctioning WiFi.softAPConfig() in the server. Insert after WiFi.softAP() a small delay (100 ms), as below:b8
    Code: C / C++
    Log in, to see the code
    .
    In addition, after WiFi.mode() insert WiFi.disconnect() and a small delay, in order to disconnect clients that were connected to the server just before it restarted:
    Code: C / C++
    Log in, to see the code
    .

Topic summary

The discussion revolves around issues faced while implementing TCP/IP communication between multiple ESP32 modules, where the function client.remoteIP() causes memory crashes when called repeatedly. Users suggest that not closing server-side client connections (using client.stop()) leads to memory leaks. Solutions include using client.setNoDelay(1) to improve communication speed and ensuring multiple instances of WiFiClient are used for handling multiple clients. Additional recommendations involve inserting delays after WiFi.softAP() and disconnecting clients before restarting the server to prevent crashes. Despite these adjustments, users still experience intermittent crashes, indicating potential underlying issues with the server configuration or memory management.
Summary generated by the language model.
ADVERTISEMENT