Skip to content

Error on password protected OTA #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pockemul opened this issue Jan 24, 2017 · 1 comment
Open

Error on password protected OTA #27

pockemul opened this issue Jan 24, 2017 · 1 comment

Comments

@pockemul
Copy link

pockemul commented Jan 24, 2017

Hi,
if OTA is password protected, the plugin fails to upload files.

edit: sorry , i just read the #4.

@attakorns
Copy link

attakorns commented Jul 22, 2019

Hmm guys..not sure if an update to the Arduino IDE allowed this but I managed to get the password from the IDE using this:
PreferencesData.getMap().get(uploader.getAuthorizationKey());
or if you want an exception when no password data is present:
PreferencesData.getMap().getOrExcept(uploader.getAuthorizationKey());

.getMap(), .get() and .getOrExcept() is imported by:
import processing.app.helpers.PreferencesMap;
.getOrExcept() also requires import processing.app.helpers.PreferencesMapException; too I think although I have not tried this.

uploader is declared as:

UploaderUtils uploaderInstance = new UploaderUtils();
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);

and requires import of:

import cc.arduino.UploaderUtils;
import cc.arduino.packages.Uploader;

To check whether a password is required for OTA upload:
if(uploader.requiresAuthorization())

I also managed to get the password dialogue prompt to appear in the same fashion as Upload Sketch does too:

if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
  PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(editor, tr("Type board password to upload a new sketch"));
  dialog.setLocationRelativeTo(editor);
  dialog.setVisible(true);

  if (dialog.isCancelled()) {
    editor.statusNotice(tr("Upload cancelled"));
    return;
  }

  PreferencesData.set(uploader.getAuthorizationKey(), dialog.getPassword());
} 

This require these extra imports:

import processing.app.forms.PasswordAuthorizationDialog;
import static processing.app.I18n.tr;

So if you do
String password = prefs.get(uploader.getAuthorizationKey());
you could then run espota using:
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-a", password, "-s", "-f", imagePath});

I got these lines from the Arduino source files: GenericNetworkUploader.java and SketchController.java. I'm a total noob at Java and how Arduino IDE coding works so if this appears like a hack then it is! I'm dropping this here so someone who knows more can properly add this feature to ESP8266FS. Hope it's helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants