ESP32 with flex sensor cannot upload data to ThingSpeak

hi im having problem uploading my latest data of my flex sensor to thingspeak. and whenever I bend my flex sensor it will show no difference or change in my graph and I received this error in my serial monitor "Problem updating channel. HTTP error code 200'
pls help cause this is a huge project for my final year and I'm trying out one flex sensor at first before I include another 4 in it to see if this works.

this is my code:

#include <WiFi.h>
#include "ThingSpeak.h"

const int flexPin0 = 25;

const char* ssid = "xxx"; // your network SSID (name)
const char* password = "xxx"; // your network password

WiFiClient client;

unsigned long myChannelNumber = xxxxxxx;
const char * myWriteAPIKey = "xxx";

// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

// Variable to hold temperature readings
//float temperatureC;
//uncomment if you want to get temperature in Fahrenheit
//float temperatureF;

// Create a sensor object
//Adafruit_BME280 bme; //BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)

//}
//}

void setup() {
Serial.begin(115200); //Initialize serial
//initBME();

WiFi.mode(WIFI_STA);

ThingSpeak.begin(client); // Initialize ThingSpeak
}

void loop() {
if ((millis() - lastTime) > timerDelay) {

// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
  Serial.print("Attempting to connect");
  while(WiFi.status() != WL_CONNECTED){
    WiFi.begin(ssid, password); 
    delay(5000);     
  } 
  Serial.println("\nConnected.");
}

// Get a new temperature reading
int flexValue = analogRead(25);
flexValue = flexPin0;

//flexValue = analogRead(flexPin0);

//uncomment if you want to get temperature in Fahrenheit
/*temperatureF = 1.8 * bme.readTemperature() + 32;
Serial.print("Temperature (ºC): ");
Serial.println(temperatureF);*/

 
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel.  Here, we write to field 1.
int x = ThingSpeak.writeField(myChannelNumber, 1, flexValue, myWriteAPIKey);
 //int y = ThingSpeak.writeField(myChannelNumber, 1, value1, myWriteAPIKey);
//uncomment if you want to get temperature in Fahrenheit
//int x = ThingSpeak.writeField(myChannelNumber, 1, temperatureF, myWriteAPIKey);

if(x == flexValue){
  Serial.println("Channel update successful.");
}
else{
  Serial.println("Problem updating channel. HTTP error code " + String(x));
}
lastTime = millis();

}
}

1 Like

I have the same problem since March 2022. Any help appreciated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.