BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to make Blynk override programmed functions?


#1

I’m curious to know how this would be possible. I have a project that is increasing with time and money, and I have a functional sketch that toggles relays based upon time or temp/humidity. I also have the hardware (Arduino Mega/Ethernet) printing RTC and sensor readings to a Blynk LCD in my app.

Through experimenting, I’ve found that a Blynk command from a button widget will override the sketch program, but with the next cycle of the loop, the sketch reverts the state from Blynk’s command, back to the programmed behavior.

What I want to now do is code it in such a way that “if Blynk issues a command that contradicts the sketch, prioritize Blynk”.

Any ideas? I’m only a half a newb, but I still don’t know how to begin researching this.


#2

Have you read about the Blynk.syncVirtual() and Blynk.syncAll() functions? They make sure your sketch and App are up to speed on the latest settings.

I’d rather make sure everything is OK than give certain inputs or outputs priority. This can lead to unexpected results which will make you pull out your hair in the end :slight_smile:


#3

Thanks Lichtsignaal, I will research the sync calls and how they can be worked into my sketch. My project is a hydroponics controller, and the devices in question are water pumps that are generally coded for timed events. When these pumps don’t run, the sketch issues “off” commands which would contradict the incoming “on” command from blynk which would otherwise leave me needing to re-tick the button in my blynk app. If the blynk buttons were given priority over the “off” commands in the sketch, the pump would stay on and get done what I want done.


#4

Hmm, sounds a bit complicated to me. Isn’t it better to re-write the sketch so Blynk is always in control? You can use timers in Blynk too. That way you can always be sure Blynk has control and not “some other” factor :slight_smile:


#5

I only wish to give priority over certain devices (relays) so rewriting the sketch would become impractical.


#6

In reality, this isn’t really a Blynk (app) vs Sketch issue, Any method of externally controlling a sketch should have sketch authority, in as such that “Blynk” could be replaced with “Push button to open elevator door, but even if elevator is not there override and open door”… potentially not a good thing.

Blynk is primarily a remote control conduit for hardware, but as Blynk (app) is susceptible to being disconnected from the link, then the hardware (sketch) should always have the priority.

This has already been determined in other issues wherein connection was lost and hardware stopped working because blynk.begin() became a blocking function, prevented a sketch from running until reconnected. The solution for those that needed it was alternative code using blynk.config() and other commands, to give the sketch primary authority on when/if to run.

Another example is when using Blynk to control a robot, with Blynk being the primary, meant that loss of connection potentially has a moving robot on the loose. Solution is again, sketch priority to make decision based on available (or lack of) communication.

Blynk’s promotion of no coding or limited coding required is only true on the most basic of use cases. More complicated logic control still requires finessing the sketch code into doing what you require.

I feel you will be best suited to map out your infrastructure and sketchflow, with priority on the sketch side, so that if a Blynk (app) button says ON, but pumps don’t run… the sketch determines WHY they don’t run and provides feedback or an alternative function instead of forcing the app button priority.


#7

Once you have made your modifications, especially if you are having difficulties with something, please post your formatted code >see here< so others can assist.


#8

My sketch and related project is a work in progress. It was the desire to build an all inclusive hydroponics controller that got me into microcontrollers, coding and circuit building. I have been at it now for roughly 2 1/2 years. I have learned a lot, though still need to learn more. I discovered Blynk roughly a year ago and have also made great things happen in my sketch. I use a hardware RTC instead of Blynk’s widget and also use 2 temp/humidity sensors and pass the data to Blynk app. Last night I learned how to forward my Serial.print statements with terminal.print. I am new, though not yesterday new, and TBH, learning how to graft Blynk concepts in my code adds to the difficulty of teaching myself all of this, none the less I am severely determined and will punch through every problem I encounter regarding this project.

I believe I asked a question and the very next reply gave me the location of the best place to start digging, and dig I shall!

Thank you all for the tips!

Edit - HERE is what my project and code looked like last year, EEEK!!! One foot in front of the other…


#9

Oh do I understand that… I have only been using Blynk for a few months and Arduino for a couple years, but with a year+ long hiatus until finding Blynk and getting back into both. Then just in case I wasn’t over my head enough, I stuck my head into the Linux’s mouth :stuck_out_tongue: with RPi and Blynk. Ah well.

But having a solid project really helps keep the motivation going. I looked at your past posting and it was nice to see someone using “proper” :wink: AC plugs for once.

…I especially like the finger accessible “Is power ON/OFF?” test points :stuck_out_tongue_winking_eye:


#10

At the time of that photo, the power was off, I verified this with the wet finger test, lol :laughing:

I also have been “in” and “out” of my studies and have also been down similar roads as you. I purchased (but never went much further) a Udoo board which is a combo of Rpi and Arduino Due (Mega pinout w/ 3v3 logic running Ubuntoo), but have found 5 volt logic easier for a newb to work with and learn with.

My project has also evolved dramatically in that I took the advice of an arduino,cc member relocated the MC into it’s own project box (away from the AC switching).