OpenDTU-old/include/PowerMeterHttpSml.h
Bernhard Kirchen 2397e5cdf5 powermeter refactor: split providers into their own classes
it is important to separate the capabilities of each power meter
provider into their own class/source file, as the providers work
fundamentally different and their implementations must not be
intermangled, which made maintenance and improvements a nightmare
in the past.
2024-06-26 20:51:54 +02:00

47 lines
1.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <list>
#include <mutex>
#include <stdint.h>
#include <Arduino.h>
#include <HTTPClient.h>
#include "Configuration.h"
#include "PowerMeterProvider.h"
#include "sml.h"
class PowerMeterHttpSml : public PowerMeterProvider {
public:
bool init() final { return true; }
void deinit() final { }
void loop() final;
float getPowerTotal() const final;
void doMqttPublish() const final;
bool updateValues();
char tibberPowerMeterError[256];
bool query(PowerMeterTibberConfig const& config);
private:
mutable std::mutex _mutex;
uint32_t _lastPoll = 0;
float _activePower = 0.0;
typedef struct {
const unsigned char OBIS[6];
void (*Fn)(double&);
float* Arg;
} OBISHandler;
const std::list<OBISHandler> smlHandlerList{
{{0x01, 0x00, 0x10, 0x07, 0x00, 0xff}, &smlOBISW, &_activePower}
};
HTTPClient httpClient;
String httpResponse;
bool httpRequest(WiFiClient &wifiClient, const String& host, uint16_t port, const String& uri, bool https, PowerMeterTibberConfig const& config);
bool extractUrlComponents(String url, String& _protocol, String& _hostname, String& _uri, uint16_t& uint16_t, String& _base64Authorization);
void prepareRequest(uint32_t timeout);
};