we used this library solely to interpret the answer of an HTTP web server as JSON and find a particular value using a path expression in the HTTP power meter implementation. since we ran out of flash memory on non-S3 ESP32, we need to cut some corners. removing FirebaseJson is the last low-hanging fruit that we currently know of. we can get rid of it by using ArduinoJson (which is already integral part of the firmware) and implementing a custom logic to extract a value based on a path expression. other than the FirebaseJson path "finder", the new implementation only knows how to access sub-keys delimited by a forward slash. in particular, accessing array members is not supported any more. I am hoping that this is simply not an issue. if so, we will have users complaining and we can add this functionality in a later release.
35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <Arduino.h>
|
|
#include <HTTPClient.h>
|
|
#include "Configuration.h"
|
|
|
|
using Auth_t = PowerMeterHttpConfig::Auth;
|
|
using Unit_t = PowerMeterHttpConfig::Unit;
|
|
|
|
class HttpPowerMeterClass {
|
|
public:
|
|
void init();
|
|
bool updateValues();
|
|
float getPower(int8_t phase);
|
|
char httpPowerMeterError[256];
|
|
bool queryPhase(int phase, PowerMeterHttpConfig const& config);
|
|
|
|
private:
|
|
float power[POWERMETER_MAX_PHASES];
|
|
HTTPClient httpClient;
|
|
String httpResponse;
|
|
bool httpRequest(int phase, WiFiClient &wifiClient, const String& host, uint16_t port, const String& uri, bool https, PowerMeterHttpConfig const& config);
|
|
bool extractUrlComponents(String url, String& _protocol, String& _hostname, String& _uri, uint16_t& uint16_t, String& _base64Authorization);
|
|
String extractParam(String& authReq, const String& param, const char delimit);
|
|
String getcNonce(const int len);
|
|
String getDigestAuth(String& authReq, const String& username, const String& password, const String& method, const String& uri, unsigned int counter);
|
|
bool tryGetFloatValueForPhase(int phase, String jsonPath, Unit_t unit, bool signInverted);
|
|
void prepareRequest(uint32_t timeout, const char* httpHeader, const char* httpValue);
|
|
String sha256(const String& data);
|
|
};
|
|
|
|
extern HttpPowerMeterClass HttpPowerMeter;
|