Skip to content

Commit 68fd738

Browse files
author
Me No Dev
committedJan 12, 2016
add support for folders and esp31b
1 parent a8e541f commit 68fd738

File tree

1 file changed

+69
-26
lines changed

1 file changed

+69
-26
lines changed
 

‎src/ESP8266FS.java

+69-26
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public void run() {
7777
while ((c = reader.read()) != -1)
7878
System.out.print((char) c);
7979
reader.close();
80+
81+
reader = new InputStreamReader(p.getErrorStream());
Has conversations. Original line has conversations.
82+
while ((c = reader.read()) != -1)
83+
System.err.print((char) c);
84+
reader.close();
8085
} catch (Exception e){}
8186
}
8287
};
@@ -145,7 +150,7 @@ private long getIntPref(String name){
145150
}
146151

147152
private void createAndUpload(){
148-
if(!PreferencesData.get("target_platform").contentEquals("esp8266")){
153+
if(!PreferencesData.get("target_platform").contentEquals("esp8266") && !PreferencesData.get("target_platform").contentEquals("esp31b") && !PreferencesData.get("target_platform").contentEquals("ESP31B")){
Has conversations. Original line has conversations.
149154
System.err.println();
150155
editor.statusError("SPIFFS Not Supported on "+PreferencesData.get("target_platform"));
151156
return;
@@ -170,21 +175,8 @@ private void createAndUpload(){
170175
}
171176

172177
TargetPlatform platform = BaseNoGui.getTargetPlatform();
173-
174-
String esptoolCmd = platform.getTool("esptool").get("cmd");
175-
File esptool;
176-
esptool = new File(platform.getFolder()+"/tools", esptoolCmd);
177-
if(!esptool.exists() || !esptool.isFile()){
178-
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
179-
if(!esptool.exists()){
180-
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
181-
if (!esptool.exists()) {
182-
System.err.println();
183-
editor.statusError("SPIFFS Error: esptool not found!");
184-
return;
185-
}
186-
}
187-
}
178+
179+
//Make sure mkspiffs binary exists
188180
String mkspiffsCmd;
189181
if(PreferencesData.get("runtime.os").contentEquals("windows"))
190182
mkspiffsCmd = "mkspiffs.exe";
Has a conversation. Original line has a conversation.
@@ -203,7 +195,46 @@ private void createAndUpload(){
203195
}
204196
}
205197
}
198+
199+
Boolean isNetwork = false;
200+
File espota = new File(platform.getFolder()+"/tools");
201+
File esptool = new File(platform.getFolder()+"/tools");
202+
String serialPort = PreferencesData.get("serial.port");
203+
204+
//make sure the serial port or IP is defined
205+
if (serialPort == null || serialPort.isEmpty()) {
206+
System.err.println();
207+
editor.statusError("SPIFFS Error: serial port not defined!");
208+
return;
209+
}
206210

211+
//find espota if IP else find esptool
212+
if(serialPort.split("\\.").length == 4){
213+
isNetwork = true;
214+
String espotaCmd = "espota.py";
215+
espota = new File(platform.getFolder()+"/tools", espotaCmd);
216+
if(!espota.exists() || !espota.isFile()){
217+
System.err.println();
218+
editor.statusError("SPIFFS Error: espota not found!");
219+
return;
220+
}
221+
} else {
222+
String esptoolCmd = platform.getTool("esptool").get("cmd");
223+
esptool = new File(platform.getFolder()+"/tools", esptoolCmd);
224+
if(!esptool.exists() || !esptool.isFile()){
225+
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
226+
if(!esptool.exists()){
227+
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
228+
if (!esptool.exists()) {
229+
System.err.println();
230+
editor.statusError("SPIFFS Error: esptool not found!");
231+
return;
232+
}
233+
}
234+
}
235+
}
236+
237+
//load a list of all files
207238
int fileCount = 0;
208239
File dataFolder = new File(editor.getSketch().getFolder(), "data");
209240
if (!dataFolder.exists()) {
@@ -213,21 +244,21 @@ private void createAndUpload(){
213244
File[] files = dataFolder.listFiles();
214245
if(files.length > 0){
215246
for(File file : files){
216-
if(!file.isDirectory() && file.isFile() && !file.getName().startsWith(".")) fileCount++;
247+
if((file.isDirectory() || file.isFile()) && !file.getName().startsWith(".")) fileCount++;
217248
}
218249
}
219250
}
220251

221252
String dataPath = dataFolder.getAbsolutePath();
222253
String toolPath = tool.getAbsolutePath();
223-
String esptoolPath = esptool.getAbsolutePath();
224254
String sketchName = editor.getSketch().getName();
225255
String imagePath = getBuildFolderPath(editor.getSketch()) + "/" + sketchName + ".spiffs.bin";
226-
String serialPort = PreferencesData.get("serial.port");
227256
String resetMethod = BaseNoGui.getBoardPreferences().get("upload.resetmethod");
228257
String uploadSpeed = BaseNoGui.getBoardPreferences().get("upload.speed");
229258
String uploadAddress = BaseNoGui.getBoardPreferences().get("build.spiffs_start");
230259

260+
261+
231262
Object[] options = { "Yes", "No" };
232263
String title = "SPIFFS Create";
233264
String message = "No files have been found in your data folder!\nAre you sure you want to create an empty SPIFFS image?";
@@ -258,13 +289,25 @@ private void createAndUpload(){
258289

259290
editor.statusNotice("SPIFFS Uploading Image...");
260291
System.out.println("[SPIFFS] upload : "+imagePath);
261-
System.out.println("[SPIFFS] reset : "+resetMethod);
262-
System.out.println("[SPIFFS] port : "+serialPort);
263-
System.out.println("[SPIFFS] speed : "+uploadSpeed);
264-
System.out.println("[SPIFFS] address: "+uploadAddress);
265-
System.out.println();
266-
267-
sysExec(new String[]{esptoolPath, "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
292+
293+
if(isNetwork){
294+
String pythonCmd;
295+
if(PreferencesData.get("runtime.os").contentEquals("windows"))
Has a conversation. Original line has a conversation.
296+
pythonCmd = "python.exe";
297+
else
298+
pythonCmd = "python";
299+
300+
System.out.println("[SPIFFS] IP : "+serialPort);
301+
System.out.println();
302+
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath});
303+
} else {
304+
System.out.println("[SPIFFS] address: "+uploadAddress);
305+
System.out.println("[SPIFFS] reset : "+resetMethod);
306+
System.out.println("[SPIFFS] port : "+serialPort);
307+
System.out.println("[SPIFFS] speed : "+uploadSpeed);
308+
System.out.println();
309+
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
310+
}
268311
}
269312

270313
public void run() {

2 commit comments

Comments
 (2)

me-no-dev commented on Jan 12, 2016

@me-no-dev
Collaborator

was like that, left it like that. do not put much thought in what is there already if it works. This was not an optimization job, but rather an opportunity-for-new bugs and new feature job ;)
if you look closely the mkspiffsCmd was just relocated and the python was a copy/paste

andig commented on Jan 12, 2016

@andig

I know- same solution here...

Please sign in to comment.