Error: call of overloaded 'abs(long unsigned int)' is ambiguous

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 "?????"

Drop the "abs" here and in similar constructions. abs() has no purpose here, since the quantities are all unsigned, and the result is unsigned.

if (abs(millis() - timer) > PUBLISH_FREQUENCY) {

I moved your topic to a more appropriate forum category @alvaro_rimbaud.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

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