I am trying to establish communication between ESP32 and Node-Red, where as ESP32 will be in remote location, that’s why the use of LoraWan comes into the scenario. I am using PubSubClient library to use MQTT but I am getting some errors related to constructor which is shown below.
#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”;
const int mqttPort = 1883;
const char* mqttUser = “pi”;
const char* mqttPassword = “Admin123”;
const char* loraTopic = “Test”;
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(mqttServer, mqttPort);
//PubSubClient mqttClient(loraTopic, mqttServer, mqttPort, callback, mqttUser, mqttPassword);
mqttClient.connect(loraTopic, 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())
{
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);
}
ERROR : Compilation error: no matching function for call to ‘PubSubClient::PubSubClient(const char*&, const int&)’
Hi.
Try writing the IP address like this:
IPAddress mqttServer(192,168,137,216);
Instead of: const char* mqttServer = “192.168.137.216”;
Let me know if this fixes the issue.
Regards,
Sara
No, that doesn’t change anything. I still get the error saying “Compilation error: no matching function for call to ‘PubSubClient::PubSubClient(const char*&, IPAddress&, const int&, void (&)(char*, byte*, unsigned int), const char*&, const char*&)'”
No, there is still the same issue.
“Compilation error: no matching function for call to ‘PubSubClient::PubSubClient(const char*&, const char [16], const int&, void (&)(char*, byte*, unsigned int), const char*&, const char*&)'”
Am I doing something wrong in declaring constructor? Pubsubclient one?
PubSubClient mqttClient(mqttServer, mqttPort);
mqttClient.connect(loraTopic, mqttUser, mqttPassword);
These two lines of code.