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
52 lines (42 loc) · 1.71 KB
/
Copy pathUpdateFirmware.cpp
File metadata and controls
52 lines (42 loc) · 1.71 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2022
// MIT License
#include <ArduinoOcpp/MessagesV16/UpdateFirmware.h>
#include <ArduinoOcpp/Core/OcppModel.h>
#include <ArduinoOcpp/Tasks/FirmwareManagement/FirmwareService.h>
#include <ArduinoOcpp/Debug.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 = loc;
//check location URL. Maybe introduce Same-Origin-Policy?
if (location.empty()) {
formatError = true;
AO_DBG_WARN("Could not read location. Abort");
return;
}
//check the integrity of retrieveDate
const char *retrieveDateRaw = payload["retrieveDate"] | "Invalid";
if (!retreiveDate.setTime(retrieveDateRaw)) {
formatError = true;
AO_DBG_WARN("Could not read retrieveDate. Abort");
return;
}
retries = payload["retries"] | 1;
retryInterval = payload["retryInterval"] | 180;
}
std::unique_ptr<DynamicJsonDocument> UpdateFirmware::createConf(){
if (ocppModel && ocppModel->getFirmwareService()) {
auto fwService = ocppModel->getFirmwareService();
fwService->scheduleFirmwareUpdate(location, retreiveDate, retries, retryInterval);
} else {
AO_DBG_ERR("FirmwareService has not been initialized before! Please have a look at ArduinoOcpp.cpp for an example. Abort");
}
return createEmptyDocument();
}