forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebApi_devinfo.cpp
41 lines (35 loc) · 1.42 KB
/
WebApi_devinfo.cpp
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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022-2024 Thomas Basler and others
*/
#include "WebApi_devinfo.h"
#include "WebApi.h"
#include <AsyncJson.h>
#include <Hoymiles.h>
#include <ctime>
void WebApiDevInfoClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
using std::placeholders::_1;
server.on("/api/devinfo/status", HTTP_GET, std::bind(&WebApiDevInfoClass::onDevInfoStatus, this, _1));
}
void WebApiDevInfoClass::onDevInfoStatus(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}
AsyncJsonResponse* response = new AsyncJsonResponse();
auto& root = response->getRoot();
auto serial = WebApi.parseSerialFromRequest(request);
auto inv = Hoymiles.getInverterBySerial(serial);
if (inv != nullptr) {
root["valid_data"] = inv->DevInfo()->getLastUpdate() > 0;
root["fw_bootloader_version"] = inv->DevInfo()->getFwBootloaderVersion();
root["fw_build_version"] = inv->DevInfo()->getFwBuildVersion();
root["hw_part_number"] = inv->DevInfo()->getHwPartNumber();
root["hw_version"] = inv->DevInfo()->getHwVersion();
root["hw_model_name"] = inv->DevInfo()->getHwModelName();
root["max_power"] = inv->DevInfo()->getMaxPower();
root["fw_build_datetime"] = inv->DevInfo()->getFwBuildDateTimeStr();
}
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}