How to add a calibration variable into hardware code

I have added a variable x that is reading virtual pin 0 from the datastream. I am able to see the integer change in the serial monitor, but its not changing in my code. I am simply subtracting the x from the temp, but it doesnt seem to be working.

Thanks in advance



#define BLYNK_FIRMWARE_VERSION "0.0.5"
#define BLYNK_TEMPLATE_ID           "TMPLvQM2iWfK"
#define BLYNK_DEVICE_NAME           "House Automation"
#define BLYNK_AUTH_TOKEN            "V9DD9TcsN-CXuqlMSgDXJVxRgEkizT8-"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHT.h"
#define DHTPIN 5    
#define DHTTYPE DHT22 
int x;


char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "cait&caiden";
char pass[] = "Kinghenry3";



DHT dht(DHTPIN, DHTTYPE); 

BlynkTimer timer;


BLYNK_WRITE(V0)
{
  x = param.asInt(); 
  Serial.print("V0 value is: ");
  Serial.println(x);
}


void temp(){

  float h = dht.readHumidity();
  float t = dht.readTemperature(true); 
  Blynk.virtualWrite(V7, h); 
  Blynk.virtualWrite(V8, (t-x));

 
}



   

void setup(){
  Serial.begin(115200);
  dht.begin();
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000L, temp);
 }


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

Try this instead…

void temp()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true); 
  float t_adj = t-x;
  Blynk.virtualWrite(V7, h); 
  Blynk.virtualWrite(V8, t_adj);

  Serial.print("Temperature = ");
  Serial.println(t);
  Serial.print("Adjusted temperature = ");
  Serial.println(t_adj);
}

You should also add…

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);
}

this will cause the server to send the latest V0 value, triggering BLYNK_WRITE(V0)

Also, this line…

serves no purpose if you aren’t using Edgent or Blynk.Air, and these two lines…

should always be the first two lines of your sketch.

BTW, the DHT range of sensors are awful!

Pete.