Borrar filtros
Borrar filtros

I keep getting the Compilation error: call of overloaded 'setField(int, double&)' is ambiguous when setting fields in my TS channel

13 visualizaciones (últimos 30 días)
I keep getting the same error "Compilation error: call of overloaded 'setField(int, double&)' is ambiguous" whenever I try to compile my code. It only works when I set the first field WATER_TEMP but when I set the second field which is the PH_LEVEL it doesn't compile. I don't know what I'm doing wrong because the code works, the only error is when I set the PH_LEVEL field.
Context: I am using an ESP32 board, I connected my PH Sensor to GPIO36 for data. My sensors work, I can see the results in the serial monitor. But everytime I set the second field, it keeps failing to compile.
This is my code:
#include <OneWire.h>
#include "WiFi.h"
#include <WiFiClient.h>
#include "ThingSpeak.h"
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4 // PIN FOR WATER TEMPERATURE SENSOR
const char* ssid = "xxxxxxxxxxxxxxx"; //My Network SSID
const char* password = "xxxxxxxxxx"; //My Network Password
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int PH_ANALOG_PIN = 36;
int sample = 10;
float adcRes = 1024.0;
WiFiClient client;
unsigned long myChannelNumber = xxxxx;
const char * myWriteAPIKey = "xxxxxxxxxx";
void setup() {
Serial.begin(9600);
sensors.begin();
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}
void loop() {
//PH LEVEL CODE:
int measure = 0;
for(int i=0; i<sample; i++){
measure += analogRead(PH_ANALOG_PIN);
delay (100);
}
float volt = 5/adcRes*measure/sample;
double PH_LEVEL = -5.70 * (float)volt + 31.27;
Serial.print("ph:");
Serial.print(PH_LEVEL);
delay(1000);
//WATER TEMPERATURE CODE:
sensors.requestTemperatures(); // Send the command to get temperature readings
float WATER_TEMP = sensors.getTempCByIndex(0); // Get the temperature in Celsius
if (WATER_TEMP != DEVICE_DISCONNECTED_C) {
Serial.print("Water Temperature: ");
Serial.print(WATER_TEMP);
} else {
Serial.print("Error: Unable to read temperature!");
}
// set the fields with the values
ThingSpeak.setField(1, WATER_TEMP);
ThingSpeak.setField(2, double(PH_LEVEL)); //THIS IS THE ONLY LINE THAT KEEPS MY SKETCH FROM COMPILING
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(3000);
} //END OF LOOP
float readTemperature()
{
float WATER_TEMP = sensors.getTempCByIndex(0); // Get the temperature in Celsius
}

Respuestas (2)

Shakthi Varun
Shakthi Varun el 8 de Abr. de 2024
setField function only takes int, long and float as the second argument. The below line should work.
ThingSpeak.setField(2, float(PH_LEVEL));

Christopher Stapels
Christopher Stapels el 17 de Oct. de 2023
Try setting the value first in this line:
ThingSpeak.setField(2, double(PH_LEVEL));
e.g.
double myLevel=double(PH_LEVEL);
ThingSpeak.setField(2, myLevel);

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by