Hi Rui,
First of all, thanks for your great tutorials. I am really enjoying passing through it.
I have found interesting tutorial about connecting ESP32 to Watson IoT platform via MQTT.
iotdesignpro.com/projects/how-to-connect-esp32-with-ibm-watson-cloud-platform
However, it uses PubSubClient Library. I am trying to make it by using AsyncMqttClient cause I already used to it, but cant figure out how to set credentials to make successful connection.
May someone please assist here?
Hi.
Are you talking about these credentials they refer in the tutorial?
#define ORG "******" #define DEVICE_TYPE "ESP32" #define DEVICE_ID "***********" #define TOKEN "********"
I’ve taken a quick look at the code as these seem to be used on the payload messages.
example:
String payload = "{\"d\":{\"Name\":\"" DEVICE_ID "\""; payload += ",\"temperature\":"; payload += temperature; payload += "}}";
So, I think you just need to send this payload to the right topic. You can use the following snipet as a reference (using the AsyncMQTT)
// Publish an MQTT message on topic uint16_t packetIdPub2 = mqttClient.publish("TOPIC", 2, true, payload.c_str()); Serial.print("Publishing on topic TOPIC at QoS 2, packetId: "); Serial.println(packetIdPub2);
Replace the “TOPIC” with the topic you want to send that payload to.
Repeat this for the other topics you need to send information to.
I’m not familiar with that platform, so I’m nor sure what’s really needed.
Regards,
Sara