• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Establishing communication between ESP32 and NodeRed via LoraWan and MQTT as broker.

Q&A Forum › Category: Arduino › Establishing communication between ESP32 and NodeRed via LoraWan and MQTT as broker.
0 Vote Up Vote Down
asked 2 years ago

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&)’

Question Tags: ESP32, LoraWan. Raspberry Pi, MQTT, Node-Red
7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

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
 

0 Vote Up Vote Down
answered 2 years ago

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*&)'”

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

And like this? Does it work?

const char mqttServer[] = "192.168.137.216";

0 Vote Up Vote Down
answered 2 years ago

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?

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Just to be sure, what is the line of code highlighted when you get the error?

0 Vote Up Vote Down
answered 2 years ago

PubSubClient mqttClient(mqttServer, mqttPort);
mqttClient.connect(loraTopic, mqttUser, mqttPassword);

These two lines of code.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

You can’t pass a topic to the connect() method.
Please, double-check the examples to see which arguments each function needs.
Which MQTT example are you using as a reference?

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.