I have a mq135 sensor abd nodemcu ESP-12E module to calculate air quality and monitor it via Cayenne platform.

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?

We can’t add Nodemcu with token method, we should use MQTT authentication instead to add and connect nodemcu module to cayenne.

 #include “MQ135.h”
 #include “CayenneDefines.h”
 #include “CayenneWiFi.h”
 #include “CayenneWiFiClient.h”
 #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:
Cayenne.begin(token, ssid, pwd);

void loop() {
// put your main code here, to run repeatedly:
// 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

You could have readily answered this question for yourself merely by looking at the example for the Cayenne-MQTT-ESP8266 library.

The key part being:

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

Cayenne.begin(username, password, clientID, ssid, wifiPassword);

It is not readily possible to know if this is the same Cayenne library you were using before, as you neglected to specify what you were using. The includes are different, but that could be a version difference, or it could be evidence of an entirely different approach.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.