Change Token authentication to MQTT authentication

Hello friends, How can i edit this below code to add and connect my Nodemcu ESP-12E module to cayenne with MQTT authentication(username, password, client_id, ssid, passwd) method, because we can’t add Nodemcu with token method, we should use MQTT authentication instead to add nodemcu module to cayenne. can you help me? :pray:

#include “MQ135.h”
#include “CayenneDefines.h”
#include “CayenneWiFi.h”
#include “CayenneWiFiClient.h”
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define VIRTUAL_PIN 5
#define ANALOGPIN A0

char token = “”; // Insert your token here
char ssid = “”; // Insert your SSID here
char pwd = “”; // Insert your SSID password here
MQ135 gasSensor = MQ135(ANALOGPIN);

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Cayenne.begin(token, ssid, pwd);
}

void loop() {
// put your main code here, to run repeatedly:
Cayenne.run();
// float rzero = gasSensor.getRZero(); //this to get the rzero value, uncomment this to get ppm value
// float ppm = gasSensor.getPPM(); // this to get ppm value, uncomment this to get rzero value
// Serial.println(rzero); // this to display the rzero value continuously, uncomment this to get ppm value
// Serial.println(ppm); // this to display the ppm value continuously, uncomment this to get rzero value
// Cayenne.virtualWrite(VIRTUAL_PIN,ppm); // uncomment after rzero define and get your ppm calculation
}

i have the same issue :frowning:

Hi @fardadjung @rapier.hu,

That sketch is a non-MQTT sketch using the Cayenne Arduino Library to connect the ESP chip as an Arduino device. The currently supported way to add a ESP8266 device is through the MQTT connectivity sketch here.

That sketch won’t ask for an auth token, and will have appropriate spots to enter your MQTT Username/Password/Client ID.

Alternatively, if you want to use the auth token sketch, you’ll want to add your ESP as an Arduino by going to Add New > Device/Widget > MicroControllers > Arduino, and picking ANY of the Arduino boards listed there (it doesn’t matter which one). This way, Cayenne will give you an auth token which makes sense in this sketch, and you won’t need to use the MQTT credentials. This is an unsupported way of connecting an ESP8266 chip to Cayenne, but many users were using it successfully until we introduced official support through the MQTT API.

2 Likes