【发布时间】:2021-05-24 21:06:27
【问题描述】:
我想用我系统的mac地址作为主题名。
我想要类似:project/00:1B:44:11:3A:B7/temperature/status
我是这样尝试的:
#define TEMP_STATUS_TOPIC "project/" + WiFi.macAddress() + "temperature/status"
#define TEMP_CONTROL_TOPIC "project/temperature/control"
但我收到此错误:
no matching function for call to 'MQTTClient::publish(StringSumHelper&, char [128], size_t&)'
任何提示都会得到极大的赞赏!
编辑:
我正在使用 mqtt.fx 客户端。
这里是我所说的发布:
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);
}
【问题讨论】:
-
Edit 包含minimal reproducible example 的问题。你在哪里打电话
publish?你在哪里/如何使用你的宏? -
感谢您的回答!我已经用更多代码编辑了我的问题,希望对您有所帮助:)
-
publish在类MQTTClient中的声明是什么? -
我认为是发布(java.lang.String topic, byte[] payload, int qos, boolean reserved)
-
编辑问题以说明您使用的是哪个 MQTT 客户端。
标签: c++ mqtt arduino-ide arduino-esp8266