homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Wrong MQTT topic used when advertising $unit #737

Closed estepper closed 1 year ago

estepper commented 1 year ago

Hi,

I'm new to Homie, but so far I find it awesome. Thanks for it!

That said, now I have a weird problem. Consider the following class:

class Max6675Sensor : public HomieNode
{
public:
  Max6675Sensor(uint8_t sclk, uint8_t cs, uint8_t miso, const char *id, const char *name, const char *type)
      : HomieNode(id, name, type), sensor(sclk, cs, miso) {}

protected:
  virtual void setup() override;
  virtual void loop() override;

private:
  MAX6675 sensor;
  // ...
};

In the .cpp file I have this:

void Max6675Sensor::setup()
{
  advertise("temperature").setName("Temperature").setDatatype("integer").setUnit("degrees");
}

void Max6675Sensor::loop()
{
}

So I would expect my MQTT Explorer to show a single property "temperature" on that node. But it shows this:

image

Why does Homie create a property "pe" just for the "$unit" attribute? Could that be a bug in Homie?

FWIW, I have this in my platformio.ini:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_port = COM7
monitor_speed = 115200
lib_deps = 
    git+https://github.com/homieiot/homie-esp8266.git#develop
    adafruit/MAX6675 library@^1.1.0
build_flags = -D_BSD_SOURCE

It appears that VSCode checked out commit e0347c08231592672c16c07356127a8f5d539c26 (Nov 25th).

estepper commented 1 year ago

Sorry, this is all my fault! I should have advertised the property before setup(), so that, when the topic buffer is generated in BootNormal.cpp:55, my property is considered at all.