I canot Gets data From Blynk To The Device

Hi everybody! please help!
i try to use INA and esp8266 to measure voltage and current values, control max current or max voltage. When I turn on or off the CVmode switch, change the slide value, nothing changes, it always shows cvmode=1, Slide value=0. Why???

• ESP8266 with INA219
• Blynk APP on Smartphone OS (iOS 3.5.4 and Android 1.9.1(122))
• Blynk Library version 1.2.0
• My sketch code is like that.

[Code deleted at the request of @thanhviet228]

there is my dashboard and datasteam

Can you post screenshots of how you’ve set-up your switch and slider widgets?


yes, here is my setup

You provided a screenshot of your mobile dashboard, but when I asked for details of how you’ve configured these widgets you’ve provided a screenshot of the web dashboard widgets.


I’m sorry. they are exactly the same

Okay, there’s a few things wrong…

1 - Variable Scope

You have cvmode defined as a global variable of type Integer at the top of your code…

but you are then declaring a local integer variable with the same name inside your BLYNK_WRITE(V7) callback…

This means that the local version of cvmode isn’t visible outside of BLYNK_WRITE(V7).
To fix that, change your BLYNK_WRITE(V7) to this…

  cvmode = param.asInt(); // <<< `int` removed from beginning
  Serial.print("V7 cvmode value is: ");

You also need to do the same thing with setpercent which you are re-declaring as local within BLYNK_WRITE(V8)

2 - Difference between “=” and "=="

In void ina219values() you have this…

The problem is that if (cvmode = 0) should be if (cvmode == 0)
and if (cvmode = 1) should be if (cvmode == 1)

When you use cvmode = 0 it means “set cvmode to 0”, so cvmode is being set to 0, then in the next piece of code it’s being set to 1 - which is why cvmode is always 1 in your serial monitor.

Double equals signs ("==") means “compare the two values” so if(cvmode==0) means "compare the current value of cvmode and 0, if they are the same then the if statement evaluates as true"


1 Like

Thank you very much. I did exactly as you said and it worked perfectly.
Thank you all for creating this great forum.

1 Like

can you delete my code ? i don’t want my source code to be copied.

I’ve deleted your code on this occasion, but I seriously doubt that anyone would want to copy it as it’s so badly written.

Bear in mind for the future that this is a public forum, so code or other information posted is being placed in the public domain.


1 Like