logo elektroda
logo elektroda
X
logo elektroda

ESP8266 WebServer Performance Issues: Main Loop Delays and Crashes

Dawidixxx 1041 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18930096
    Dawidixxx
    Level 7  
    Hey Hey :) .
    I have a problem when using the server on ESP, over time (once every few days) esp crashes and for example the main loop executes in 5-8 seconds (default ~244ms). Already in not the first project. Below posted I tried to optimise for memory used, on the advice of user Khoam, I still have a bit left. However, I don't know if it's me neglecting something or if the library itself might be causing the problem. I've made a precaution in the main loop, however I would like to know why this is happening.

    Link .
    The code has grown a bit and I would write it differently now, but I will try to describe the actions.
    ESP starts by checking if it has WiFi data stored otherwise it starts WiFiRegister and resets.
    Depending on the mode-STA/AP is combined (WiFiController), then the server is started (WebServerController) and esp waits for information from the web or RF receiver.
    The project itself consists of analogue volume knob control of the radio system over the whole plot + RF devices.
    Control via web + RF receiver + RF transmitter + pin on mosfet to disconnect servo (in case of esp reset and PWM misreading)
    Thanks in advance for your help and suggestions and I am open to any reasoned criticism of the code ;) .
    Regards.
  • ADVERTISEMENT
  • Helpful post
    #2 18930116
    sasiadstar
    Level 23  
    If it happens once in a while then the chance of finding the bug is quite poor.
    It could be a problem with the network connection, for example, or a hundred others.
    In general, the esp8266 is a rather "delicate" device and it likes to freak out.
    It is better to change to the esp32 controller for the 2 core version (1 core also came out).
    Networking times are heaven and earth, plus one CPU takes care of networking and bluetooth and the other is for user code.
    In addition, it supports true multitasking .
  • ADVERTISEMENT
  • #3 18961305
    krzbor
    Level 27  
    I have an SMA inverter. I have often had problems connecting to it (it has its own web server). It's a bit far from the AP and I thought it was a signal problem, although it shouldn't be. Once I decided to restart the SMA - access was still not there. I restarted the AP and everything was OK. I started to analyse the problem - an unused TPlink router was "doing the job" as the AP. I had a lot of the family's devices connected on it (phones, laptops and tablets) and of course 'my' ESP. I began to wonder how many simultaneous WiFi connections such an AP could have. I couldn't find such information anywhere, so I wrote to TPlink's service department - I got the answer that the recommended maximum is about 14-15, and that's the number I was achieving! So I bought a new TPlink AP (surprisingly it was more expensive than the router), but it supports up to 64 simultaneous connections. I didn't have any more problems. As you can see, the problem is not always on the device side.
  • ADVERTISEMENT
  • #4 18961464
    Slawek K.
    Level 35  
    The SMA connection is the SMA problem, I have two SMA inverters and it's exactly the same on both, and it doesn't depend on the number of AP connections, that's the beauty of it.
    Sorry for the OT, I just wanted to refer to a post by a colleague @krzbor .

    Greetings
  • #5 18961476
    sasiadstar
    Level 23  
    @SlaweK K. colleague @krzbor has a bit right about that. People mess around with devices they want to connect and sometimes it's the router that can't handle it.
    I have a tp-linka (can't remember the model) which is about 5 years old and is currently used as a switch because it couldn't cope with the emergence of android phones.
    For some reason when I connected my phone it slowed down so much that it couldn't cope and I had to replace it with a new one.
    Nothing helped and there was no new firmware and open-wrt was also out and there was no way to update.

    Generally when writing the previous post I was suggesting the esp8266 itself.
    I have spent over 6 months with this chip and know how annoying it is.
  • #6 18961497
    Slawek K.
    Level 35  
    Everyone probably has different experiences. I got rid of TP-Link about 10 years ago because it is lousy, I use Mikrotik routers and have no problems.
    As for esp8266, I've been playing with these systems for a few years now, I've built my home automation on them, including control of central heating, DHW and underfloor heating, pressurised solar collector or irrigation, and my observation is that it's a very cool system, and the possible issue of hanging is mainly a problem of not very well written software. I tried to switch to esp32 but the underdevelopment of this circuit in the initial versions put me off (if only the issue of a simple ADC) and for the time being I am waiting for better times for it, as it obviously has nice potential ;) .

    Greetings
  • #7 18961505
    sasiadstar
    Level 23  
    @SlaweK K. well you see and I have completely the opposite experience and I don't complain about esp32 I appreciate its speed and stability (and the two cores) but it all depends on what you expect from the chip. You are annoyed by the adc in esp32 and I am annoyed by the sleep mode in esp8266 :) whatever you like.
    I'm generally writing on the subject because when something doesn't work, people always have the client device in the foreground and few people think that the infrastructure is to blame.
  • ADVERTISEMENT
  • #8 18962625
    khoam
    Level 42  
    Dawidixxx wrote:
    I have a problem when using the server on ESP, occasionally (once every few days) esp crashes and for example the main loop executes in 5-8 seconds (default ~244ms).
    .
    Are you sure that this delay occurs in the loop() directly, and not in WebServerController::webSocketLoop() or WebServerController::handleClientLoop()? It would be useful to investigate this, e.g. measure the time between the input and output of these functions.

    P.S. Yes, I have looked at the code for myself in (fairly) detail ;) .
  • #9 18962667
    krzbor
    Level 27  
    At my place, the SMA "embraced" itself after replacing the router with an AP. Nobody complains at home about WiFi problems either. As for ESP8266 and ESP32, in addition to my own ESP8266-based devices, I also program the ones I bought: SONOFF, Shelly, and I recently ordered a BW-SS3. There's ESP8266 all over the place. You simply don't need more for IOT. The chips work stably - otherwise all these manufacturers would have chosen something else. I recently had a minor problem when connecting to the server. It turned out that, as @SlaweK K. writes, the problem was a bug in the software. The ESP32 is a pretty serious processor, but there are a couple of things that haven't been worked out in it - I don't know why the A/D converter hasn't been done properly, specifically there's no way to supply a reference voltage from outside. I once looked at a graph of how the converter worked - practically at the lower and upper voltages it didn't work. And a good and fast converter is an opening to the remote measurement market. The second thing is the D/A converter - 2 channels. It begs to be used in audio applications, but 8 bits is definitely not enough. They could have at least given 12 as in the A/D converter. As I build circuits on universal boards, the large number of ESP32 pins is more of a disadvantage than an advantage.

    Moderated By dondu:

    Post reported.
    Please focus on the problem of the subject author .

    .
  • #10 18962741
    khoam
    Level 42  
    Colleagues, the first post is about a likely bug in the software, not about ESP32 or SMA inverters. On the other hand, if someone wants to use an ADC in an ESP32, let them calibrate it , or buys the (more expensive) ESP32 from one of the official Espressif distributors version of the ESP32 with calibrated ADC, rather than from ali or local online shopkeepers.

    Dawidixxx wrote:
    Thanks in advance for your help and suggestions and I am open to any reasoned criticism of the code
    .

Topic summary

The discussion revolves around performance issues with the ESP8266 WebServer, specifically delays in the main loop execution and occasional crashes. Users suggest that the problem may stem from various factors, including network connection issues, router limitations, and software bugs. Recommendations include switching to the ESP32 for better multitasking capabilities and stability, as it features dual cores and improved networking. Users also emphasize the importance of investigating specific functions within the code, such as WebServerController::webSocketLoop() and WebServerController::handleClientLoop(), to pinpoint the source of delays. Additionally, experiences with different routers, such as TP-Link and Mikrotik, highlight the impact of infrastructure on device performance.
Summary generated by the language model.
ADVERTISEMENT