Thingspeak (via ESP8622) is not showing any graphical data from 3 Fields.

10 vues (au cours des 30 derniers jours)
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);
}
}

Réponse acceptée

Vinod
Vinod le 17 Nov 2020
I strongly recommend using the ThingSpeak library and starting from the examples provided with it.
  2 commentaires
Nathan Garpiya
Nathan Garpiya le 17 Nov 2020
I completed the "Write" example and it was okay.
I am a bit confused with this part of the code:
int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
// Check the return code
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
I don't get the "return code" bit.
Christopher Stapels
Christopher Stapels le 18 Nov 2020
That section checks the HTTP return code to make sure the request was successful.

Connectez-vous pour commenter.

Plus de réponses (0)

Communautés

Plus de réponses dans  ThingSpeak Community

Catégories

En savoir plus sur Read Data from Channel dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by