Is there a way for a program to request a widget's state?

I wrote a thermostat sketch to control my apartment’s HVAC with an ESP8266. It seems to be working fine, but there’s one problem. I can’t figure out out to poll the Blynk app on startup to retrieve the temperature that I’ve set. I have a slider widget with which II can set a desired temperature of between 50 and 75 degrees F. That desired temperature is compared to the actual temperature from a DHT11 sensor. Unfortunately, the sketch doesn’t have access to the state of the slider unless / until the slider is CHANGED. In the case of a restart, there’s no way to have my sketch ask if I left the slider on 65 or 70. Have I missed something really obvious?

As I understand it, BLYNK_READ() and BLYNK_WRITE() take care of widget-initiated data input and output with the sketch, respectively. Blynk.virtualWrite() takes care of sketch-initiated output to the a widget. However, there doesn’t seem to be any method for sketch-initiated input from a widget. Logically, this would be the elusive Blynk.virtualRead() statement. A little help, please. :confused:

2 Likes

one of the possible way is to store the received temperature value in EEPROM.

So even after restart of the HW the set value is still available in EEPROM.

Thanks, @RaPo. I’m already using the EEPROM to store settings that are less prone to change (e.g. hysteresis settings, sensor calibration offset). However, I’d like to avoid writing frequently changing data to the EEPROM, if possible. As I understand it, EEPROMs have a limited life, and the ESP8266’s is lower than most.

@chrome1000 if I understood you correctly you need something like that?

@Dmitriy The link sends me to the “Arduino over USB” section of the documentation page. In any case, I’ve searched that page several times for this capability, and can’t seem to find it. Let me simplify my example.

Let’s say I’ve created a dashboard with just a the slider widget, and set that slider to pin V1. I’ve initialized a variable in my code called “MyVar”. My code is now running, and I move the slider in the Blynk app to the “100” position. On my hardware, the following code is activated by that change, and MyVar receives the new value of 100.

BLYNK_WRITE(V1) {
MyVar = param.asInt();
}

Now, I restart my hardware. MyVar is re-initialized, and hasn’t yet been assigned a value. What I’d really like it to do is to tell the code to “look” at the slider position in the Blynk app (which is still at 100, where I left it), so that I can assign that value to MyVar again. The BLYNK_WRITE code above won’t do that, because it only sends a value to the hardware when there’s a CHANGE in the slider.

What would I have to put into my code to retrieve the value of V1 on startup of my hardware?

2 Likes

Clear. Thanks for good explanation. Yes, at the moment this is a problem and no way to resolve it with Blynk directly. But we are aware of it. We plan to fix this after Sharing and Bluetooth features.

3 Likes

And with buttons is the same storry! If I have virtual pin which send value from app to arduino and if I can change that value with phisical button I would like to see changes on app too. For example I have connected to arduino room light and room light phisical wall button and I can switch on and off room light with phisical button and with app, and if I switch on light with app then on app switch shows that it is on and if I switch that light off with phisical room switch on app switch still show that it is on, but on reality it is off. It was be greate if app switch show real status, so that mean button need not just write state to the hardware but read too from hardware!

1 Like

Yes. Agree. This will be next big step for Blynk. We build Blynk based on Blynkers feedback. At the moment most requested features are Sharing and Bluetooth. So please be patient. We do our best.

3 Likes

Chrome100 - I agree - BUT I don’t think the ESP Flash (it’s not EEPROM) lasts less than most. I have a block I write to in order to save settings with my various projects - along with the SSID etc etc,I write to it several times a day and in something like a year I’ve never damaged a board. I think writing the state of buttons is likely fine - the issue would be writing the state of the likes of the zeRGBa which updates rather too frequently.Maybe a timer to update a block of controls after a second or so of no change?

1 Like

so what ever happened to virtualRead()? I had asked you about that way back on March 30.
Thanks

Also, back in april we discussed this issue of having blynk reflect the status of real world switch. Light switch turned on, blynk switch updates to on. This way you know what the state of the switch is when using the app.

“This is a great comment. We should definitely take it into production. Adding the rest of the team here. Thanks, Brian.”

Any update on the status of this?

Thanks!