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
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()
. 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())){
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.