Browse Source

sns: broken mqtt address publishing

cannot declare constexpr objects like that with old compiler
fix #2594
dev
Maxim Prokhorov 6 months ago
parent
commit
480c72dc07
3 changed files with 25 additions and 23 deletions
  1. +5
    -1
      code/espurna/config/sensors.h
  2. +19
    -22
      code/espurna/sensor.cpp
  3. +1
    -0
      code/test/build/nondefault.h

+ 5
- 1
code/espurna/config/sensors.h View File

@ -57,9 +57,13 @@
// Warning: this might wear out flash fast!
#endif
#ifndef SENSOR_PUBLISH_ADDRESSES
#define SENSOR_PUBLISH_ADDRESSES 0 // Publish sensor addresses
#define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
#endif
#ifndef SENSOR_ADDRESS_TOPIC
#define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
#endif
// -----------------------------------------------------------------------------
// Magnitude offset correction


+ 19
- 22
code/espurna/sensor.cpp View File

@ -1833,27 +1833,6 @@ void report(const Value& report) {
for (auto& handler : internal::report_handlers) {
handler(report);
}
#if MQTT_SUPPORT
{
mqttSend(report.topic.c_str(), report.repr.c_str());
#if SENSOR_PUBLISH_ADDRESSES
{
static constexpr auto AddressTopic = STRING_VIEW(SENSOR_ADDRESS_TOPIC);
String address_topic;
address_topic.reserve(report.topic.length() + AddressTopic.length());
address_topic.concat(AddressTopic.c_str(), AddressTopic.length());
address_topic += '/';
address_topic += report.topic;
mqttSend(address_topic.c_str(), magnitude.sensor->address(magnitude.slot).c_str());
}
#endif // SENSOR_PUBLISH_ADDRESSES
}
#endif // MQTT_SUPPORT
}
Info info(const Magnitude& magnitude) {
@ -3652,6 +3631,22 @@ void setup() {
namespace mqtt {
namespace {
void report(const Value& report, const Magnitude& magnitude) {
mqttSend(report.topic.c_str(), report.repr.c_str());
#if SENSOR_PUBLISH_ADDRESSES
STRING_VIEW_INLINE(AddressTopic, SENSOR_ADDRESS_TOPIC);
String address_topic;
address_topic.reserve(1 + report.topic.length() + AddressTopic.length());
address_topic.concat(AddressTopic.data(), AddressTopic.length());
address_topic += '/';
address_topic += report.topic;
mqttSend(address_topic.c_str(), magnitude.sensor->address(magnitude.slot).c_str());
#endif
}
void callback(unsigned int type, StringView topic, StringView payload) {
if (!magnitude::count(MAGNITUDE_ENERGY)) {
return;
@ -4031,10 +4026,12 @@ void loop() {
const auto report = magnitude::value(magnitude, value.filtered);
magnitude::report(report);
#if MQTT_SUPPORT
mqtt::report(report, magnitude);
#endif
#if THINGSPEAK_SUPPORT
tspkEnqueueMagnitude(index, report.repr);
#endif
#if DOMOTICZ_SUPPORT
domoticzSendMagnitude(index, report);
#endif


+ 1
- 0
code/test/build/nondefault.h View File

@ -1,4 +1,5 @@
#define SENSOR_SUPPORT 1
#define SENSOR_PUBLISH_ADDRESSES 1
#define INFLUXDB_SUPPORT 1
#define KINGART_CURTAIN_SUPPORT 1
#define LLMNR_SUPPORT 1


Loading…
Cancel
Save