* DPL MQTT handler: modernize * there is no need to tokenize and check the topic of a received MQTT message if we only subscribe to a single topic. all messages will be for that topic. avoid testing the topic in the callback alltogether. * use std::string and std::stoi over allocating and deleting a buffer and copying charactes around. * use a switch statement to process the actual payload. * break a long line. * DPL: fix getMode() return value getMode() returned a bool. probably its return type was not adjusted when the third mode was introduced. this lead to mode 2 being cast to true implicitly, which in turn was used to construct a String, such that "1" was published as the DPL mode when in fact it was 2. make the mode an enum class to avoid such problems in the future. inline getMode() and setMode(). fix indention.
20 lines
504 B
C++
20 lines
504 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include "Configuration.h"
|
|
#include <espMqttClient.h>
|
|
|
|
class MqttHandlePowerLimiterClass {
|
|
public:
|
|
void init();
|
|
void loop();
|
|
|
|
private:
|
|
void onCmdMode(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
|
|
|
uint32_t _lastPublishStats;
|
|
uint32_t _lastPublish;
|
|
|
|
};
|
|
|
|
extern MqttHandlePowerLimiterClass MqttHandlePowerLimiter; |