Scenario: Existing project: read soft serial then do http post

New project: MQTT player from other (MrDIY / MrDIY Audio Notifier · GitLab)

Objective: Combine together (Result: successful )

Issue: When read serial do http post, after http.end(). MQTT client disconnect. It taks above 10 secs to reconnect.

The only way I found is just a workaround to add ESP.restart(); after each http post.

But that's stupid. I have spend more than 10 hours to fix this issue. Any one can help?

Eg code:

void loop() {
  if (!mqttClient.connected()) {

  if (mySerial.available() > 0)  //Checks is there any data in buffer
    receive_data = String(receive_data) + String(char(mySerial.read()));

    if (String(receive_data).indexOf("lighton") >= 0) {
      receive_data = "";
      http.begin(client, switchon);
      http.addHeader("Content-Type", "application/json");
      http.addHeader("Authorization", auth);
      int httpCode = http.POST("{\"entity_id\": \"switch.sonoff_guest_room\"}");
      Serial.printf("[http] GET... code: %d\n", httpCode);
  • Please add URL to things you refers to!
    – MatsK
    Oct 22, 2021 at 12:20
  • Did you ever figure this out? I'm struggling with the same problem myself now, I also can only make one initial http request, all subsequent requests fails with status -5...
    – jishi
    Dec 18, 2021 at 16:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.