Skip to content

OTA runtime password set has no effect. #8803

Closed
@zekageri

Description

@zekageri

Board

ESP32-Wrover

Device Description

no

Hardware Configuration

no

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Windows10

Flash frequency

80

PSRAM enabled

yes

Upload speed

115200

Description

I want to be able to dinamically change OTA password every day, but it has no effect.

Sketch

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "..........";
const char* password = "..........";
boolean shouldResetPassword = true;
long startMS = 0;

void setup() {
  Serial.begin(115200);

  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  ArduinoOTA.setPassword("admin");

  ArduinoOTA
    .onStart([]() {
      String type;
      if (ArduinoOTA.getCommand() == U_FLASH)
        type = "sketch";
      else // U_SPIFFS
        type = "filesystem";

      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
      Serial.println("Start updating " + type);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });

  ArduinoOTA.begin();

  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void setNewOTA_Password(){
    ArduinoOTA.setPassword("admin1");
    Serial.println("OTA new password set");
    shouldResetPassword = false;
}

void loop() {
  ArduinoOTA.handle();
  if( !shouldResetPassword ){ return; }
  if( millis() - startMS >= 10000 ){
      setNewOTA_Password();
  } 
}

Debug Message

No debug message, the new password is not set. And you can upload a new sketch with the old password.

Other Steps to Reproduce

If i reinitialise OTA, my esp crashes.

void setNewOTA_Password(){
ArduinoOTA.end();
vTaskDelay(100); // Doesn't matter.

ArduinoOTA.setPassword("admin1");

Serial.println("OTA new password set");
shouldResetPassword = false;

ArduinoOTA.begin(); // Crash
}

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions