Hello, community. I have a problem when executing this code:
#include <UbidotsEsp32Mqtt.h>
#define DO_PIN_MQ2 26
#define AO_PIN_MQ2 23
#define DO_PIN_MQ135 32
#define AO_PIN_MQ135 14
#define DO_PIN_MQ7 35
#define AO_PIN_MQ7 27
const char *UBIDOTS_TOKEN = "##########";
const char *WIFI_SSID = "##########";
const char *WIFI_PASS = "##########$";
const char *DEVICE_LABEL = "calidadAire";
const char *VARIABLE_LABEL1 = "mq2";
const char *VARIABLE_LABEL2 = "mq7";
const char *VARIABLE_LABEL3 = "mq135";
const int PUBLISH_FREQUENCY = 5000;
unsigned long timer;
Ubidots ubidots(UBIDOTS_TOKEN);
void setup() {
Serial.begin(115200);
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
ubidots.setCallback(callback);
ubidots.setup();
ubidots.reconnect();
Serial.println("Conectado a WiFi");
timer = millis();
pinMode(DO_PIN_MQ2, INPUT);
pinMode(DO_PIN_MQ135, INPUT);
pinMode(DO_PIN_MQ7, INPUT);
delay(20000);
}
void loop() {
if (!ubidots.connected()) {
ubidots.reconnect();
}
if (abs(millis() - timer) > PUBLISH_FREQUENCY) {
float valorMQ2 = detectarValor(DO_PIN_MQ2, AO_PIN_MQ2, "MQ2");
float valorMQ135 = detectarValor(DO_PIN_MQ135, AO_PIN_MQ135, "MQ135");
float valorMQ7 = detectarValor(DO_PIN_MQ7, AO_PIN_MQ7, "MQ7");
ubidots.add(VARIABLE_LABEL1, valorMQ2);
ubidots.add(VARIABLE_LABEL2, valorMQ135);
ubidots.add(VARIABLE_LABEL3, valorMQ7);
ubidots.publish(DEVICE_LABEL);
timer = millis();
}
ubidots.loop();
}
void callback(char *topic, byte *payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
float detectarValor(uint8_t DO_PIN, uint8_t AO_PIN, const char *sensorName) {
float estadoGas = digitalRead(DO_PIN);
float valorGas = analogRead(AO_PIN);
Serial.print(sensorName);
Serial.print(" - ");
if (estadoGas == HIGH) {
Serial.println("Valor encontrado:");
Serial.print(valorGas);
} else {
Serial.println("Error en detección");
}
return valorGas;
Serial.println();
}
What I want is to monitor air quality using MQ7, 2 and 135 and uploading the data obtained to Ubidots. However, I can't because I get this error. Additionally, it gives me "Multiple libraries were found for "WiFi.h"". I am working with the ESP32 WROOM 32 and using the Arduino IDE 1.8.13. I really appreciate your time if you got this far, I hope you can help me. I have tried some solutions but the Serial Monitor throws me "?????"