Hi I want to start with MQTT and node-RED. Beside the installation on an RaspPi I started to develop a short testprogramm on Arduino IDE for an ESP32 Node MCU.
I followed an tutorial but I got this error:
libraries\\EspMQTTClient\\EspMQTTClient.cpp.o:(.literal._ZN13EspMQTTClientC2EPKcS1_S1_S1_S1_S1_s+0x10): undefined reference to `onConnectionEstablished()\’collect2.exe: error: ld returned 1 exit statusexit status 1Fehler beim Kompilieren für das Board ESP32 Dev Module.
Here my sketch:
#include <WiFi.h>
#include <WiFiClient.h>
#include “EspMQTTClient.h”
const char* ssid = “____”;
const char* password = “______”;
EspMQTTClient client (
“bluenet”, // SSID
“ichessegernpizza”, // password
// “192.168.178.51”, // MQTT Broker server IP
“esp01” // IOT device Name
);
void setup(void)
{
Serial.begin(115200);
WiFi.begin(ssid, password); // Connect to WiFi network
Serial.println(“”);
while (WiFi.status() != WL_CONNECTED) // Wait for connection
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.print(“Connected to “);
Serial.println(ssid);
Serial.print(“IP address: “);
Serial.println(WiFi.localIP());
}
void loop(void)
{
}
Hi.
Can you tell me what is the board that you are using?
ESP32 or ESP8266?
Regards,
Sara
Sorry, yes of course: I use a ESP32 expressif
After I asked I followed your tutorial (before I folowed a tutorial from a colleque)
This works. Than I switched back to the first sektch an it seems I must at least run the “client.loop()” in the programm. Than it works too (see sketch below).
Nevertheless I will follow your tutorial for design a learning IOT network project for my studends.
Your tutorials are very helpfull THANKS
Solved:
#include <WiFi.h>
#include <WiFiClient.h>
#include “EspMQTTClient.h”
const char* ssid = “_____”;
const char* password = “_____________”;
const char* mqtt_ip = “_____________”;
EspMQTTClient client ( //Erstelle ein “Objekt” mit den Daten des MQTT Broker’s
ssid, // WiFi SSID
password, // WiFi password
mqtt_ip, // MQTT Broker server IP
//””, // MQTT Broker benutzername
//””, // MQTT broker password
“esp01” // MQTT ID (IOT device Name)
);
void setup(void)
{
Serial.begin(115200); //starte den seriellen Monitor mit der angegebenen Baud Rate
WiFi.begin(ssid, password); // Connect to WiFi network
Serial.println(“”);
while (WiFi.status() != WL_CONNECTED) // Wait for connection
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.print(“Connected to “);
Serial.println(ssid);
Serial.print(“IP address: “);
Serial.println(WiFi.localIP());
}
void onConnectionEstablished() { // dieser void ist zwingend erforderlich, da es ohne ihn zu compilierungs-Fehlern kam
Serial.println(“Verbunden”); // Schreibe, sobald der ESP verbunden ist, eine Nachricht in den Seriellen Monitor
}
void loop(void)
{
client.loop(); // Starte den MQTT Client im loop
client.publish(“esp/test”, “Dies ist ein Test ##__”); // Veröffentliche die Nachricht “Dies ist ein Test” unter dem Topic “esp/test”
delay(2000); // Pause zwischen den Nachrichten
client.publish(“esp/test”, “Dies ist ein Test __##”); // Veröffentliche die Nachricht “Dies ist ein Test” unter dem Topic “esp/test”
delay(2000); // Pause zwischen den Nachrichten
}