My data in thingspeak are not same as in Blynk using webhook

I have problem to display my data in thingspeak


the data are not same as in my serial monitor

Hardware use:
1- Esp 32
2- MQ 135, MQ 7, MQ 4, MQ 8 (GAS SENSOR)

This is my coding

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "jO6eiUFb7TYwBGjUEp5YmYMc3FRolDP7";
char ssid[] = "nino_ai";
char pass[] = "faris2210";

int redLed = 5;
int yellowLed = 17;
int greenLed = 16;

int gas1 = 33;
int gas2 = 32;
int gas3 = 35;
int gas4 = 34;

int analogSensor1 = 0;
int analogSensor2 = 0;
int analogSensor3 = 0;
int analogSensor4 = 0;
BlynkTimer timer;

void setup()
{
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(gas1, INPUT);
  pinMode(gas2, INPUT);
  pinMode(gas3, INPUT);
  pinMode(gas4, INPUT);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  digitalWrite(redLed, 0);
  digitalWrite(yellowLed, 0);
  digitalWrite(greenLed, 0);
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(5000L, SendToThingspeak);
}

void myTimerEvent()
{
  Blynk.virtualWrite(V1, analogSensor1);
  Blynk.virtualWrite(V2, analogSensor2);
  Blynk.virtualWrite(V3, analogSensor3);
  Blynk.virtualWrite(V4, analogSensor4);
}

void loop()
{
  Blynk.run();
  timer.run();
  analogSensor1 = analogRead(gas1);
  analogSensor2 = analogRead(gas2);
  analogSensor3 = analogRead(gas3);
  analogSensor4 = analogRead(gas4);

  Serial.print("Sensor 1: ");
  Serial.println(analogSensor1);
  Serial.print("Sensor 2: ");
  Serial.println(analogSensor2);
  Serial.print("Sensor 3: ");
  Serial.println(analogSensor3);
  Serial.print("Sensor 4: ");
  Serial.println(analogSensor4);
  Serial.println();
  delay(100);

  if ((analogSensor1 > 100 && analogSensor1 < 500) && (analogSensor2 > 100 && analogSensor2 < 500) && (analogSensor3 > 100 && analogSensor3 < 500) && (analogSensor4 > 100 && analogSensor4 < 500))
  {
    digitalWrite(redLed, 0);
    digitalWrite(yellowLed, 0);
    digitalWrite(greenLed, 1);
  }

  else if ((analogSensor1 > 500 && analogSensor1 < 1500) && (analogSensor2 > 100 && analogSensor2 < 500) && (analogSensor3 > 100 && analogSensor3 < 500) && (analogSensor4 > 100 && analogSensor4 < 500))
  {
    digitalWrite(redLed, 0);
    digitalWrite(yellowLed, 1);
    digitalWrite(greenLed, 0);
  }

  else if ((analogSensor1 > 1500 && analogSensor1 < 3000) && (analogSensor2 > 100 && analogSensor2 < 500) && (analogSensor3 > 100 && analogSensor3 < 500) && (analogSensor4 > 100 && analogSensor4 < 500))
  {
    digitalWrite(redLed, 1);
    digitalWrite(yellowLed, 0);
    digitalWrite(greenLed, 0);
  }
}

void SendToThingspeak()
{ 
  Blynk.virtualWrite(V0, gas1, gas2, gas3, gas4);           
}

Thats all thankyou
Hope for fast respomse

First of all, your void loop is terrible, and not compatible with Blynk. You should read this then restructure your code:
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Secondly, this piece of code is taking readings from your sensors and saving them in variables called analogSensor1 , analogSensor2 etc

but this piece of code is sending the value of variables gas1, gas2 etc to the Blynk webhook widget and presumably on to Thingspeak:

The variables gas1, gas2 etc are what you are using to hold the GPIO pin numbers that your sensors are connected to:

This is why the Thingspeak charts are showing values of 33, 35 & 34. The chart that should be displaying the value 32 (chart 2) is blank, because you’ve made a mistake with your Blynk webhook setup in the app, or in Thingspeak.

As you’ve chosen not to hide your Blynk auth code in the code that you’ve posted, it’s possible for anyone reading this to view the setup of your project on the Blynk cloud server, and it shows that the error is in the way that you’ve set-up your webhook in the app:


You have an extra ampersand, circled in red, in your webhook setup.

You now obviously need to change your Blynk auth code and you Thingspeak API key, as anyone can now post data to both if they wish.

Pete.

thank you so much Pete
Im gonna try correct it


I already correct the mistake but only 1 data has been sent into the Thingspeak

This is my current coding

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = " jO6eiUFb7TYwBGjUEp5YmYMc3FRolDP7";
char ssid[] = "nino_ai";
char pass[] = "faris2210";

int redLed = 5;
int yellowLed = 17;
int greenLed = 16;

int gas1 = 33;
int gas2 = 32;
int gas3 = 35;
int gas4 = 34;

int analogSensor1 = 0;
int analogSensor2 = 0;
int analogSensor3 = 0;
int analogSensor4 = 0;
BlynkTimer timer;

void setup()
{
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(gas1, INPUT);
  pinMode(gas2, INPUT);
  pinMode(gas3, INPUT);
  pinMode(gas4, INPUT);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  digitalWrite(redLed, 0);
  digitalWrite(yellowLed, 0);
  digitalWrite(greenLed, 0);
  timer.setInterval(5000L, sensorDataSend);
  timer.setInterval(5000L, SendToThingspeak);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void sensorDataSend()
{
  analogSensor1 = analogRead(gas1);       // reading sensor from analog pin
  Blynk.virtualWrite(V1, analogSensor1);  // sending sensor value to Blynk app
  analogSensor2 = analogRead(gas2);
  Blynk.virtualWrite(V2, analogSensor2);
  analogSensor3 = analogRead(gas3);
  Blynk.virtualWrite(V3, analogSensor3);
  analogSensor4 = analogRead(gas4);
  Blynk.virtualWrite(V4, analogSensor4);
}

void SendToThingspeak()
{ 
  Blynk.virtualWrite(V0, analogSensor1, analogSensor2, analogSensor3, analogSensor4);    
}      

This is inside my webhook
Is it should be empty in the body part?

Your webhook was working earlier, apart from the extra ampersand, the problem was with the data that you were sending it from the MCU.

Pete.