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();
}
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.
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.
I put attention to anything that might add to the conflicts… standard troubleshooting 101… start dirt simple then add in the bells and whistles a step at a time
Can you send and see floats in any other configuration??
Add in my little example on another display widget & vPin for example
Setup a step widget with float resolution and send the manually adjusted data to another display widget on same vPin (don’t even need to add code for this)… and so on.
That’s why I left them in there, just commented-out.
My approach to troubleshooting is to remove all of the unwanted/unnecessary stuff, so that there’s no chance of odd interactions and side-effects.
Just checked, BLYNK_READ works fine for me.
Double check you have the correct REFRESH INTERVAL setting saved in Widget settings (it automatically switches to Push when virtual pin is selected).
Just tried widget GAUGE and it works with float!!! Later I came back to Value gadget and it was working as well. That was really strange problem. THANK YOU ALL!
BTW, I removed button and connected deem switch(water counter) and ESP-01 failed in load immediately. Deem switch has 5,5kOm and 1,5kOm once it send an pulse(connected). Any ideas why ESP failed when water counter is connected? I do not see a difference in connection button and deem switch(inside the counter)