I tried many several times to connect ESP32 to Cumulocity IoT plateform, I have used that code below in my esp32 , it showed that it’s connected to mqtt in serial monitor of my esp32 but i don’t find it in cumulocity iot device management even if i used the same ID i gave for my ESP32 board in the code;
Any solution please!
#include <PubSubClient.h>
#include <WiFi.h>
//#include "wifi_config.h"
const char* ssid = "wifi ssid"; // Change this to your WiFi SSID
const char* password = "wifi password"; // Change this to your WiFi password
const char* mqttServer = "mqtt.us.cumulocity.com";
const int mqttPort = 1883;
const char* mqttUser = "tenant/username";
const char* mqttPassword = "password of the user";
const char* topic = "s/us";
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
Serial.begin(115200);
Serial.println("Starting connecting WiFi.");
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
client.setServer(mqttServer, mqttPort);
while (!client.connected()) {
Serial.println("Connecting to MQTT ...");
if (client.connect("ESP32Client", mqttUser, mqttPassword)) {
Serial.println("connected");
}else{
Serial.print("failed with state");
Serial.print(client.state());
delay(2000);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}
