forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateFirmware.cpp
More file actions
53 lines (42 loc) · 1.72 KB
/
Copy pathUpdateFirmware.cpp
File metadata and controls
53 lines (42 loc) · 1.72 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
48
49
50
51
52
53
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2021
// MIT License
#include <ArduinoOcpp/MessagesV16/UpdateFirmware.h>
#include <ArduinoOcpp/Core/OcppEngine.h>
using ArduinoOcpp::Ocpp16::UpdateFirmware;
UpdateFirmware::UpdateFirmware() {
}
void UpdateFirmware::processReq(JsonObject payload) {
/*
* Process the application data here. Note: you have to implement the FW update procedure in your client code. You have to set
* a onSendConfListener in which you initiate a FW update (e.g. calling ESPhttpUpdate.update(...) )
*/
const char *loc = payload["location"] | "";
location = String(loc);
//check location URL. Maybe introduce Same-Origin-Policy?
if (location.isEmpty()) {
formatError = true;
Serial.println(F("[UpdateFirmware] Could not read location. Abort"));
return;
}
//check the integrity of retrieveDate
const char *retrieveDateRaw = payload["retrieveDate"] | "Invalid";
if (!retreiveDate.setTime(retrieveDateRaw)) {
formatError = true;
Serial.println(F("[UpdateFirmware] Could not read retrieveDate. Abort"));
return;
}
retries = payload["retries"] | 1;
retryInterval = payload["retryInterval"] | 180;
}
DynamicJsonDocument* UpdateFirmware::createConf(){
DynamicJsonDocument* doc = new DynamicJsonDocument(0);
doc->to<JsonObject>();
FirmwareService *fwService = getFirmwareService();
if (fwService != NULL) {
fwService->scheduleFirmwareUpdate(location, retreiveDate, retries, retryInterval);
} else {
Serial.println(F("[UpdateFirmware] FirmwareService has not been initialized before! Please have a look at ArduinoOcpp.cpp for an example. Abort"));
}
return doc;
}