Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By mr rishu
#87805 I'm trying to update nodemcu from a password protected server. i can login from the nodemcu through basic http authentication (getting http code 200) but when trying to update the firmware its showing

HTTP_UPDATE_FAILD Error (-104): Wrong HTTP CODE

i'm using the code mentioned below

Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "base64.h"
#include <ESP8266httpUpdate.h>
 
const char* ssid = "ssid";
const char* password =  "pass";
 
String authUsername = "username";
String authPassword = "password";
 
void setup() {
 
  Serial.begin(115200);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to WiFi");
 
}
 
void loop() {
 
  if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
 
    HTTPClient http;
    http.begin("server");
 
    String auth = base64::encode(authUsername + ":" + authPassword);
    http.addHeader("Authorization", "Basic " + auth);
    //http.setAuthorization("auth");
    int httpCode = http.GET();
 
    if (httpCode > 0) { //Check for the returning code
 
        String payload = http.getString();
        Serial.println(httpCode);
        Serial.println(payload);
    }
 
    else {
      Serial.println("Error on HTTP request");
    }
    if (httpCode == 200)
    {
      t_httpUpdate_return ret = ESPhttpUpdate.update("server/file.bin");
       switch (ret)
   {
      case HTTP_UPDATE_FAILED:
      Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
      break;

      case HTTP_UPDATE_NO_UPDATES:
      Serial.println("HTTP_UPDATE_NO_UPDATES");
      break;

      case HTTP_UPDATE_OK:
      Serial.println("HTTP_UPDATE_OK");
      break;
   }
    }
    http.end();
 
  }
  delay(10000);
 
}


i'm new to this coding community, any help from the experts would appreciated.