Thingspeak (via ESP8622) is not showing any graphical data from 3 Fields.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nathan Garpiya
am 17 Nov. 2020
Kommentiert: Christopher Stapels
am 18 Nov. 2020
Hi
i'm trying to send data on thinkspeak for 3 fields. But thingspeak is not showing any graphical representation despite entries.
I reduced the update time to 10 and still didn't get anything
This is my code:
//Include the ESP8266 WiFi library.
#include <ESP8266WiFi.h>
//Local Network Settings.
char ssid[] = "AndroidAP5723"; // your network SSID (name)
char pass[] = "hookuyte"; // your network password
const byte buttonPin = 4;
const byte potentiometerPin = A0;
char thingSpeakAddress[]= "api.thingspeak.com";// Host address URL
String APIKey = "**************";//Blanked out for security reasons
const int updateThingSpeakInterval = 20 * 1000;// every 20 secs
//Initialize wifi client
WiFiClient client;
void setup() {
//Set the baud rate for Serial Communication
Serial.begin(115200);
delay(2000);
//Display what SSiD you are connecting to.
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
//Connect to the Access.
WiFi.begin(ssid,pass);
//Now we establish a connection to the access point
while(WiFi.status()!= WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
}//Close setup
void loop() {
//Read Sensor Data
int potentiometerReading = analogRead(potentiometerPin);
boolean buttonReading = digitalRead(buttonPin);
//Convert sensor data into String objects
String potentiometerField = String(potentiometerReading);
String buttonField = String(buttonReading);
String randomNumberField = String(random (0, 42));
/* Concatenate the field into one string object
* which we can send as the Message body
*/
String thingSpeakData = "field1=" + potentiometerField+ "&field2=" + buttonField + "&field3=" + randomNumberField;
//Establish a connection with ThingSpeak
if(client.connect(thingSpeakAddress, 80)){
//Send the Message Start-Line (Method URI protocolVersion).
client.println("POST /update HTTP/1.1");
//Send the HTTP Header Field
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println("X-THINGSPEAKAPIKEY: " + APIKey);
client.println("Contect-Type: application/x-www-form-urlencoded");
client.print("Content-Lenght: ");
client.println(thingSpeakData.length());
client.println();// Header fields are complete
//Send Message Body
client.print(thingSpeakData);
//check if connection to thingSpeak was established
if (client.connected()){
Serial.println("Connected to thingSpeak.");
Serial.println();
}
//Display info to Serial Monitor for troublShooting
Serial.print("Potentiometer [Field 1]= " );
Serial.print(potentiometerField);
Serial.print(" Button [Field 2] = " );
Serial.print(buttonField);
Serial.print(" Random [Field 3] = " );
Serial.print(randomNumberField);
delay(updateThingSpeakInterval);
}
}
0 Kommentare
Akzeptierte Antwort
Vinod
am 17 Nov. 2020
2 Kommentare
Christopher Stapels
am 18 Nov. 2020
That section checks the HTTP return code to make sure the request was successful.
Weitere Antworten (0)
Communitys
Weitere Antworten in ThingSpeak Community
Siehe auch
Kategorien
Mehr zu Read Data from Channel 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!