arduino-esp8266fs-plugin
arduino-esp8266fs-plugin copied to clipboard
Error on password protected OTA
Hi, if OTA is password protected, the plugin fails to upload files.
edit: sorry , i just read the #4.
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.