the parameters to peform an HTTP request by the HTTP(S)+JSON power meter have been generalized by introducing a new config struct. this is now used for all values which the HTTP(S)+JSON power meter can retrieve, and also used by the HTTP+SML power meter implementation. we anticipate that other feature will use this config as well. generalizing also allows to share serialization and deserialization methods in the configuration handler and the web API handler, leading to de-duplication of code and reduced flash memory usage. a new web UI component is implemented to manage a set of HTTP request settings.
31 lines
918 B
C++
31 lines
918 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <stdint.h>
|
|
#include <Arduino.h>
|
|
#include <HTTPClient.h>
|
|
#include "Configuration.h"
|
|
#include "PowerMeterSml.h"
|
|
|
|
class PowerMeterHttpSml : public PowerMeterSml {
|
|
public:
|
|
~PowerMeterHttpSml();
|
|
|
|
bool init() final { return true; }
|
|
void loop() final;
|
|
bool updateValues();
|
|
char tibberPowerMeterError[256];
|
|
bool query(HttpRequestConfig const& config);
|
|
|
|
private:
|
|
uint32_t _lastPoll = 0;
|
|
|
|
std::unique_ptr<WiFiClient> wifiClient;
|
|
std::unique_ptr<HTTPClient> httpClient;
|
|
String httpResponse;
|
|
bool httpRequest(const String& host, uint16_t port, const String& uri, bool https, HttpRequestConfig const& config);
|
|
bool extractUrlComponents(String url, String& _protocol, String& _hostname, String& _uri, uint16_t& uint16_t, String& _base64Authorization);
|
|
void prepareRequest(uint32_t timeout);
|
|
};
|