简体   繁体   English

PubSubClient 编译错误 - 没有匹配 function

[英]PubSubClient Complation error - no matching function

#include <Arduino.h>
#include <LoRa.h>
#include <PubSubClient.h>

const int pin_ss = 5;
const int pin_rst = 14;
const int pin_dio0 = 26;
const char* mqttServer = "192.168.137.216"; // MQTT broker IP or hostname
const int mqttPort = 1883; // MQTT broker port
const char* mqttUser = "pi"; // MQTT username
const char* mqttPassword = "Admin123"; // MQTT password
const char* loraTopic = "Test"; // Topic to subscribe/publish to


void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) 
  {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

PubSubClient mqttClient(loraTopic, mqttServer, mqttPort, callback, mqttUser, mqttPassword);

void setup() {
  Serial.begin(115200);
  // initialize LoRa module
  LoRa.setPins(pin_ss, pin_rst, pin_dio0);
  if (!LoRa.begin(866E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  // connect to MQTT broker
  while (!mqttClient.connect("ESP32", mqttUser, mqttPassword)) {
    delay(1000);
    Serial.println("Connecting to MQTT...");
  }
  Serial.println("Connected to MQTT");
  mqttClient.subscribe(loraTopic);
}

void loop() {
  mqttClient.loop();

  // send message to the topic
  String message = "Hello from ESP32";
  mqttClient.publish(loraTopic, message.c_str());
  delay(1000);
}

Compilation error: no matching function for call to 'PubSubClient::PubSubClient(const char*&, const char*&, const int&, void (&)(char*, byte*, unsigned int), const char*&, const char*&)编译错误:没有匹配 function 调用 'PubSubClient::PubSubClient(const char*&, const char*&, const int&, void (&)(char*, byte*, unsigned int), const char*&, const char *&)

Can someone help me with this?有人可以帮我弄这个吗? There is some issue with PubSubClient, I try to change the string into character but still no results PubSubClient 有一些问题,我尝试将字符串更改为字符,但仍然没有结果

There isn't a version of the PubSubClient constructor that takes a topic as its first argument or the username and password.没有将主题作为其第一个参数或用户名和密码的 PubSubClient 构造函数版本。

https://pubsubclient.knolleary.net/api#PubSubClient2 https://pubsubclient.knolleary.net/api#PubSubClient2

PubSubClient mqttClient(mqttServer, mqttPort, callback, client);

You also appear to be missing code to set up the WiFi connection, which would supply the client passed as the final argument.您似乎还缺少设置 WiFi 连接的代码,该连接将提供作为最后一个参数传递的client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM