Added webapi to fetch current inverter limit
This commit is contained in:
parent
3e5fb00248
commit
46367c4fa9
@ -6,6 +6,7 @@
|
||||
#include "WebApi_eventlog.h"
|
||||
#include "WebApi_firmware.h"
|
||||
#include "WebApi_inverter.h"
|
||||
#include "WebApi_limit.h"
|
||||
#include "WebApi_mqtt.h"
|
||||
#include "WebApi_network.h"
|
||||
#include "WebApi_ntp.h"
|
||||
@ -29,6 +30,7 @@ private:
|
||||
WebApiEventlogClass _webApiEventlog;
|
||||
WebApiFirmwareClass _webApiFirmware;
|
||||
WebApiInverterClass _webApiInverter;
|
||||
WebApiLimitClass _webApiLimit;
|
||||
WebApiMqttClass _webApiMqtt;
|
||||
WebApiNetworkClass _webApiNetwork;
|
||||
WebApiNtpClass _webApiNtp;
|
||||
|
||||
15
include/WebApi_limit.h
Normal file
15
include/WebApi_limit.h
Normal file
@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
class WebApiLimitClass {
|
||||
public:
|
||||
void init(AsyncWebServer* server);
|
||||
void loop();
|
||||
|
||||
private:
|
||||
void onLimitStatus(AsyncWebServerRequest* request);
|
||||
|
||||
AsyncWebServer* _server;
|
||||
};
|
||||
@ -24,6 +24,7 @@ void WebApiClass::init()
|
||||
_webApiEventlog.init(&_server);
|
||||
_webApiFirmware.init(&_server);
|
||||
_webApiInverter.init(&_server);
|
||||
_webApiLimit.init(&_server);
|
||||
_webApiMqtt.init(&_server);
|
||||
_webApiNetwork.init(&_server);
|
||||
_webApiNtp.init(&_server);
|
||||
@ -41,6 +42,7 @@ void WebApiClass::loop()
|
||||
_webApiEventlog.loop();
|
||||
_webApiFirmware.loop();
|
||||
_webApiInverter.loop();
|
||||
_webApiLimit.loop();
|
||||
_webApiMqtt.loop();
|
||||
_webApiNetwork.loop();
|
||||
_webApiNtp.loop();
|
||||
|
||||
42
src/WebApi_limit.cpp
Normal file
42
src/WebApi_limit.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
*/
|
||||
#include "WebApi_limit.h"
|
||||
#include "ArduinoJson.h"
|
||||
#include "AsyncJson.h"
|
||||
#include "Hoymiles.h"
|
||||
|
||||
void WebApiLimitClass::init(AsyncWebServer* server)
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
|
||||
_server = server;
|
||||
|
||||
_server->on("/api/limit/status", HTTP_GET, std::bind(&WebApiLimitClass::onLimitStatus, this, _1));
|
||||
}
|
||||
|
||||
void WebApiLimitClass::loop()
|
||||
{
|
||||
}
|
||||
|
||||
void WebApiLimitClass::onLimitStatus(AsyncWebServerRequest* request)
|
||||
{
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) {
|
||||
auto inv = Hoymiles.getInverterByPos(i);
|
||||
|
||||
// Inverter Serial is read as HEX
|
||||
char buffer[sizeof(uint64_t) * 8 + 1];
|
||||
sprintf(buffer, "%0lx%08lx",
|
||||
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
|
||||
((uint32_t)(inv->serial() & 0xFFFFFFFF)));
|
||||
|
||||
root[buffer]["limit"] = inv->SystemConfigPara()->getLimitPercent();
|
||||
}
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user