MacAddress for topic name – Arduino IDE MQTT

  arduino-esp8266, arduino-ide, c++, mqtt

I want to use the mac address of my system as a topic name.

I want something like : project/00:1B:44:11:3A:B7/temperature/status

I tried in this way:

#define TEMP_STATUS_TOPIC "project/" + WiFi.macAddress() + "temperature/status"   
#define TEMP_CONTROL_TOPIC "project/temperature/control"

But I get this error:

no matching function for call to 'MQTTClient::publish(StringSumHelper&, char [128], size_t&)'

Any tip will be greatly appriciated!

EDIT:

Here is where I call publish:

sensors.requestTemperatures(); 
  float t = sensors.getTempCByIndex(0);
  bool static led_temp_status = HIGH;
  
  const int capacity = JSON_OBJECT_SIZE(3);
  StaticJsonDocument<capacity> poolsystem;
  
  if (t < destemp) {
    led_temp_status = LOW;
    digitalWrite(LED_EXTERNAL_TEMP, led_temp_status);
    const int capacity = JSON_OBJECT_SIZE(3);
StaticJsonDocument<capacity> poolsystem;

    poolsystem["temp"] = t;
    poolsystem["heatstatus"] = "on";
    char buffer[128];
    size_t n = serializeJson(poolsystem, buffer);
    Serial.print(F("JSON message: "));
    Serial.println(buffer);
    mqttClient.publish(TEMP_STATUS_TOPIC, buffer, n);   
  } else {
    led_temp_status = HIGH;
    digitalWrite(LED_EXTERNAL_TEMP, led_temp_status);

    poolsystem["temp"] = t;
    poolsystem["heatstatus"] = "off";
    char buffer[128];
    size_t n = serializeJson(poolsystem, buffer);
    Serial.print(F("JSON message: "));
    Serial.println(buffer);
    mqttClient.publish(TEMP_STATUS_TOPIC, buffer, n); 
  }

Source: Windows Questions C++

LEAVE A COMMENT