Browse Source

add ArduinoOTA to ESP32 builds. although neither it nor the old SimpleUpdater work on the Heltec Lora32 devices. TODO.

Thomas Buck 2 months ago
parent
commit
2efc8917a9
5 changed files with 62 additions and 6 deletions
  1. 6
    5
      include/SimpleUpdater.h
  2. 3
    0
      platformio.ini
  3. 43
    0
      src/SimpleUpdater.cpp
  4. 8
    0
      src/main.cpp
  5. 2
    1
      src/servers.cpp

+ 6
- 5
include/SimpleUpdater.h View File

29
 public:
29
 public:
30
     SimpleUpdater(String _uri = String("/update"));
30
     SimpleUpdater(String _uri = String("/update"));
31
     void setup(UPDATE_WEB_SERVER *_server);
31
     void setup(UPDATE_WEB_SERVER *_server);
32
-    
32
+    void run(void);
33
+
33
 private:
34
 private:
34
 
35
 
35
 #if defined(ARDUINO_ARCH_ESP8266)
36
 #if defined(ARDUINO_ARCH_ESP8266)
36
-    
37
+
37
     ESP8266HTTPUpdateServer updateServer;
38
     ESP8266HTTPUpdateServer updateServer;
38
 
39
 
39
 #elif defined(ARDUINO_ARCH_ESP32)
40
 #elif defined(ARDUINO_ARCH_ESP32)
40
-    
41
+
41
     void get(void);
42
     void get(void);
42
     void postResult(void);
43
     void postResult(void);
43
     void postUpload(void);
44
     void postUpload(void);
44
-    
45
+
45
 #endif
46
 #endif
46
-    
47
+
47
     String uri;
48
     String uri;
48
     UPDATE_WEB_SERVER *server;
49
     UPDATE_WEB_SERVER *server;
49
 };
50
 };

+ 3
- 0
platformio.ini View File

67
 framework = arduino
67
 framework = arduino
68
 upload_protocol = esptool
68
 upload_protocol = esptool
69
 upload_port = /dev/ttyUSB2
69
 upload_port = /dev/ttyUSB2
70
+# TODO neither web ota nor arduino ota work on heltec esp32?!
71
+#upload_protocol = espota
72
+#upload_port = lora-testing
70
 monitor_port = /dev/ttyUSB2
73
 monitor_port = /dev/ttyUSB2
71
 monitor_speed = 115200
74
 monitor_speed = 115200
72
 extra_scripts = pre:extra_script.py
75
 extra_scripts = pre:extra_script.py

+ 43
- 0
src/SimpleUpdater.cpp View File

15
 #include <ESP8266HTTPUpdateServer.h>
15
 #include <ESP8266HTTPUpdateServer.h>
16
 #elif defined(ARDUINO_ARCH_ESP32)
16
 #elif defined(ARDUINO_ARCH_ESP32)
17
 #include <Update.h>
17
 #include <Update.h>
18
+#include <ArduinoOTA.h>
18
 #endif
19
 #endif
19
 
20
 
20
 #include "config.h"
21
 #include "config.h"
148
         get();
149
         get();
149
     });
150
     });
150
 
151
 
152
+    ArduinoOTA.setMdnsEnabled(false);
153
+
154
+    ArduinoOTA.onStart([]() {
155
+        String type;
156
+        if (ArduinoOTA.getCommand() == U_FLASH) {
157
+            type = "sketch";
158
+        } else {  // U_SPIFFS
159
+            type = "filesystem";
160
+        }
161
+
162
+        // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
163
+        Serial.println("Start updating " + type);
164
+    })
165
+    .onEnd([]() {
166
+        Serial.println("\nEnd");
167
+    })
168
+    .onProgress([](unsigned int progress, unsigned int total) {
169
+        Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
170
+    })
171
+    .onError([](ota_error_t error) {
172
+        Serial.printf("Error[%u]: ", error);
173
+        if (error == OTA_AUTH_ERROR) {
174
+            Serial.println("Auth Failed");
175
+        } else if (error == OTA_BEGIN_ERROR) {
176
+            Serial.println("Begin Failed");
177
+        } else if (error == OTA_CONNECT_ERROR) {
178
+            Serial.println("Connect Failed");
179
+        } else if (error == OTA_RECEIVE_ERROR) {
180
+            Serial.println("Receive Failed");
181
+        } else if (error == OTA_END_ERROR) {
182
+            Serial.println("End Failed");
183
+        }
184
+    });
185
+
186
+    ArduinoOTA.begin();
187
+
151
 #endif
188
 #endif
152
 }
189
 }
153
 
190
 
156
     server = NULL;
193
     server = NULL;
157
 }
194
 }
158
 
195
 
196
+void SimpleUpdater::run(void) {
197
+#ifdef ARDUINO_ARCH_ESP32
198
+    ArduinoOTA.handle();
199
+#endif
200
+}
201
+
159
 #endif
202
 #endif

+ 8
- 0
src/main.cpp View File

133
 #endif // FEATURE_UI
133
 #endif // FEATURE_UI
134
     }
134
     }
135
     debug.println(F("\nWiFi connected!"));
135
     debug.println(F("\nWiFi connected!"));
136
+
137
+    debug.printf("IP: %s\n", WiFi.localIP().toString().c_str());
138
+    debug.printf("Hostname: %s\n", hostname.c_str());
139
+
136
 #ifdef FEATURE_UI
140
 #ifdef FEATURE_UI
137
     ui_progress(UI_WIFI_CONNECTED);
141
     ui_progress(UI_WIFI_CONNECTED);
138
 #endif // FEATURE_UI
142
 #endif // FEATURE_UI
183
 #endif // FEATURE_UI
187
 #endif // FEATURE_UI
184
     }
188
     }
185
     debug.println(F("\nWiFi connected!"));
189
     debug.println(F("\nWiFi connected!"));
190
+
191
+    debug.printf("IP: %s\n", WiFi.localIP().toString().c_str());
192
+    debug.printf("Hostname: %s\n", hostname.c_str());
193
+
186
 #ifdef FEATURE_UI
194
 #ifdef FEATURE_UI
187
     ui_progress(UI_WIFI_CONNECTED);
195
     ui_progress(UI_WIFI_CONNECTED);
188
 #endif // FEATURE_UI
196
 #endif // FEATURE_UI

+ 2
- 1
src/servers.cpp View File

207
 static void handleServers() {
207
 static void handleServers() {
208
 #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
208
 #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
209
     server.handleClient();
209
     server.handleClient();
210
+    updater.run();
210
 #else
211
 #else
211
     http_server();
212
     http_server();
212
 #endif
213
 #endif
213
-    
214
+
214
 #if defined(ARDUINO_ARCH_ESP8266)
215
 #if defined(ARDUINO_ARCH_ESP8266)
215
     MDNS.update();
216
     MDNS.update();
216
 #endif
217
 #endif

Loading…
Cancel
Save