ThingSpeak code is not working

My code is not sending data to Thingspeak can anyone help me?

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>

#define ANALOG_IN_PIN A0

const char *ssid = "Telenor 4G-EF7E";
const char *password = "65802165";
const char *thingSpeakApiKey = "47JINVXT89DJ4IOA";
const unsigned long myChannelNumber = 2535942;

float R1 = 30000.0;
float R2 = 7500.0;
float ref_voltage = 3.3; // Updated to 3.3V for ESP8266

WiFiClient client;

void setup() {
  Serial.begin(9600);
delay(1000);
WiFi.begin(ssid,password);
Serial.print("connecting to WIFI");
 Serial.begin(9600);

  delay(100);
// meowww meowww meowww meowww
while (WiFi.status() != WL_CONNECTED)
{
  delay(1000);
  Serial.print(".");
  Serial.println();
  ThingSpeak.begin(client);
}
// written by Adrian Agreste

}

void loop() {
  // Check WiFi connection and reconnect if needed
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi not connected, attempting to reconnect...");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println(" Reconnected!");
  }

  float temperature1 = NAN, temperature2 = NAN, temperature3 = NAN;

  // Check if Serial data is available
  if (Serial.available() >= 16) {
    temperature1 = Serial.parseFloat();
    temperature2 = Serial.parseFloat();
    temperature3 = Serial.parseFloat();

    while (Serial.available() > 0) {
      Serial.read();
    }

    int adc_value = analogRead(ANALOG_IN_PIN);
    float adc_voltage = (adc_value * ref_voltage) / 1024.0;
    float in_voltage = adc_voltage * ((R1 + R2) / R2);

    // Print values to Serial Monitor for debugging
    Serial.print("Temperature 1: ");
    Serial.println(temperature1);
    Serial.print("Temperature 2: ");
    Serial.println(temperature2);
    Serial.print("Temperature 3: ");
    Serial.println(temperature3);
    Serial.print("ADC Value: ");
    Serial.println(adc_value);
    Serial.print("ADC Voltage: ");
    Serial.println(adc_voltage, 2);
    Serial.print("Input Voltage: ");
    Serial.println(in_voltage, 2);

    Serial.println("Updating ThingSpeak fields");

    ThingSpeak.setField(1, temperature1);
    ThingSpeak.setField(2, temperature2);
    ThingSpeak.setField(3, temperature3);
    ThingSpeak.setField(4, in_voltage);

    int response = ThingSpeak.writeFields(myChannelNumber, thingSpeakApiKey);
    if (response == 200) {
      Serial.println("Data sent to ThingSpeak successfully");
    } else {
      Serial.println("Failed to send data to ThingSpeak");
      Serial.println("Response Code: " + String(response));
    }
  } else {
    Serial.println("No valid serial data available");
  }

    
  delay(15000); // Increased delay to 15 seconds for reliable updates
}

Was the WiFi board recognized by the Arduino?
Did the WiFi connect?

yes its connected
watch esp

Did you let this thing write your program?


made my own templates it works with one senor but not working with multiple

I do not know about ThingSpeak. Have other projects of yours used multiple sensors?

Once I used 3 thermistors and 1 voltage sensor at time on NANO and then connect RX and TX pins with Node MCU and then it uploads data but now its not working.
Even yesterday I take help from Chat GPT but it was nothing positive response
CHAT GPT

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include<ThingSpeak.h>
#include <ESP8266WebServer.h>

const char* ssid = "😹😹😹😹";
const char* password = "***************************";
const char* server = "api.thingspeak.com";
const char* apiKey = "ZTHF537GWI5DEM0N";

WiFiClient client;

void setup() {
  Serial.begin(9600);
  delay(15000);
  
  // Connect to Wi-Fi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(15000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
}
void loop() {
  // Variables to store temperature values
  float temperature1 = 0.0;
  float temperature2 = 0.0;
  float temperature3 = 0.0;

  if (Serial.available() > 0) {
    String data = Serial.readStringUntil('\n'); // Read the incoming data as a string

    // Parse the incoming data assuming it is in the format "temp1,temp2,temp3"
    int commaIndex1 = data.indexOf(',');
    int commaIndex2 = data.indexOf(',', commaIndex1 + 1);

    if (commaIndex1 > 0 && commaIndex2 > commaIndex1) {
      temperature1 = data.substring(0, commaIndex1).toFloat();
      temperature2 = data.substring(commaIndex1 + 1, commaIndex2).toFloat();
      temperature3 = data.substring(commaIndex2 + 1).toFloat();

      // Update ThingSpeak fields
      ThingSpeak.setField(1, temperature1);
      ThingSpeak.setField(2, temperature2);
      ThingSpeak.setField(3, temperature3);

      int updateRes = ThingSpeak.writeFields(123456, apiKey); // Replace 123456 with your Channel ID
      if (updateRes == OK) {
        Serial.println("ThingSpeak update successful");
      } else {
        Serial.println("Error updating ThingSpeak");
      }
    } else {
      Serial.println("Error parsing temperature data");
    }
  }

  delay(15000); // ThingSpeak allows updates every 15 seconds (900ms min delay)
}

You have changed something that was necessary. Use the working sketch to discover the problems.

Probably not.

Difficult but I thinK parsing data is solution

brother you have two Serial.begin() and why

is while loop put it outside loop and inside setup

how you separate 3 sensors, you just giving one value to all .By the way can you share the output you receiving through serial monitor