[英]Arduino MQTT publish to topic issues
I am trying to get my ESP8266 to publish to a topic with its mac address as a sub to differentiate between many devices, However when I create a Topic string with the mac in it the client.publish(Topic, String) breaks... I am getting this error我试图让我的 ESP8266 发布到一个主题,它的 mac 地址作为一个 sub 来区分许多设备,但是当我创建一个带有 mac 的主题字符串时,client.publish(Topic, String) 中断了......我收到此错误
error: no matching function for call to 'PubSubClient::publish(<unresolved overloaded function type>, const char*)'
if (client.publish(Topic.c_str, msg.c_str())){
^
void loop() {
val = ( 100.00 - ( (analogRead(analogPin)/1023.00) * 100.00 ) ); // read the input pin
// Serial.println(val);
client.loop();
//client.publish("esp/test" val);
String mac = WiFi.macAddress();
String Topic = String("esp/test/moisture/" + mac);
String msg = String("{Moisture:") + String(val) + String(", mac:") + String(mac) + String("}");
if (client.publish(Topic.c_str, msg.c_str())){
Serial.println("Message Sent!");
// Serial.println(msg);
Serial.println(msg.c_str());
delay(10000);
}
}
You're missing parentheses for the function call in the first argument to client.publish()
.您在client.publish()
的第一个参数中缺少函数调用的括号。 The line currently reads:该行目前是:
if (client.publish(Topic.c_str, msg.c_str())){
It should read它应该读
if (client.publish(Topic.c_str(), msg.c_str())){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.