ESP32 + ThingSpeak just send zero value.

7 次查看(过去 30 天)
Hi everyone.
I'm trying to send the ADC value from a potentiometer to the ThingSpeak channel and I'm dealing with the problem that I send data to ThingSpeak and I just receive zero value in the channel even if I turn the potentiometer knob. If I run the program without the ThingSpeak configuration everything work well.
Could you help me, please?
I leave the source code below.
Thank you.
/*LIBRARIES*/
#include <Arduino.h>
#include "ThingSpeak.h"
#include "WiFi.h"
/*DEFINITIONS*/
#define ANALOGPIN 15
/*THINGSPEAK CONFIGURATION*/
const char* ssid = "xxxxxx";
const char* password = "xxxxxx";
unsigned long channelID = xxxxxxx;
const char* WriteAPIKey = "xxxxxx";
WiFiClient Client;
/*PROTOTYPES*/
void readPot (void);
/*--START FILE--*/
void setup()
{
delay(2000);
Serial.begin(115200);
Serial.println("ESP32 ADC");
/*WIFI CONNECTION*/
WiFi.begin(ssid,password);
while(WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("\nWifi connected");
ThingSpeak.begin(Client);
}
void loop()
{
delay(2000);
readPot();
ThingSpeak.writeFields(channelID,WriteAPIKey);
Serial.println("Send data.");
Serial.println("---------------\n");
delay(18000);
}
/*FUNCTION*/
void readPot (void)
{
int potVal = analogRead(ANALOGPIN);
while(isnan(potVal))
{
Serial.println("Read failed");
delay(2000);
potVal = analogRead(ANALOGPIN);
}
Serial.println("\nADC: ");
Serial.println(potVal);
ThingSpeak.setField(1,potVal);
}
/*-- END OF FILE --*/
  2 个评论
Christopher Stapels
I would consider returning the pot value from your function readPot and them calling setField in the same scope (in the main loop) as writefields. I'm not sure the variable information set with setField() in the function is transferred back to the main function.
I have multiple devices running for multiple years that read the ADC while wifi is connected with no problem.

请先登录,再进行评论。

回答(0 个)

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Read Data from Channel 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by