parseInt in virtual pin

Hi guys. I have a problem with showing paresInt to virtual pin (V2). the problem is Decimal numbers not showing correctly. For example, instead of displaying the number 20070.84, it incorrectly displays the number 8420070.

thanks for any help.

the sketch:

#include<SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

SoftwareSerial period(4, 5);
SoftwareSerial periodavg(12, 14);

BlynkTimer timer;

int age1;
int age2;

char auth[] = "WJz71rs0YRqdaZ9oh1VysC_rjvwwx4Re";
char ssid[] = "MikroTik";
char pass[] = "12345678";
char server[] = "10.5.51.5";

void setup() {
  Serial.begin(9600);
  period.begin(9600);
  periodavg.begin(9600);
  Blynk.begin(auth, ssid, pass, server, 8080);
  timer.setInterval(1000L, pw);
  timer.setInterval(1000L, pa);
}

void pw() {
  age1 = period.parseInt();
  Blynk.virtualWrite(V1, age1);
  Serial.println(age1);
}

void pa() {
  age2 = periodavg.parseInt();
  Blynk.virtualWrite(V2, age2);
  Serial.println(age2);
}

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

Try float instead of int. Using int value will always round the value downwards, so 8420070.84 will be 8420070.

1 Like

thanks for reply. I tried with float but it did not changed.

Have you tried parseFloat ?

1 Like

Oh thanks. the problem is solved with parseFloat and Serial.println from sender side.

1 Like