ESP32 + ThingSpeak just send zero value.
古いコメントを表示
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 件のコメント
Armando Villegas
2023 年 2 月 10 日
Christopher Stapels
2023 年 2 月 10 日
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 コミュニティ
カテゴリ
ヘルプ センター および File Exchange で Read Data from Channel についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!