Can not send float variable to Blynk IOS app

Yes, widget is on V5! It is Labeled Value widget.

I want to add 0.01 to float Result by pressing the hardware button on breadboard. I set Result to initial value = 2.

So, if i press first time I should see 2.01 in app, second time - 2.02 and so on. But I just see 2 in spite of I pressed button

If I add 1(integer) it counts in correct way and I see right result.

I think you need to post your full code (correctly formatted of course).

Pete.

Have you confirmed that your code is calculating the floats correctly by printing the result to your serial monitor?

yes, I confirm it calcs correctly.

Here is the code

#include <ESP8266WiFi.h>  
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleEsp8266.h>


const byte CounterPin = 2; 
int CounterState; 
float Result =2.00;
volatile byte interruptCounter = 0;


char auth[] = "My_Token"; 
char ssid[] = "My_SSID";
char pass[] = "My_psw";

void handleInterrupt() {
  
static unsigned long last_interrupt_time = 0; 
unsigned long interrupt_time = millis(); 

if (interrupt_time - last_interrupt_time > 500) 
{ 
  Result=Result+0.01;
  
}
last_interrupt_time = interrupt_time; 
}


BLYNK_READ(V5) 
{
  Blynk.virtualWrite(V5,Result);
}

void setup() {

Blynk.begin(auth, ssid, pass);
  
Serial.begin(115200);         
delay(10);
Serial.println('\n');
 
pinMode(CounterPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CounterPin), handleInterrupt, FALLING);

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

}
 

It never fails… almost no one reads the Welcome Topic before posting here (despite it being a universal forum requirement) so they just don’t get it :disappointed:

@bavspb I fixed your last post for you

1 Like

@bavspb

I just added in a simple test (to one of my existing projects) to emulate your count up… and it is working just fine for me in both Android and iOS on a Labeled Display Widget set for /pin.##/

float Result = 2.00;

BLYNK_READ(V18){
Result=Result+0.01;
Blynk.virtualWrite(V18,Result);
}

09 46
… and counting…

Since you are using BLYNK_READ() are you sure you set your display widget to a reading rate and not PUSH?

1 Like

I have exactly the same screen with settings as you attached besides Input. I gave V5 pin. So it should work but does not

Local Server or Cloud?

What version Blynk Library?

I use cloud

Blynk 2.23.0(4)

And?

where can I get it?

Possibly from the IDE Library manager… depending on how you originally installed it

From within the the library files themselves (OK, not as easy)

When using Blynk print, it will show in the serial monitor.

And you can even print it to a display widget with this command… Blynk.virtualWrite(vPin, BLYNK_VERSION);

Also… what version of ESP Core for Arduino? This you should be able to see in the IDE Library manager.

But all that said… if you do not know, then they are both probably too old :stuck_out_tongue:
I recommend updating them both…

thanks for detailed guiding me!

As I wrote earlier Arduino IDE board version(it was 2.4.0) and now I set up 2.4.2

I will check other stuff shortly

Ahh… yes, I glanced over that, but was looking for the word ESP CORE :blush: :stuck_out_tongue:

added newest Library but it did not help

This is interesting.
I cant get @bavspb’s code to update the labelled value widget at all in iOS, even when it’s set to 1sec refresh. It seems that the BLYNK_READ(V5) function is never being called (this is using the Blynk Cloud servers).

If I move the Blynk.virtualWrite(V5,Result); command out of BLYNK_READ(V5) and into the interrupt function then it obviously works fine (including decimal places).

As @Gunner knows, I’m not really one for using Blynk like this, so my knowledge and experience of using the BLYNK_READ function is non-existent, but maybe this is an issue with the iOS version of the app?

My test setup:
Arduino IDE v1.8.7
ESP Core 2.4.2
Blynk library v0.5.4
iOS App 2.23.0(4)
Wemos D1 Mini
IwIP Variant v2 lower memory
Blynk Cloud Server 139.59.206.133 (Ping around 50ms)

This is the working (and tidied-up) version of @bavspb’s code…

#define BLYNK_PRINT Serial // Added so that you can see the Blynk messages

#include <ESP8266WiFi.h>
//#include <ESP8266WiFiMulti.h> // Not Needed!
//#include <ESP8266mDNS.h>      // Not Needed!
//#include <ESP8266WebServer.h> // Not Needed!
#include <BlynkSimpleEsp8266.h>

const byte CounterPin = 2;
//  CounterState; // Not Used!
float Result = 2.00;
// volatile byte interruptCounter = 0; // Not Used!

char auth[] = "REDACTED";
char ssid[] = "REDACTED";
char pass[] = "REDACTED";

void handleInterrupt()
{
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();

  if (interrupt_time - last_interrupt_time > 500)
  {
    Result = Result + 0.01;
    Serial.println(Result); // Added serial print of Result
    Blynk.virtualWrite(V5,Result);   // Virtual Write moved to here, won't flood because of 500ms check
  }
  last_interrupt_time = interrupt_time;
}

//BLYNK_READ(V5)  // Moved your Virtual Write to the interrupt function above
//{
//  Blynk.virtualWrite(V5,Result);
//}

void setup() {
  Serial.begin(74880); // Changed baud rate to 74880 so you can see the boot messages from your ESP
  Blynk.begin(auth, ssid, pass); // Moved this to after the serial begin so you can see the Blynk messages
  
  //delay(10); Not Needed!
  Serial.println('\n');
  pinMode(CounterPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(CounterPin), handleInterrupt, FALLING);
}

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

Pete.

Well… I don’t know what else you might be doing… you have some strange code in your sketch… at least for the simple task you are doing…

I don’t see your confirmation serial print commands

And since you are not apparently using any other Blynk functions… are you sure you are even connected and actively communicating??

I would activate DEBUG and possibly set up more serial print commands to check your code flow

FYI, just in case you didn’t know… BLYNK_READ() requires the corresponding widget to be set to a reading rate, as then the widget determines the timing of the function call.

Yep. I worked that one out :angel::angel::angel:, but it doesn’t work…

I tried putting a serial.print statement in the BLYNK_READ function and with the corresponding widget set to 1 Sec the message never appears on the serial monitor. I’d expect 1 message per second, but it doesn’t happen.

Pete.