Skip to content

ArduinoOTA interferes with hardware serial #3881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
djdehaan opened this issue Nov 26, 2017 · 13 comments
Closed

ArduinoOTA interferes with hardware serial #3881

djdehaan opened this issue Nov 26, 2017 · 13 comments

Comments

@djdehaan
Copy link

Hi all,

Not a question, but a tip for others who struggle. I use a Wemos D1 with a GPS receiver and SD-card. And I did not get the ArduinoOTA function to work. IT started uploading but after 10 or 12 or 8 bullets appearing in the IDE it stopped uploading. After long searching I found the reason.

Earlier, I found it most stable if I address that GPS using hardware serial, meaning I connect it on the RX/TX pins. Appearantly, that interferes with the upload process. When I add the following code in the Setup() routine, the upload works like a charm:

  ArduinoOTA.onStart([]() {
    Serial.end();
  });
  ArduinoOTA.setHostname("CarTrax");
  ArduinoOTA.begin();

Maybe this is completely logic, but it took me some time to find out and I did not find similar cases online.

@lrmoreno007
Copy link
Contributor

WOW I try it and now it work like a charm. Before it failed 50% of the time or more.

Now this is my setupOTA function:

void setupOTA() {
  ArduinoOTA.setHostname(hostOTA);

  //ArduinoOTA.setPort(8266);

  // No authentication by default
  //ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
    Serial.println("Comienzo OTA");
    Serial.end();
  });
  ArduinoOTA.onEnd([]() {
    Serial.begin(115200);
    Serial.println("\nOTA Finalizado con exito");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    //Serial.printf("Subido: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError(
      [](ota_error_t error) {
        Serial.begin(115200);
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) Serial.println("Fallo de autentificacion");
        else if (error == OTA_BEGIN_ERROR) Serial.println("Fallo al continuar");
        else if (error == OTA_CONNECT_ERROR) Serial.println("Fallo de conexion");
        else if (error == OTA_RECEIVE_ERROR) Serial.println("Fallo de recepcion");
        else if (error == OTA_END_ERROR) Serial.println("Fallo final");
      });
  ArduinoOTA.begin();
}

@igrr
Copy link
Member

igrr commented Dec 27, 2017

Possible duplicate of #2576 #3869.

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 1, 2018

Could you please try again with latest git and without onStart's Serial.end() ?

@lrmoreno007
Copy link
Contributor

For me with latest git today and hand fixing #4086 (index problem and int<-> char warning), it work fine without Serial.end(). Tested many times successfully.

Regards

@devyte
Copy link
Collaborator

devyte commented Jan 4, 2018

Ok, relevant PRs are merged. Please retest.

@lrmoreno007
Copy link
Contributor

Working OK for me, uploading sketch and SPIFFS image.

Only sometimes it remains as "Uploading" and after a while the message "An error occurred while sending the sketch" appears, but I remember that this was a problem of the Arduino IDE. However, the sketch has been sent correctly if we look at the serial output.

Tested with Arduino IDE 1.8.3 and 1.8.5.

@devyte
Copy link
Collaborator

devyte commented Jan 5, 2018

@djdehaan will you be testing this as well?

@djdehaan
Copy link
Author

djdehaan commented Jan 5, 2018

@devyte I will, I hope to find time this weekend.

@djdehaan
Copy link
Author

djdehaan commented Jan 6, 2018

@devyte I have a test-setup, however, I do not know how to download your upgraded lib. I did in GitGui a Remote / FetchFrom / Origin, that does update something but not ArduinoOTA. When running a test (with serial.end removed) it goes wrong again. To be expected with the old libs. How do I get your new libs?

@devyte
Copy link
Collaborator

devyte commented Jan 6, 2018

@djdehaan I'm not sure about gitgui, I didn't even know it existed. I use git from (linux) command line.
The repo has to be clones with git into a specific directory for the arduino build system to pick it up. Also, the core installed via board manager has to be uninstalled, both can't coexist.
Instructions for git install are on readthedocs.

@djdehaan
Copy link
Author

djdehaan commented Jan 6, 2018

@devyte Indeed, ESP8266 is not installed via board manager. But following the (Windows) instructions:

git clone https://github.com/esp8266/Arduino.git esp8266
cd esp8266/tools
python get.py
Restart Arduino

So I deleted the entire directory and reinstalled ESP8266. It will not do OTA without Serial.end();
If I disable Serial.end() this is the result:
image
If I enable Serial.end() the bullets keep coming until uploading is finished.

//OTA
ArduinoOTA.onStart( {
//Serial.end();
});
ArduinoOTA.setHostname("CarTrax");
ArduinoOTA.begin();

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 10, 2018

Does this bug happen too with the example Files/Examples/ArduinoOTA/BasicOTA,
or only with your sketch ?

@earlephilhower
Copy link
Collaborator

There is no working MCVE, and there were some big changes to the uart infrastructure and OTA (including re-enabling interrupts while flash is being written which allows serial comms even during the long flash ops you'd see in OTA, and uart logic corrected to not write out of bounds in overflow conditions) in 2.5.0. Please try the latest 2.5.0 release and open a new issue w/MCVE if there is still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants