diff --git a/.travis.yml b/.travis.yml index ad9c6b8..d18a946 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ jdk: script: - export SRC=$PWD - cd $HOME - - export TAG=1.6.6 + - export TAG=1.6.12 - wget https://github.com/arduino/Arduino/archive/$TAG.zip - unzip $TAG.zip - rm $TAG.zip diff --git a/README.md b/README.md index 7b158c1..16f49b6 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,11 @@ Tested with the following Arduino IDE versions: 1.6.5-r2, ## Installation - Make sure you use one of the supported versions of Arduino IDE and have ESP8266 core installed. - Download the tool archive from [releases page](https://github.com/esp8266/arduino-esp8266fs-plugin/releases/latest). -- In your Arduino sketchbook directory, create tools directory if it doesn't exist yet. -- Unpack the tool into tools directory (the path will look like `/Arduino/tools/ESP8266FS/tool/esp8266fs.jar)`. -- Restart Arduino IDE. +- In your Arduino sketchbook directory, create `tools` directory if it doesn't exist yet. You can find the location of your sketchbook directory in the Arduino IDE at **File > Preferences > Sketchbook location**. +- Unpack the tool into `tools` directory (the path will look like `/tools/ESP8266FS/tool/esp8266fs.jar)`. +- Restart Arduino IDE. + +On OS X and Linux based OSs create the tools directory in ~/Documents/Arduino/ and unpack the files there ## Usage - Open a sketch (or create a new one and save it). diff --git a/make.sh b/make.sh index 9a7702e..6d76779 100755 --- a/make.sh +++ b/make.sh @@ -19,7 +19,7 @@ echo "lib_path: $lib_path" set -e mkdir -p bin -javac -target 1.8 -cp "$pde_path:$core_path:$lib_path" \ +javac -target 11 -cp "$pde_path:$core_path:$lib_path" \ -d bin src/ESP8266FS.java pushd bin diff --git a/src/ESP8266FS.java b/src/ESP8266FS.java index 9b38017..81b55ef 100644 --- a/src/ESP8266FS.java +++ b/src/ESP8266FS.java @@ -40,7 +40,6 @@ import processing.app.BaseNoGui; import processing.app.Platform; import processing.app.Sketch; -import processing.app.SketchData; import processing.app.tools.Tool; import processing.app.helpers.ProcessUtils; import processing.app.debug.TargetPlatform; @@ -77,6 +76,11 @@ public void run() { while ((c = reader.read()) != -1) System.out.print((char) c); reader.close(); + + reader = new InputStreamReader(p.getErrorStream()); + while ((c = reader.read()) != -1) + System.err.print((char) c); + reader.close(); } catch (Exception e){} } }; @@ -107,36 +111,45 @@ public void run() { } private String getBuildFolderPath(Sketch s) { + // first of all try the getBuildPath() function introduced with IDE 1.6.12 + // see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03 try { - File buildFolder = FileUtils.createTempFolder("build", DigestUtils.md5Hex(s.getMainFilePath()) + ".spiffs"); - DeleteFilesOnShutdown.add(buildFolder); - return buildFolder.getAbsolutePath(); + String buildpath = s.getBuildPath().getAbsolutePath(); + return buildpath; } - catch (IOException e) { - editor.statusError(e); + catch (IOException er) { + editor.statusError(er); } - catch (NoSuchMethodError e) { - // Arduino 1.6.5 doesn't have FileUtils.createTempFolder - // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath(); - java.lang.reflect.Method method; + catch (Exception er) { try { - method = BaseNoGui.class.getMethod("getBuildFolder"); - File f = (File) method.invoke(null); - return f.getAbsolutePath(); - } catch (SecurityException ex) { - editor.statusError(ex); - } catch (IllegalAccessException ex) { - editor.statusError(ex); - } catch (InvocationTargetException ex) { - editor.statusError(ex); - } catch (NoSuchMethodException ex) { - editor.statusError(ex); + File buildFolder = FileUtils.createTempFolder("build", DigestUtils.md5Hex(s.getMainFilePath()) + ".tmp"); + return buildFolder.getAbsolutePath(); + } + catch (IOException e) { + editor.statusError(e); + } + catch (Exception e) { + // Arduino 1.6.5 doesn't have FileUtils.createTempFolder + // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath(); + java.lang.reflect.Method method; + try { + method = BaseNoGui.class.getMethod("getBuildFolder"); + File f = (File) method.invoke(null); + return f.getAbsolutePath(); + } catch (SecurityException ex) { + editor.statusError(ex); + } catch (IllegalAccessException ex) { + editor.statusError(ex); + } catch (InvocationTargetException ex) { + editor.statusError(ex); + } catch (NoSuchMethodException ex) { + editor.statusError(ex); + } } } return ""; } - private long getIntPref(String name){ String data = BaseNoGui.getBoardPreferences().get(name); if(data == null || data.contentEquals("")) return 0; @@ -170,21 +183,8 @@ private void createAndUpload(){ } TargetPlatform platform = BaseNoGui.getTargetPlatform(); - - String esptoolCmd = platform.getTool("esptool").get("cmd"); - File esptool; - esptool = new File(platform.getFolder()+"/tools", esptoolCmd); - if(!esptool.exists() || !esptool.isFile()){ - esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd); - if(!esptool.exists()){ - esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd); - if (!esptool.exists()) { - System.err.println(); - editor.statusError("SPIFFS Error: esptool not found!"); - return; - } - } - } + + //Make sure mkspiffs binary exists String mkspiffsCmd; if(PreferencesData.get("runtime.os").contentEquals("windows")) mkspiffsCmd = "mkspiffs.exe"; @@ -203,7 +203,64 @@ private void createAndUpload(){ } } } + + Boolean isNetwork = false; + File espota = new File(platform.getFolder()+"/tools"); + File esptool = new File(platform.getFolder()+"/tools"); + String serialPort = PreferencesData.get("serial.port"); + String pythonCmd = PreferencesData.get("runtime.os").contentEquals("windows") ? "python3.exe" : "python3"; + String uploadCmd = ""; + + //make sure the serial port or IP is defined + if (serialPort == null || serialPort.isEmpty()) { + System.err.println(); + editor.statusError("SPIFFS Error: serial port not defined!"); + return; + } + // Find upload.py, don't fail if not present for backwards compat + File uploadPyFile = new File(platform.getFolder()+"/tools", "upload.py"); + if (uploadPyFile.exists() && uploadPyFile.isFile()) { + uploadCmd = uploadPyFile.getAbsolutePath(); + } + // Find python.exe if present, don't fail if not found for backwards compat + String[] paths = { platform.getFolder()+"/tools", platform.getFolder()+"/tools/python3", PreferencesData.get("runtime.tools.python3.path") }; + for (String s: paths) { + File toolPyFile = new File(s, pythonCmd); + if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) { + pythonCmd = toolPyFile.getAbsolutePath(); + break; + } + } + // pythonCmd now points to either an installed exe with full path or just plain "python3(.exe)" + + //find espota if IP else find esptool + if(serialPort.split("\\.").length == 4){ + isNetwork = true; + String espotaCmd = "espota.py"; + espota = new File(platform.getFolder()+"/tools", espotaCmd); + if(!espota.exists() || !espota.isFile()){ + System.err.println(); + editor.statusError("SPIFFS Error: espota not found!"); + return; + } + } else { + String esptoolCmd = platform.getTool("esptool").get("cmd"); + esptool = new File(platform.getFolder()+"/tools", esptoolCmd); + if(!esptool.exists() || !esptool.isFile()){ + esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd); + if(!esptool.exists()){ + esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd); + if (!esptool.exists() && uploadCmd.isEmpty()) { + System.err.println(); + editor.statusError("SPIFFS Error: esptool not found!"); + return; + } + } + } + } + + //load a list of all files int fileCount = 0; File dataFolder = new File(editor.getSketch().getFolder(), "data"); if (!dataFolder.exists()) { @@ -213,21 +270,21 @@ private void createAndUpload(){ File[] files = dataFolder.listFiles(); if(files.length > 0){ for(File file : files){ - if(!file.isDirectory() && file.isFile() && !file.getName().startsWith(".")) fileCount++; + if((file.isDirectory() || file.isFile()) && !file.getName().startsWith(".")) fileCount++; } } } String dataPath = dataFolder.getAbsolutePath(); String toolPath = tool.getAbsolutePath(); - String esptoolPath = esptool.getAbsolutePath(); String sketchName = editor.getSketch().getName(); String imagePath = getBuildFolderPath(editor.getSketch()) + "/" + sketchName + ".spiffs.bin"; - String serialPort = PreferencesData.get("serial.port"); String resetMethod = BaseNoGui.getBoardPreferences().get("upload.resetmethod"); String uploadSpeed = BaseNoGui.getBoardPreferences().get("upload.speed"); String uploadAddress = BaseNoGui.getBoardPreferences().get("build.spiffs_start"); + + Object[] options = { "Yes", "No" }; String title = "SPIFFS Create"; String message = "No files have been found in your data folder!\nAre you sure you want to create an empty SPIFFS image?"; @@ -239,10 +296,10 @@ private void createAndUpload(){ } editor.statusNotice("SPIFFS Creating Image..."); - System.out.println("[SPIFFS] data : "+dataPath); - System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024)); - System.out.println("[SPIFFS] page : "+spiPage); - System.out.println("[SPIFFS] block : "+spiBlock); + System.out.println("[SPIFFS] data : "+dataPath); + System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024)); + System.out.println("[SPIFFS] page : "+spiPage); + System.out.println("[SPIFFS] block : "+spiBlock); try { if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-p", spiPage+"", "-b", spiBlock+"", "-s", (spiEnd - spiStart)+"", imagePath}) != 0){ @@ -257,14 +314,28 @@ private void createAndUpload(){ } editor.statusNotice("SPIFFS Uploading Image..."); - System.out.println("[SPIFFS] upload : "+imagePath); - System.out.println("[SPIFFS] reset : "+resetMethod); - System.out.println("[SPIFFS] port : "+serialPort); - System.out.println("[SPIFFS] speed : "+uploadSpeed); - System.out.println("[SPIFFS] address: "+uploadAddress); - System.out.println(); - - sysExec(new String[]{esptoolPath, "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath}); + System.out.println("[SPIFFS] upload : "+imagePath); + + if(isNetwork){ + System.out.println("[SPIFFS] IP : "+serialPort); + System.out.println(); + sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath}); + } else { + System.out.println("[SPIFFS] address : "+uploadAddress); + System.out.println("[SPIFFS] reset : "+resetMethod); + System.out.println("[SPIFFS] port : "+serialPort); + System.out.println("[SPIFFS] speed : "+uploadSpeed); + if (!uploadCmd.isEmpty()) { + System.out.println("[SPIFFS] python : "+pythonCmd); + System.out.println("[SPIFFS] uploader : "+uploadCmd); + } + System.out.println(); + if (!uploadCmd.isEmpty()) { + sysExec(new String[]{pythonCmd, uploadCmd, "--chip", "esp8266", "--port", serialPort, "--baud", uploadSpeed, "write_flash", uploadAddress, imagePath}); + } else { + sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath}); + } + } } public void run() {