Modify helpers for publishing to accept a std::string
This commit is contained in:
34
src/main.cpp
34
src/main.cpp
@@ -1,5 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include <EspMQTTClient.h>
|
||||
#include <EspMqttClient.h>
|
||||
#include <arduino-timer.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <RFPowerView.h>
|
||||
@@ -74,9 +74,9 @@ bool sendPacket(Packet *packet);
|
||||
bool checkPosition(uint16_t shadeID);
|
||||
void startFetchingPosition(uint16_t shadeID, int8_t targetPosition);
|
||||
|
||||
void publishPosition(const String& shadeName, const uint8_t position);
|
||||
void publishState(const String& shadeName, const String& state);
|
||||
void publishBattery(const String& shadeName, const uint8_t battery);
|
||||
void publishPosition(const std::string& shadeKey, const uint8_t position);
|
||||
void publishState(const std::string& shadeKey, const String& state);
|
||||
void publishBattery(const std::string& shadeKey, const uint8_t battery);
|
||||
|
||||
void publishDiscoveryTopics();
|
||||
|
||||
@@ -168,7 +168,7 @@ void processPacket(const Packet *packet) {
|
||||
}
|
||||
shade->lastPosition = position;
|
||||
|
||||
publishPosition(shade->key.c_str(), position);
|
||||
publishPosition(shade->key, position);
|
||||
}
|
||||
} else if (field.identifier == 0x42) {
|
||||
auto shade = shadeRepository.findById(source);
|
||||
@@ -176,7 +176,7 @@ void processPacket(const Packet *packet) {
|
||||
uint8_t value = std::get<uint8_t>(field.value);
|
||||
uint8_t battery = uint8_t(((float)value / 200) * 100);
|
||||
|
||||
publishBattery(shade->key.c_str(), battery);
|
||||
publishBattery(shade->key, battery);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,13 +304,13 @@ void processCommandMessage(const String &topic, const String &payload) {
|
||||
|
||||
startFetchingPosition(shade->ID, 100);
|
||||
|
||||
publishState(shade->key.c_str(), "opening");
|
||||
publishState(shade->key, "opening");
|
||||
} else if (payload == "CLOSE") {
|
||||
sendClosePacket(shade->ID);
|
||||
|
||||
startFetchingPosition(shade->ID, 0);
|
||||
|
||||
publishState(shade->key.c_str(), "closing");
|
||||
publishState(shade->key, "closing");
|
||||
} else if (payload == "STOP") {
|
||||
sendStopPacket(shade->ID);
|
||||
|
||||
@@ -333,9 +333,9 @@ void processSetPositionMessage(const String& topic, const String &payload) {
|
||||
sendSetPosition(shade->ID, percentage);
|
||||
|
||||
if (payload.toInt() > shade->lastPosition) {
|
||||
publishState(shade->key.c_str(), "opening");
|
||||
publishState(shade->key, "opening");
|
||||
} else if (payload.toInt() < shade->lastPosition) {
|
||||
publishState(shade->key.c_str(), "closing");
|
||||
publishState(shade->key, "closing");
|
||||
}
|
||||
|
||||
startFetchingPosition(shade->ID, payload.toInt());
|
||||
@@ -358,7 +358,7 @@ bool checkPosition(uint16_t shadeID) {
|
||||
}
|
||||
}
|
||||
|
||||
publishState(shade->key.c_str(), shade->lastPosition > 0 ? "open" : "closed");
|
||||
publishState(shade->key, shade->lastPosition > 0 ? "open" : "closed");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -381,16 +381,16 @@ void startFetchingPosition(uint16_t shadeID, int8_t targetPosition) {
|
||||
}
|
||||
}
|
||||
|
||||
void publishState(const String& shadeName, const String& state) {
|
||||
client.publish(topic_prefix.c_str() + shadeName + "/state", state, true);
|
||||
void publishState(const std::string& shadeKey, const String& state) {
|
||||
client.publish((topic_prefix + shadeKey + "/state").c_str(), state, true);
|
||||
}
|
||||
|
||||
void publishPosition(const String& shadeName, const uint8_t position) {
|
||||
client.publish(topic_prefix.c_str() + shadeName + "/position", String(position), true);
|
||||
void publishPosition(const std::string& shadeKey, const uint8_t position) {
|
||||
client.publish((topic_prefix + shadeKey + "/position").c_str(), String(position), true);
|
||||
}
|
||||
|
||||
void publishBattery(const String& shadeName, const uint8_t battery) {
|
||||
client.publish(topic_prefix.c_str() + shadeName + "/battery", String(battery), true);
|
||||
void publishBattery(const std::string& shadeKey, const uint8_t battery) {
|
||||
client.publish((topic_prefix + shadeKey + "/battery").c_str(), String(battery), true);
|
||||
}
|
||||
|
||||
void publishDiscoveryTopics() {
|
||||
|
||||
Reference in New Issue
Block a user