ThingSpeak not showing any data from my ESP32!

2 Ansichten (letzte 30 Tage)
Matheus Bitencourt
Matheus Bitencourt am 17 Nov. 2020
Kommentiert: Vinod am 17 Nov. 2020
It seems like the site isn't receiving any data. The graphics are empty!
Could you please help me? Here's the source code!
Thanks so much!
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
#include <WiFi.h>
String apiKey = "BE7U15RJYY57AV91"; // Enter your Write API key from ThingSpeak
const char *ssid = "Ashish"; // replace with your wifi ssid and wpa2 key
const char *pass = "12345678";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
int h = 0;
float t =0;
h = hallRead();
t = ((temprature_sens_read()-32)/1.8); //changing temperature parameter to celsius
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(h);
postStr += "&field2=";
postStr += String(t);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Hall: ");
Serial.println(h);
Serial.print("Temperature:");
Serial.print(t);
Serial.println(" C");
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
delay(10000);
}

Antworten (1)

Vinod
Vinod am 17 Nov. 2020
I strongly recommend using the ThingSpeak library and starting from the examples provided with it.
  2 Kommentare
Matheus Bitencourt
Matheus Bitencourt am 17 Nov. 2020
Thank you so much.
After using ThingSpeak library, I was able to upload the data!
However, I can't upload more than ONE field for Channel. Can you help me? https://www.mathworks.com/matlabcentral/answers/651273-unable-to-send-data-to-two-fields-at-the-same-channel-can-you-help-me
Vinod
Vinod am 17 Nov. 2020
Did you try this example?

Melden Sie sich an, um zu kommentieren.

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu REST API finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by