Skip to content

Inconsistent Post Requests #3264

Closed
Closed
@KyleHunter

Description

@KyleHunter

Basic Infos

Hardware

Hardware: ESP-12
Core Version: Latest NodeMCU

Description

So this issue has been infuriating to me for the last several weeks.. It is related to my prior issue: #3182

I had incorrectly assumed that it was fixed when it wasn't. So I am sending post requests to dweetpro.io every 15 seconds. I have the most inconsistent results with it. I have tried everything, from having a local WiFiClient instance, to a global one, that only connects at the start of the sketch. When I do WiFiClient.println(); sometimes it will go super fast, submit the post, return a response in less than half a second. Other times it will take seconds for each println(), but still get a valid post. Other times it will take 5+ seconds on each println() and won't submit a valid post..

But what is so frustrating, is that it will work for hours/days only failing on a few here and there, and then it will fail completely until a restart, but many times restarting it doesn't immediately solve it either. I've tried printing the current signal strength, and it's in the same room as the router so it is always -50dB or better.

Everything with the website, dweetpro is fine. Because when the esp is failing, I am able to manually make post requests from other sources and they work perfectly.

I've tried with a generic esp-12, nodemcu, same issues. I really don't know what else to try, as it is just bizarre how inconsistent this board is.

Settings in IDE

Module: ESP-12
Flash Size: 4MB
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: SERIAL
Reset Method: ?ck / nodemcu?

Sketch

  bool send_post_to_server(WiFiClient client, String content, int content_length)
  {
    Serial.println(client.connected()); //always prints 1
    Serial.println("Here2.2"); // For debugging
    client.println("POST /v2/dweets HTTP/1.1");
    Serial.println("Here2.21"); // For debugging
    client.println("Host: dweetpro.io");
    Serial.println("Here2.22"); // For debugging
    client.println("X-DWEET-AUTH: xxx");
    Serial.println("Here2.23"); // For debugging
    client.println("Accept: application/json");
    Serial.println("Here2.24"); // For debugging
    client.println("Content-Type: application/json");
    Serial.println("Here2.25"); // For debugging
    client.print("Content-Length: ");
    Serial.println("Here2.36"); // For debugging
    client.println(content_length);
    client.println();
    Serial.println("Here2.4"); // For debugging
    client.print(content);
    Serial.println("Here2.5"); // For debugging
  }

  void send_to_server(String* time_sent, String status,
    bool, float* data, int data_size, WiFiClient client)
  {
    Serial.println("Here2"); // For debugging
    int content_length;
    String content = make_json_content(&content_length, status, data, data_size);
    Serial.println("Here2.1"); // For debugging
    send_post_to_server(client, content, content_length);
    Serial.println("Here3"); // For debugging
    delay(10);
    int timer = millis();
    while (client.available() == 0)
    {
      delay(10);
      if (millis() - timer > 3000)
      {
        Serial.println("2"); // When it fails, it is here. I have increased time to 10000, no difference
        return;
      }
    }

      Serial.println("Here4"); // For debugging
      String json = "";
      bool http_body = 0;

      led::turn_green_led(0);
      while(client.available())
      {
        String line = client.readStringUntil('\r');
        if (!http_body && line.charAt(1) == '{')
          http_body = 1;
        if (http_body)
          json += line;
      }

      Serial.println("Response: ");
      Serial.println(json);
  }

// In main loop I use:

  if (!client.connected())
  {
    client.stop();
    client.connect(IPAddress(54, 236, 198, 240), 80);
  }
//I have tried local instances, and global where I connect/disconnect each request.
//This way I have now seems slightly(?) more reliable

Other thoughts I've had are maybe interference from electronics/router..? I'm out of ideas, as I have tried literally everything.

I have a 2Amp usb power supply, tried multiple different ones as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions