Skip to content

Commit 22a37ea

Browse files
committed
Merge pull request #4107 from me-no-dev/esp8266-ota
Enable OTA Update mechanism for any mDNS enabled platform

2 parents ef25a2b + 2b75aec commit 22a37ea

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

arduino-core/src/cc/arduino/packages/UploaderFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import cc.arduino.packages.uploaders.SSHUploader;
3333
import cc.arduino.packages.uploaders.SerialUploader;
34+
import cc.arduino.packages.uploaders.GenericNetworkUploader;
3435
import processing.app.debug.TargetBoard;
3536

3637
public class UploaderFactory {
@@ -41,6 +42,9 @@ public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadP
4142
}
4243

4344
if (port != null && "network".equals(port.getProtocol())) {
45+
if(port.getPrefs().get("ssh_upload").contentEquals("no")){
46+
return new GenericNetworkUploader(port);
47+
}
4448
return new SSHUploader(port);
4549
}
4650

arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

+15
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ public void serviceResolved(ServiceEvent serviceEvent) {
144144
port.getPrefs().put("board", board);
145145
port.getPrefs().put("distro_version", info.getPropertyString("distro_version"));
146146
port.getPrefs().put("port", "" + info.getPort());
147+
148+
//Add additional fields to permit generic ota updates
149+
//and make sure we do not intefere with Arduino boards
150+
// define "ssh_upload=no" TXT property to use generic uploader
151+
// define "tcp_check=no" TXT property if you are not using TCP
152+
// define "auth_upload=yes" TXT property if you want to use authenticated generic upload
153+
String useSSH = info.getPropertyString("ssh_upload");
154+
String checkTCP = info.getPropertyString("tcp_check");
155+
String useAuth = info.getPropertyString("auth_upload");
156+
if(useSSH == null || !useSSH.contentEquals("no")) useSSH = "yes";
157+
if(checkTCP == null || !checkTCP.contentEquals("no")) checkTCP = "yes";
158+
if(useAuth == null || !useAuth.contentEquals("yes")) useAuth = "no";
159+
port.getPrefs().put("ssh_upload", useSSH);
160+
port.getPrefs().put("tcp_check", checkTCP);
161+
port.getPrefs().put("auth_upload", useAuth);
147162
}
148163

149164
String label = name + " at " + address;

arduino-core/src/cc/arduino/packages/discoverers/network/BoardReachabilityFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void run() {
6969
ports.add(0, 22);
7070
}
7171

72-
boolean reachable = NetUtils.isReachable(inetAddress, ports);
72+
boolean reachable = board.getPrefs().get("tcp_check").contentEquals("no") || NetUtils.isReachable(inetAddress, ports);
7373
if (!reachable) {
7474
boardPortIterator.remove();
7575
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
GenericNetworkUploader - generic network uploader implementation
3+
makes possible to implement firmware updates over the air on any device
4+
Part of the Arduino project - http://www.arduino.cc/
5+
6+
Copyright (c) 2004-05
7+
Hernando Barragan
8+
Copyright (c) 2012
9+
Cristian Maglie <[email protected]>
10+
Copyright (c) 2015
11+
Hristo Gochkov <[email protected]>
12+
13+
This program is free software; you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation; either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
This program is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with this program; if not, write to the Free Software Foundation,
25+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26+
*/
27+
28+
package cc.arduino.packages.uploaders;
29+
30+
import cc.arduino.packages.BoardPort;
31+
import cc.arduino.packages.Uploader;
32+
import processing.app.*;
33+
import processing.app.debug.RunnerException;
34+
import processing.app.debug.TargetPlatform;
35+
import processing.app.helpers.PreferencesMap;
36+
import processing.app.helpers.StringReplacer;
37+
38+
import java.io.File;
39+
import java.util.List;
40+
41+
import static processing.app.I18n.tr;
42+
43+
public class GenericNetworkUploader extends Uploader {
44+
45+
private final BoardPort port;
46+
47+
public GenericNetworkUploader(BoardPort port) {
48+
this.port = port;
49+
}
50+
51+
public boolean requiresAuthorization() {
52+
return this.port.getPrefs().get("auth_upload").contentEquals("yes");
53+
}
54+
55+
@Override
56+
public String getAuthorizationKey() {
57+
return "runtime.pwd." + this.port.getAddress();
58+
}
59+
60+
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
61+
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
62+
PreferencesMap prefs = PreferencesData.getMap();
63+
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
64+
if (boardPreferences != null) {
65+
prefs.putAll(boardPreferences);
66+
}
67+
String tool = prefs.getOrExcept("upload.tool");
68+
if (tool.contains(":")) {
69+
String[] split = tool.split(":", 2);
70+
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
71+
tool = split[1];
72+
}
73+
prefs.putAll(targetPlatform.getTool(tool));
74+
75+
String password = "";
76+
if(requiresAuthorization()){
77+
password = prefs.getOrExcept(getAuthorizationKey());
78+
}
79+
prefs.put("network.password", password);
80+
81+
prefs.put("network.port", this.port.getPrefs().get("port"));
82+
83+
prefs.put("build.path", buildPath);
84+
prefs.put("build.project_name", className);
85+
if (verbose) {
86+
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
87+
} else {
88+
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
89+
}
90+
91+
boolean uploadResult;
92+
try {
93+
String pattern;
94+
//check if there is a separate pattern for network uploads
95+
pattern = prefs.get("upload.network_pattern");
96+
if(pattern == null)
97+
pattern = prefs.getOrExcept("upload.pattern");
98+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
99+
uploadResult = executeUploadCommand(cmd);
100+
} catch (RunnerException e) {
101+
throw e;
102+
} catch (Exception e) {
103+
throw new RunnerException(e);
104+
}
105+
return uploadResult;
106+
}
107+
108+
@Override
109+
public boolean burnBootloader() throws RunnerException {
110+
throw new RunnerException("Burning bootloader is not supported via network!");
111+
}
112+
}

0 commit comments

Comments
 (0)