I’m using Blynk to create a user interface app for a device that I’m prototyping. I’m making several copies of the same device so I’m cloning my Blynk project to make an individual user interface for each prototype device. In my project I’m using the Numeric Input widget to define a limit for a particular value and after cloning the project and setting up a new device my hardware does not seem to be getting a value from my Numeric input. If I change the numeric input value on the app the hardware gets an updated value, but until I touch the + or - the hardware does not have a value. I am syncing all pins when Blynk connects, and I have a BLYNK_WRITE function for the virtual pin that the numeric input is connected to. Relevant code should be below.
For example, I clone my project and the new project shows a value of -1 for the numeric input widget. I download code to the particle photon with the new authorization key for the project. The code on the hardware runs and connects to the blynk server, some stuff happens, and instead of my Limit being -1, it’s 0. I’m not sure if I’m not syncing the virtual pin properly or if the widget isn’t being initialized since it’s a cloned project.
Cloning copies the primary widget settings like Min/Max, vPin, labels, NOT the user adjustable stuff like Button state, Slider position, Numeric input setting, etc. This includes any Min/Max, etc. settings that get set by the device script Blynk.setProperty()… they will not be set until the device connects and runs.
If it is the in-App-set Min/Max that you are referring too… then that might be a bug? as that is a newer widget.
The Android and iOS apps are up to date. The Numeric input widget has a min set to -1, and max set to 0, along with a step of .01. All those settings are copied correctly when cloning and it appears to default to displaying the minimum value, which in this case is -1.
I can try setting the properties for the widget in the code running on the hardware. Should I set those properties in my initial setup function after calling Blynk.begin()?
I agree… depending on how many vPins you really need to sync, I have found individual Blynk.syncVirtual(vPin) ir even nested sync like Blynk.syncVirtual(vPin, vPin, vPin) is more reliable as syncAll seems to hit everything at the same time and has caused me issue in larger cases.
I’m sorry I wasn’t clear, the app is displaying -1 after cloning, but after syncing the hardware does not have the “Limit” as -1, the “Limit” is just 0 when I print it out since the value hasn’t been initialized.
Costas,
I was previously syncing just the pins I needed to sync with Blynk.syncVirtual(vPin). I copied my sync code in below which shows the different sync commands I’ve tried and then commented out. I started out calling each pin, then I tried calling each pin in one command, and then as a last resort I tried the Sync all.
I made a simple program that demonstrates the problem.
The Blynk app consists of a Numeric Input widget on pin V0, minimum set to -1, maximum set to 0, and step set to .01. I have a value display on pin V1 set to Push. I have a LED on pin V2.
If you create that Blynk app and download the code below to a particle photon, once the code is running the LED will be blinking every second, the Numeric input will display -1, and the value display will show 0. It stays that way until you increment the numeric input. As soon as you tap the + or - the value display will now start to match the numeric input. It will also sync properly if you turn the particle off, change the value in the app, and then turn the particle back on. As far as I can tell, the sync is just broken until the value is changed.
I think it has to do with the fact that until a button is pressed on the app, the value of V0 on the server is 0. That is, without pushing the button on the app, you have not written anything to V0, so it is its default value of 0.
Since your numeric input widget seems to always start at -1 when first created, you may be able to just assign Limit as -1 so that upon first boot they match. float Limit = -1;. Then once a value has been written to the server, it will override this value if rebooted.
This is because you have now written a value to V0 on the server.
Assigning an initial value in the code is certainly a fine possibility and I can push that value to the Numeric input. But I still think there’s a problem overall since the value displayed in the widget does not match the server.
It does match the server. Since you have not written a value to V0 by pressing the numeric input widget, the value of V0 is 0.
I suspect the issue only happens when you first create and run the app. Once you have fiddled with it, it seems to work properly?
Try this, before booting the board for the first time, change the numeric input from -1 to any value and then back again to -1. Then boot the board. I suspect it will appear to work as you think it should. That is because you have changed the default value of V0 on the server.
You are correct, once you change the value by pressing +/- on the numeric widget the value on the server now matches what the numeric widget displays. The problem I have, which I would consider a bug in Blynk, is that until you press +/- the value on the server is 0 and if you’ve set your minimum in the widget to something other than 0, the value the widget is displaying does not match the value on the server. They should always match.
I think the issue is that BLYNK must decide on a default value for the virtual pins on the server, and to me 0 seems logical. BLYNK has no way of predicting what widget will be assigned to a virtual pin, and if a numerical input, what the minimum value may be.
Just because it does not do what you expect it to do, I would not say that it is a bug. It may be able to be improved by having a numeric input write its minimum value to the sever upon starting of the app since that seem to be where it starts when created. But I don’t think the fact that it doesn’t do that is a bug.
Since we can predict the way the widget behaves (that is, it starts at its lowest value), I think there are many ways we can get it to do what we want. Like assigning this value to the variable in the program, or using BLYNK_APP_CONNECTED()