ct-Open-Source / Basecamp

An Arduino library to ease the use of the ESP32 in IoT projects
GNU General Public License v3.0
253 stars 48 forks source link

Unstable OTA #52

Open Fuempel opened 6 years ago

Fuempel commented 6 years ago

When using Basecamp 0.1.8 with PlatformIO / Atom, the OTA feature works very easily. However it is not stable and not successful in a high number of attempts.

I guess, main reason for this is the excessive delay in Basecamp.cpp:

void Basecamp::OTAHandling(void * OTAParams) {

    ...

    // The while loop checks if OTA requests are received and sleeps for a bit if not
    while (1) {
      ArduinoOTA.handle();
      vTaskDelay(100);
    }
}

The original value of 100 ms is way too high for the UDP based transmission, for high speed connections. Changing the value to 5 solved the problem for me for the moment.

But I am not sure on the side effects (runtime consumption) and if 5 ms is sufficiently low. Can you please check ?

Fuempel commented 6 years ago

After some additional investigation, I guess the above mentioned delay is not the real root cause. Still it remains unstable. Also the parameter to vTaskDelay is not in ms, but in ticks.

But: I suspect the real root cause is that the ArduinoOTA library is not designed to run in a separate task in core 0, in parallel to the Arduino infrastucture.

I did a prototype, where the creatin of an additional task via xTaskCreatePinnedToCore(&OTAHandling, "ArduinoOTATask", ...) is avoided.

I have implemented a member function Basecamp::handle, called from main.cpp loop() function which then calls ArduinoOTA.handle(); Then ArduinoOTA runs on core 1 together with other Arduino infrastracture.

With this, I have a stabel setup of OTA functionality.

Fuempel commented 6 years ago

see PR #53