Pubsubclient: no matching function for call to 'PubSubClient:

Created on 22 Aug 2017  Â·  23Comments  Â·  Source: knolleary/pubsubclient

Arduino: 1.8.4 (Linux), Board: "Adafruit HUZZAH ESP8266, 80 MHz, 115200, 4M (3M SPIFFS)"

mqtt_test.ino:21: error: no matching function for call to 'PubSubClient::PubSubClient(WiFiClient&, const char&, const int&)'
PubSubClient client(wclient, mqtt_server, mqtt_port); //instanciates client object
^
/home/sspence65/sketchbook/mqtt_test/mqtt_test.ino/mqtt_test.ino.ino:21:53: note: candidates are:
In file included from /home/sspence65/sketchbook/mqtt_test/mqtt_test.ino/mqtt_test.ino.ino:2:0:
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:116:4: note: PubSubClient::PubSubClient(const char
, uint16_t, std::function PubSubClient(const char, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:116:4: note: candidate expects 5 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:115:4: note: PubSubClient::PubSubClient(const char
, uint16_t, std::function PubSubClient(const char, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:115:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:114:4: note: PubSubClient::PubSubClient(const char
, uint16_t, Client&, Stream&)
PubSubClient(const char, uint16_t, Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:114:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:113:4: note: PubSubClient::PubSubClient(const char
, uint16_t, Client&)
PubSubClient(const char, uint16_t, Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:113:4: note: no known conversion for argument 1 from 'WiFiClient' to 'const char
'
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:112:4: note: PubSubClient::PubSubClient(uint8_t, uint16_t, std::function PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:112:4: note: candidate expects 5 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:111:4: note: PubSubClient::PubSubClient(uint8_t
, uint16_t, std::function PubSubClient(uint8_t , uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:111:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:110:4: note: PubSubClient::PubSubClient(uint8_t
, uint16_t, Client&, Stream&)
PubSubClient(uint8_t , uint16_t, Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:110:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:109:4: note: PubSubClient::PubSubClient(uint8_t
, uint16_t, Client&)
PubSubClient(uint8_t , uint16_t, Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:109:4: note: no known conversion for argument 1 from 'WiFiClient' to 'uint8_t
{aka unsigned char}'
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:108:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:108:4: note: candidate expects 5 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:107:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:107:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:106:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&, Stream&)
PubSubClient(IPAddress, uint16_t, Client& client, Stream&);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:106:4: note: candidate expects 4 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:105:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&)
PubSubClient(IPAddress, uint16_t, Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:105:4: note: no known conversion for argument 1 from 'WiFiClient' to 'IPAddress'
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:104:4: note: PubSubClient::PubSubClient(Client&)
PubSubClient(Client& client);
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:104:4: note: candidate expects 1 argument, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:103:4: note: PubSubClient::PubSubClient()
PubSubClient();
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:103:4: note: candidate expects 0 arguments, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(const PubSubClient&)
class PubSubClient {
^
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(PubSubClient&&)
/home/sspence65/sketchbook/libraries/PubSubClient/src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided
mqtt_test.ino:24: error: 'MQTT' does not name a type
void callback(const MQTT::Publish& pub) {
^
mqtt_test.ino:24: error: expected unqualified-id before '&' token
void callback(const MQTT::Publish& pub) {
^
mqtt_test.ino:24: error: expected ')' before '&' token
mqtt_test.ino:24: error: expected initializer before 'pub'
void callback(const MQTT::Publish& pub) {
^
mqtt_test.ino:24: error: 'MQTT' does not name a type
void callback(const MQTT::Publish& pub) {
^
mqtt_test.ino:24: error: expected unqualified-id before '&' token
void callback(const MQTT::Publish& pub) {
^
mqtt_test.ino:24: error: expected ')' before '&' token
mqtt_test.ino:24: error: expected initializer before 'pub'
void callback(const MQTT::Publish& pub) {
^
exit status 1
no matching function for call to 'PubSubClient::PubSubClient(WiFiClient&, const char
&, const int&)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

needs info

Most helpful comment

I got same error and I fixed it! The error is this function needs char array and we use String. To solve that error you need to convert this string to char array...

String comsg;
comsg="Connected";

client.publish("/test/confirm", (char*) comsg.c_str());

Good Luck!

All 23 comments

Hi,

The PubSubClient doesn't provide a constructor that matches that signature, hence this error.

What sketch are you trying to build?

Hello!
I seem to have the same problem (error message as above) building the sketch at:
http://www.arjunsk.com/iot/esp8266-programming-cloud-mqtt-part-3/
Any idea what can be wrong?

Thanks
Bert

I have the same problem (error message as above). Where is the issue?

@Bagunda are you sure you've installed this library and not a different fork that has changed the callback signature?

How exactly did you install the library?

@knolleary Download zip.
Unzip folder "pubsubclient-master" to D:\Downloads\Arduino\TestMega_MQTT\libraries.
In ArduinoIDE in settings set folder to D:\Downloads\Arduino\TestMega_MQTT\

E:\Organisasi\Santren Koding\ioT\Coonect geeknesia\nyoba_bisa_Bismillah\nyoba_bisa_Bismillah.ino: In function 'void senddata(char, String, char, String)':

nyoba_bisa_Bismillah:33: error: no matching function for call to 'PubSubClient::publish(const char [9], String&)'

client.publish("iot/data",pubString);

                                 ^

E:\Organisasi\Santren Koding\ioT\Coonect geeknesia\nyoba_bisa_Bismillah\nyoba_bisa_Bismillah.ino:33:37: note: candidates are:

In file included from E:\Organisasi\Santren Koding\ioT\Coonect geeknesia\nyoba_bisa_Bismillah\nyoba_bisa_Bismillah.ino:2:0:

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:130:12: note: boolean PubSubClient::publish(const char, const char)

boolean publish(const char* topic, const char* payload);

        ^

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:130:12: note: no known conversion for argument 2 from 'String' to 'const char*'

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:131:12: note: boolean PubSubClient::publish(const char, const char, boolean)

boolean publish(const char* topic, const char* payload, boolean retained);

        ^

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:131:12: note: candidate expects 3 arguments, 2 provided

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:132:12: note: boolean PubSubClient::publish(const char, const uint8_t, unsigned int)

boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);

        ^

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:132:12: note: candidate expects 3 arguments, 2 provided

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:133:12: note: boolean PubSubClient::publish(const char, const uint8_t, unsigned int, boolean)

boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);

        ^

C:\Users\khafiS_Fahrurrozi\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:133:12: note: candidate expects 4 arguments, 2 provided

exit status 1
no matching function for call to 'PubSubClient::publish(const char [9], String&)'

same issue

error in arduino ide:

Arduino: 1.6.7 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, DOUT, 1M (64K SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

WARNING: Spurious .github folder in 'Adafruit MQTT Library' library
WARNING: Spurious .github folder in 'Adafruit SGP30 Sensor' library
WARNING: Spurious .github folder in 'IRremoteESP8266' library
WARNING: Spurious .github folder in 'aREST' library
ESPsonoff_4CH-v1.01p.ino:79: error: no matching function for call to 'PubSubClient::PubSubClient(WiFiClient&, const char [14], int)'

PubSubClient mqttClient(wifiClient, MQTT_SERVER, MQTT_PORT);

                                                       ^

F:\NODEMCU PROGRAMS\sonoff\ESPsonoff_4CH-v1.01p\ESPsonoff_4CH-v1.01p.ino\ESPsonoff_4CH-v1.01p.ino.ino:79:59: note: candidates are:

In file included from F:\NODEMCU PROGRAMS\sonoff\ESPsonoff_4CH-v1.01p\ESPsonoff_4CH-v1.01p.ino\ESPsonoff_4CH-v1.01p.ino.ino:29:0:

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:116:4: note: PubSubClient::PubSubClient(const char*, uint16_t, std::function

PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:116:4: note: candidate expects 5 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:115:4: note: PubSubClient::PubSubClient(const char*, uint16_t, std::function

PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:115:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:114:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&, Stream&)

PubSubClient(const char*, uint16_t, Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:114:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:113:4: note: PubSubClient::PubSubClient(const char*, uint16_t, Client&)

PubSubClient(const char*, uint16_t, Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:113:4: note: no known conversion for argument 1 from 'WiFiClient' to 'const char*'

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:112:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, std::function

PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:112:4: note: candidate expects 5 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:111:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, std::function

PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:111:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:110:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&, Stream&)

PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:110:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:109:4: note: PubSubClient::PubSubClient(uint8_t*, uint16_t, Client&)

PubSubClient(uint8_t *, uint16_t, Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:109:4: note: no known conversion for argument 1 from 'WiFiClient' to 'uint8_t* {aka unsigned char*}'

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:108:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function

PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:108:4: note: candidate expects 5 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:107:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, std::function

PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:107:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:106:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&, Stream&)

PubSubClient(IPAddress, uint16_t, Client& client, Stream&);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:106:4: note: candidate expects 4 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:105:4: note: PubSubClient::PubSubClient(IPAddress, uint16_t, Client&)

PubSubClient(IPAddress, uint16_t, Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:105:4: note: no known conversion for argument 1 from 'WiFiClient' to 'IPAddress'

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:104:4: note: PubSubClient::PubSubClient(Client&)

PubSubClient(Client& client);

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:104:4: note: candidate expects 1 argument, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:103:4: note: PubSubClient::PubSubClient()

PubSubClient();

^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:103:4: note: candidate expects 0 arguments, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(const PubSubClient&)

class PubSubClient {

   ^

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: PubSubClient::PubSubClient(PubSubClient&&)

C:\Users\udayw\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:83:7: note: candidate expects 1 argument, 3 provided

ESPsonoff_4CH-v1.01p.ino:82: error: 'MQTT' does not name a type

void callback(const MQTT::Publish& pub) {

                 ^

ESPsonoff_4CH-v1.01p.ino:82: error: expected unqualified-id before '&' token

void callback(const MQTT::Publish& pub) {

                              ^

ESPsonoff_4CH-v1.01p.ino:82: error: expected ')' before '&' token

ESPsonoff_4CH-v1.01p.ino:82: error: expected initializer before 'pub'

void callback(const MQTT::Publish& pub) {

                                ^

exit status 1
no matching function for call to 'PubSubClient::PubSubClient(WiFiClient&, const char [14], int)'

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I have the same problem, calling the subscribe method and passing a string.
no matching function for call to 'PubSubClient::subscribe (String&)'
It's possible only to pass a string constant? I need to index the call

Same. Anyone get this back working?

same same.

@exocode thanks for your contribution to the discussion.

What version of PubSubClient have you got? How did you install it? What platform are you using it on?

Hi @knolleary

I'm also getting this error:

error: no matching function for call to 'PubSubClient::publish(const char [19], String)'
client.publish("office/sensor/temp", String((float)temp));

As you can see, I have 2.7 installed. Also tried with 2.6 with same result

image

Windows 10, 64bits. Arduino IDE 1.8.9. ESP8266 ESP-01

@vazquezjm you are passing a string type as the second argument. There is no such method in this library. You probably want that second arg to be a char* : https://github.com/knolleary/pubsubclient/blob/d2ff771f4a79950fa36e35c4c71e232da4f85f5d/src/PubSubClient.h#L141

I got same error and I fixed it! The error is this function needs char array and we use String. To solve that error you need to convert this string to char array...

String comsg;
comsg="Connected";

client.publish("/test/confirm", (char*) comsg.c_str());

Good Luck!

This library doesn't define anything to do with void callback(const MQTT::Publish& pub). You must be using an example from a different library.

I don't understand what you mean. Rather than hijack someone else's issue with your own problem, please raise a new issue if it is related to this library. If you are using a different library, then I can't help.

I downloaded library of yours only sir...I doing project it is very
urgent... kindly help....lib name is pubsubclient master lib ..

On Wed 28 Aug, 2019, 2:14 AM knolleary, notifications@github.com wrote:

I don't understand what you mean. Rather than hijack someone else's issue
with your own problem, please raise a new issue if it is related to this
library. If you are using a different library, then I can't help.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/knolleary/pubsubclient/issues/319?email_source=notifications&email_token=ALDQGJWZ74JFE43UQ5MGGWDQGWGZRA5CNFSM4DXXWGBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5JBZ2A#issuecomment-525475048,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALDQGJTBNFZDF6I5VXQWAALQGWGZRANCNFSM4DXXWGBA
.

You are using this library, but your sketch is for a different library. All I can say is you should start with the examples this library provides, not whatever code you've copied to get the MQTT::Publish reference in your code. But as I said, do not use someone else's issue for your own problem. I will not reply to you on this issue again. Raise a new issue and provide details of your code if you want any help. It may be urgent for you, but it really isn't for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

include //Library can be download below

include //Library can be downloaded below

include //Library can be downloaded below

include

int sensorPin1 = 5;

//int flowPin2 = 4;
//int flowPin3 = 3;
//int flowPin4 = 2;

unsigned long flow1count = 0;
unsigned long flow2count = 0;

define countof(a) (sizeof(a) / sizeof(a[0]))

/* Connecting to existing wifi AP Network */

//char ssid[] = "14CORE"; // your network SSID (name)
//char password[] = "we do what we must, because we can"; // your
network password

/* Make you own stand alone wifi networ accesspoint/
const char
ssid = "14CORE";
const char* password = "1234567890";

// Set your IP address for your suitable for your network IP/SEGMENT

IPAddress server(192, 168, 4, 100);

PubSubClient client(server);
String webString = "14CORE | Water Flow Sensor with ESP8266"; // String
to display

// Callback function

void callback(const MQTT::Publish& pub) {
if(pub.payload_string().equals("flow1"))
{
webString = "Flow 2: " + String(flow1count/450.0) + " L"; // Arduino
has a hard time with float to string
client.publish("outTopic",webString);
} else if(pub.payload_string().equals("flow2"))
{
webString = "Flow 2: " + String(flow2count/450.0) + " L";
client.publish("outTopic",webString); // send to someones
browser when asked

  } else

Serial.print("14CORE | Flow Sensor ")
Serial.print("Flow 1 in Liters: ");
Serial.print(flow1count/450.0);
Serial.print("\tFlow 2 in Liters: ");
Serial.print(flow2count/450.0);
Serial.print("\tFlow 1 in pulses: ");
Serial.print(flow1count);
Serial.print("\tFlow 2 in pulse: ");
Serial.println(flow2count);
delay(500);

{
}
Serial.print(pub.topic());
Serial.print(" => ");
Serial.println(pub.payload_string());
}
void setup()
{

Serial.begin(115200);
pinMode(sensorPin1, INPUT_PULLUP);
attachInterrupt(sensorPin1, flow1, CHANGE);
pinMode(flowPin2, INPUT_PULLUP);
attachInterrupt(flowPin2, flow2, CHANGE);
client.set_callback(callback);

// Connect to existing wifi network

WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");

// Wait 5mili for connection

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("Connecting ")
Serial.print(".");
}

Serial.println("");
Serial.print
Serial.println("14CORE | ESP8266 Server");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

if (client.connect("14CORE | ESP8266 Liquid Flow Sensor")) {
client.publish("outTopic","flow boot up");
client.subscribe("inTopic");
}
}

void loop()
{
client.loop();
}

void flow1()
{
flow1count +=1;
}

void flow2()
{
flow2count +=1;
}

On Wed 28 Aug, 2019, 2:23 AM knolleary, notifications@github.com wrote:

You are using this library, but your sketch is for a different library.
All I can say is you should start with the examples this library provides,
not whatever code you've copied to get the MQTT::Publish reference in your
code. But as I said, do not use someone else's issue for your own problem.
I will not reply to you on this issue again. Raise a new issue and provide
details of your code if you want any help. It may be urgent for you, but it
really isn't for me.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/knolleary/pubsubclient/issues/319?email_source=notifications&email_token=ALDQGJX5S7E6ZPVTTOAKMA3QGWH3FA5CNFSM4DXXWGBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5JCR4Y#issuecomment-525478131,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALDQGJSUPBIDHH2X4OGXAELQGWH3FANCNFSM4DXXWGBA
.

I have mail you kindly help me sir...I was trying...otherwise give link of
the another library...sirrr..it is very much important to me

On Wed 28 Aug, 2019, 2:23 AM knolleary, notifications@github.com wrote:

You are using this library, but your sketch is for a different library.
All I can say is you should start with the examples this library provides,
not whatever code you've copied to get the MQTT::Publish reference in your
code. But as I said, do not use someone else's issue for your own problem.
I will not reply to you on this issue again. Raise a new issue and provide
details of your code if you want any help. It may be urgent for you, but it
really isn't for me.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/knolleary/pubsubclient/issues/319?email_source=notifications&email_token=ALDQGJX5S7E6ZPVTTOAKMA3QGWH3FA5CNFSM4DXXWGBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5JCR4Y#issuecomment-525478131,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALDQGJSUPBIDHH2X4OGXAELQGWH3FANCNFSM4DXXWGBA
.

@sujithkumarjp. I asked you not to comment on this issue. Raise a new issue. Any more replies from you on this issue will be removed. If this really is so important to you, you can raise a new issue like I have asked 3 times.

I got same error and I fixed it! The error is this function needs char array and we use String. To solve that error you need to convert this string to char array...

String comsg;
comsg="Connected";

client.publish("/test/confirm", (char*) comsg.c_str());

Good Luck!

This worked for me. I can pass a string value such as "OK" but if I pass something like this...

String ip = WiFi.localIP().toString();

I have to convert ip to the char array and it works.

Hola, me podrias ayudar con esto?, es que estoy haciendo un proyecto de Iot, y me muestra este error luego de que he agregado tu biblioteca, te agradecería mucho si me ayudas, graciasss

C:\Users\Owner\AppData\Local\Temp\arduino_modified_sketch_532223\publish.ino: In function 'void reconnect()':

publish:48:51: error: no matching function for call to 'PubSubClient::connect(const char [10], const char [36], const char [1])'

 if (client.connect(MQTT_CLIENT_NAME, TOKEN, "")) {

                                               ^

In file included from C:\Users\Owner\AppData\Local\Temp\arduino_modified_sketch_532223\publish.ino:5:0:

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:119:9: note: candidate: bool PubSubClient::connect(String)

bool connect(String id);

     ^

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:119:9: note: candidate expects 1 argument, 3 provided

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:131:9: note: candidate: bool PubSubClient::connect(String, String, uint8_t, bool, String)

bool connect(String id, String willTopic, uint8_t willQos, bool willRetain, String willMessage);

     ^

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:131:9: note: candidate expects 5 arguments, 3 provided

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:193:9: note: candidate: bool PubSubClient::connect(MQTT::Connect&)

bool connect(MQTT::Connect &conn);

     ^

C:\Users\Owner\Documents\Arduino\libraries\pubsubclient-master\src/PubSubClient.h:193:9: note: candidate expects 1 argument, 3 provided

publish:52:27: error: 'class PubSubClient' has no member named 'state'

   Serial.print(client.state());

                       ^

C:\Users\Owner\AppData\Local\Temp\arduino_modified_sketch_532223\publish.ino: In function 'void setup()':

publish:81:10: error: 'class PubSubClient' has no member named 'setServer'

client.setServer(mqttBroker, 1883);

      ^

publish:82:10: error: 'class PubSubClient' has no member named 'setCallback'

client.setCallback(callback);

      ^

Se encontraron varias bibliotecas para "WiFi.h"
Usado: C:\Users\Owner\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
No usado: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\libraries\WiFi
exit status 1
no matching function for call to 'PubSubClient::connect(const char [10], const char [36], const char [1])'

Was this page helpful?
0 / 5 - 0 ratings