Przeglądaj źródła

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

Thomas Buck 4 miesięcy temu
rodzic
commit
2efc8917a9
5 zmienionych plików z 62 dodań i 6 usunięć
  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 Wyświetl plik

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

+ 3
- 0
platformio.ini Wyświetl plik

@@ -67,6 +67,9 @@ board = heltec_wifi_lora_32_V3
67 67
 framework = arduino
68 68
 upload_protocol = esptool
69 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 73
 monitor_port = /dev/ttyUSB2
71 74
 monitor_speed = 115200
72 75
 extra_scripts = pre:extra_script.py

+ 43
- 0
src/SimpleUpdater.cpp Wyświetl plik

@@ -15,6 +15,7 @@
15 15
 #include <ESP8266HTTPUpdateServer.h>
16 16
 #elif defined(ARDUINO_ARCH_ESP32)
17 17
 #include <Update.h>
18
+#include <ArduinoOTA.h>
18 19
 #endif
19 20
 
20 21
 #include "config.h"
@@ -148,6 +149,42 @@ void SimpleUpdater::setup(UPDATE_WEB_SERVER *_server) {
148 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 188
 #endif
152 189
 }
153 190
 
@@ -156,4 +193,10 @@ SimpleUpdater::SimpleUpdater(String _uri) {
156 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 202
 #endif

+ 8
- 0
src/main.cpp Wyświetl plik

@@ -133,6 +133,10 @@ void setup() {
133 133
 #endif // FEATURE_UI
134 134
     }
135 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 140
 #ifdef FEATURE_UI
137 141
     ui_progress(UI_WIFI_CONNECTED);
138 142
 #endif // FEATURE_UI
@@ -183,6 +187,10 @@ void setup() {
183 187
 #endif // FEATURE_UI
184 188
     }
185 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 194
 #ifdef FEATURE_UI
187 195
     ui_progress(UI_WIFI_CONNECTED);
188 196
 #endif // FEATURE_UI

+ 2
- 1
src/servers.cpp Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz