electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

Error code 302 with arduino espressif8266 staging version #54

Closed vlad2005 closed 5 years ago

vlad2005 commented 6 years ago

Hi! I use esp8266-12E board with platformio 3.5.1 All work fine. Config file for my project is like this:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
board_f_cpu = 80000000L
build_flags = -Wl,-Teagle.flash.4m1m.ld
upload_speed = 230400

I want switch to staging version of arduino esp8266 so i change line for platform to this:

platform = https://github.com/platformio/platform-espressif8266.git#feature/stage

Everything compile fine, no error, esp boot normally but i got code error 302 (Moved Temporarily). Something is even more strange. In my code i make two request for google script. First request work ok, but second give me error. I have no idea what can be.

This is the important part of the code

if(client->GET(url_checkstatus, host)){
        String res = client->getResponseBody();
        StaticJsonBuffer<200> jsonBuffer;
        JsonObject& root = jsonBuffer.parseObject(res);
        if (root.success()) {
            execute_something();
            if(o){
                delay(1000);
                if(client->GET(url_checkprogram, host)){
                    res = client->getResponseBody();
                    StaticJsonBuffer<200> jsonBuffer;
                    JsonObject& root = jsonBuffer.parseObject(res);
                    if (root.success()) {
                               execute_something();
                    }else{
                        #ifdef DEBUG
                        Serial.println("Json error in function: getProgram");
                        #endif
                    }
                }else{
                    #ifdef DEBUG
                    Serial.println("Error make request for: getProgram" + +client->getReasonPhrase(););
                    #endif
                }
            }
        }else{
            #ifdef DEBUG
            Serial.println("Json error in function: getStatus");
            #endif
        }       
}else{
        #ifdef DEBUG
        Serial.println("Error make request for: getStatus");
        #endif
}
vlad2005 commented 6 years ago

I come back. Is not an real issue. It's seem that staging version for arduino esp8266 is very buggy. Sometime i have error mentioned, sometimes no. Also OTA update sometime work, sometime no. For now I will remain with stable version. It works perfectly.

electronicsguy commented 6 years ago

Hello @vlad2005, thanks for pointing it out. Let me know if you still face difficulties. I recommend using it only with the stable version of the esp8266 library.

enindza commented 6 years ago

Hello @vlad2005

Everything compile fine, no error, esp boot normally but i got code error 302 (Moved Temporarily). Something is even more strange. In my code i make two request for google script. First request work ok, >but second give me error. I have no idea what can be.

I have experienced the same problem after update platform-espressif8266 to stable 1.7.0 with (Arduino Core 2.4.1) Even with such error google sheet is registering the data.

After changing it to stable 1.6.0 with Arduino Core v2.4.0 everything works fine again. No code error 302. (Moved Temporarily).

platform = espressif8266@1.6.0 ; v2.4.0

@vlad2005 could you confirm that platform-espressif8266 stable version 1.7.0 is working OK since that update is released 15 days ago.

vlad2005 commented 6 years ago

I move my code from Google sheets to something more suitable, respectively Google Firestore. But I will try later older code to see if that error occurs.

vlad2005 commented 6 years ago

I can confirm that after update to 1.7.0 i have error: Moved Temporarily, so library is unusable. @enindza - u need to open a new ticket. For me is not important, as i say, i moved my project to firestore cloud api.

electronicsguy commented 6 years ago

@vlad2005 and @enindza Please be specific as to where you are seeing this so-called error. Moved 302 is normal response for Google Docs API, as clearly explained in the Readme. That's what the library is all about. Are you seeing something different from that?

vlad2005 commented 6 years ago

In first call of client->GET(........)

if(client->GET(url_checkstatus, host)){
.........................
}else{
// here capture error code
Serial.println("Error make request for: getStatus");
}

Test code from example for work as expected? I uncomment DEBUG from DebugMacros.h and i get this in console

Status code: 302
Reason phrase: Moved Temporarily

L.E. I can confirm that switching from 1.7.0 to 1.6.0 resolve this problem. So, is something related to new version. Also i have some problems with OTA update. I will stick with 1.6.0 version for moment.

enindza commented 6 years ago

@electronicsguy and @vlad2005 thank you for your quick response and help

As I could see this is not the first issue reported with Arduino Core 2.4.1 (Issue Ram usage - client connect #59).

My code. As I remember. I can't test right now.

  if((WiFi.status() == WL_CONNECTED) and (HTTPSredirectscale == HTTPSredirectscaleMax) and !HTTPSRedirectFirstRunFlag and !WaitingForNTPResponse){
      // Use HTTPSRedirect class to create a new TLS connection
    Serial.println("Enter HTTPSredirect");
    client = new HTTPSRedirect(httpsPort);
    client->setPrintResponseBody(true);
    client->setContentTypeHeader("application/json");

    if (client != nullptr){
      if (!client->connected()){
        Serial.print("connectin client again,---");
        client->connect(host, httpsPort);
        Serial.println("PASSED");
      }
      else{Serial.println("Client already connected, ---");}
      payload = payload_base + "\"" + " ," + DateTime.hour + ESP.getFreeHeap() + "\"}";
      if(client->POST(url2, host, payload)){Serial.println("Client post return TRUE"); config.NTPUpdateStatus = false;}
      else {Serial.println("Client post return FALSE");}
      Serial.print("Status code: "); Serial.println(client->getStatusCode());
      Serial.print("Reason phrase: "); Serial.println(client->getReasonPhrase());
    }
  }

got message:

connectin client again,---PASSED

and during the execution of if(client->POST(url2, host, payload)){Serial.println("Client post return TRUE"); config.NTPUpdateStatus = false;}

after significant delay (like client->POST time out) got console message from code inside library file HTTPSRedirect.cpp

case 302:
...
          // Make a new connection to the re-direction server
            if (!connect(_redirHost.c_str(), _httpsPort)) {
              Serial.println("Connection to re-directed URL failed!");
              return false;
            }

Connection to re-directed URL failed!

And then from the main code

Client post return FALSE Status code: 302 Reason phrase: Moved Temporarily

Interesting thing is that the after reboot the on first call client->POST1 there is no error. But later on such error occurs frequently.

I agree that it could be something with this version platform-espressif8266 1.7.0 with (Arduino Core 2.4.1)

matthuisman commented 6 years ago

I had same issue as above.

connect and post in loop() would work about 5x times with 10 second sleep between. Then just start failing to connect. This is to script.google.com.

switching to espressif8266@1.6.0 fixed it for me.

I'll try get some test code for you :)

Here is test code: https://pastebin.com/dic74iaj

You'll need to put in your SSID and PASSWORD. Replace "ID" in the url with a google app script ID that has a POST method.

You will see it works for 4-5 calls, and then starts failing with "Connection to re-directed URL failed!" or sometimes just fails to connect altogether.

Switching to espressif8266@1.6.0 fixes it