Esp32 registering to Cumulocity IoT

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:

}
![WhatsApp Image 2023-06-07 at 12.29.57 AM|690x323](upload://jfurjIc4CuNCeiXeRVSPUMBDHPp.jpeg)

The Device is not creaed on-connect, you’ll have to tell the platform to create it - together with it’s name and type. To do this, send 100,<your device name>,<your device type> to s/us.

This and all other templates you can use for s/us you can find here.

1 Like

If you also want to implement the bootstrap process (Device integration using MQTT - Cumulocity IoT Guides) you can also have a look at this sample code: cumulocity-iot-examples/ESP Demo with device registration at master · SoftwareAG/cumulocity-iot-examples · GitHub

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.