-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceUpdateService.cpp
More file actions
47 lines (38 loc) · 1.66 KB
/
DeviceUpdateService.cpp
File metadata and controls
47 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <DeviceUpdateService.h>
DeviceUpdateService::DeviceUpdateService(WiFiClient &client, String updateServerUrl, int port,
String currentDeviceVersion) {
this->client = client;
this->updateServerUrl = updateServerUrl;
this->port = port;
this->currentDeviceVersion = currentDeviceVersion;
}
void DeviceUpdateService::setup() {
ESPhttpUpdate.onStart(DeviceUpdateService::updateStarted);
ESPhttpUpdate.onEnd(DeviceUpdateService::updateFinished);
ESPhttpUpdate.onProgress(DeviceUpdateService::updateProgress);
ESPhttpUpdate.onError(DeviceUpdateService::updateError);
}
void DeviceUpdateService::installUpdateIfPossible() {
t_httpUpdate_return returnCode =
ESPhttpUpdate.update(client, updateServerUrl, port, (String) "", currentDeviceVersion);
switch (returnCode) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(),
ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("HTTP_UPDATE_OK");
break;
}
}
void DeviceUpdateService::updateStarted() { Serial.println("CALLBACK: HTTP update process started"); }
void DeviceUpdateService::updateFinished() { Serial.println("CALLBACK: HTTP update process finished"); }
void DeviceUpdateService::updateError(int errorCode) {
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", errorCode);
}
void DeviceUpdateService::updateProgress(int current, int total) {
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", current, total);
}