Int vs var,

Hi,

I’m using sparkfun blynk board together with ds18b20 temp sensors.

And i have two situations:
with this row in code, on terminal and blynk apm i’m reciecing integers of temperature.

 int temp = (sensors.getTempC(sensor1));

and if im changing int to var im recieving numberers with decimals on terminal, and ,%f3 (like some error) on blynk app

 var temp = (sensors.getTempC(sensor1));

I’m prefer to recieve temperature with decimals.

all code

// https://randomnerdtutorials.com/esp32-with-multiple-ds18b20-temperature-sensors/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

char auth[] = "6449734381964f98a85f6bfa2f29d9ca";
char ssid[] = "default";
char pass[] = "";
BlynkTimer timer;

void myTimerEvent()

{
  DeviceAddress sensor1 = { 0x28, 0xD3, 0x26, 0xE7, 0x07, 0x00, 0x00, 0x52 };
  sensors.begin();
  sensors.requestTemperatures();
  int temp = (sensors.getTempC(sensor1));
  Blynk.virtualWrite(V5, millis() / 1000);
  Blynk.virtualWrite(V6, temp);
  Serial.println(temp);
}

 void setup()

{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);

}

void loop() 
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer  
}
void loop()

Google My Friend.

https://www.arduino.cc/en/Reference/VariableDeclaration

I’m just very basic programmer, only i can do is copy and paste, and combine different sketches.

Blynk declares, that if your sketch is working fine without blynk, it will work then with it.

But in reality you need to bee more advanced to do even simple projects.

Not sure where you read that. BLYNK can usually be easily adapted to most sketches. Typically this involves clearing out the loop() and implementing timers.

A good place to start is HERE, and work through the examples in the sketch builder. Most of those example provide a good template for getting things going, and can easily be combined to create more advanced sketches. Also, there are a ton of example that you can copy and paste from on this forum, you just have to search around a bit and look for what you need. If you get stuck on something, just post the code(properly formatted that is) you have attempted to make work with BLYNK on this forum, and usually people will try to do their best to help.

“var” isn’t a variable type in C++, so if that’s the only change you’ve made to the code you posted it won’t compile. It will give an error that says “‘var’ does not name a variable type”.

If you’re seeing this error, you may not be using the latest Blynk library and ESP core. See this thread:

If you want temperature values that include decimal places then you should go for a float variable type, not an int (but you’ll have learned that already if you’ve followed the link that @Toro_Blanco gave you and studied the information).

Pete.

2 Likes

My wonder is, because in both ways on terminal monitor i’m recieving data. But only in one way blynk is working. Later i will play a bit more with the code.

Thank you