Is my project too complex for Blynk controls?

Hi all,

I have a very simple water moisture project. I have a sensor connected to an ESB8266 and I can read the values fine. Now this is what I’m trying to build:

  1. Show sensor value in a Gauge. Working fine
  2. Get user input as a number by using a Slider
  3. Using an Eventor, compare sensor value (from Gauge) with user selected value (from slider)
    4.1. If sensor value is below, then send an email and phone notification

I can’t seem to find a way for the Eventor to cover this scenario. Is this combination possible? Or should I change the logic and data sources? How would you do it?

Cheers,
Cheese

This is very simple without “eventor”. Play with get data sketch. (In the sketch builder above) Once you have the slider value in an int compare it with your soil moisture int.

1 Like

Thanks. I was hoping to avoid code and leave the device fairly generic. But if that’s the only way, then I can put up with it. So you’re saying to code the logic on the device, but where will the notification come from? I mean what will trigger the event, and what will actually send an email or notify on the phone?

@Cheese A bit of background would maybe help us… how long you been playing with Arduino? You have history with C++? You have a few years on a computer? (PC) Ever wondered or thought about what happens when you click on something?

The notification can be an email, or a Blynk notification which pops-up on the home screen of your phone (or both), or a Twitter tweet - the choice is yours.

The notification trigger will occur when the criteria you define in your code are met. You would probably have a timer that reads the temperature from your sensor every 10 seconds or so, and compares it to your target temperature (which comes from the slider). As you wouldn’t want to keep getting alerts every 10 seconds while the temperature is above target, you’d have a flag in your code that is set to true when the alert is sent, then set to false when the temperature falls below the target.

In reality, if this is a heating system then you’d turn off the relay controlling the heater, or if it was a greenhouse then you’d automatically open the vents to allow the heat to escape.

Pete.

If you got the gauge and sensor to work you obviously put some code on so it is not generic anymore…

Now all you need to add is an integer variable that store the slider value and a timer that compares it with your temperature.

EDIT: Again Pete explains it better :point_up_2: up there.

Actually I literally flashed it with the WIFI and blynk auth code. Nothing else. No other logic of any sort. So then it can just connect the moisture sensor to it, open the Blynk app and view the value from that specific pin. That’s what got me wondering how generic I could make the Node MCU (it was a little challenge for myself)… I’m totally comfortable with coding as I’m from IT consulting and development background. But knowing how to write code doesn’t mean it’s a good idea to do so. :slight_smile:

Also @PeteKnight, I appreciate your response and it makes sense, though I’m a full bottle about those ideas. so let’s go right to the details…

  • Is the Eventor the wrong thing to use to compare the value of a pin and an in-app control? Byt the sound of what you guys are saying, I need to send back the value to the Node MCU and run the logic there.
  • I just read the Notification control instructions and I think I misunderstood this before too. Am I right to say that it’s the code in the Node MCU that needs to make a Blynk.notify call and send a notification?

Yes, absolutely. Forget Eventor.

That’s a rather strange way to view the process. The sensor is connected to the NodeMCU and the code is running on the NodeMCU. The sensor is read by the code and the logic applied within the code.
The results are then sent to the app (it’s much better to do this with Virtual pins) and to the serial monitor as well if you wish.

Pete.

Edit: adding Thanks Pete! :slight_smile:

Ah I think you forget that I need an input on the app where the user defines a custom threshold. So in my case a slider on the app where I set to say, 50. Then when the sensor value goes below 50, it sends a notification. So sensor is connected to the Node MCU, threshold Slider is on the app.

No, I’m not forgetting that.
The slider should be attached to a virtual pin. When it changes then this will trigger the BLYNK_WRITE(Virtual PIN number) callback, which allows you to save the value from the slider to a variable.
The code will read the sensor, compare it to the stored slider value and apply the logic.

There are a ton of thermostat code examples on the forum, do a search and study them, or look at some of the sketch builder examples.

Pete.

Got it. Thanks. I literally wrote the virtual pin code just now. I guess we’re looking at things from 2 different perspectives, but the issue and answer are still the same.

When you have the basic code working, look at the BLYNK_CONNECTED callback, and put a Blynk.syncVirtual(Virtual pin number) command in there.
That way, when the NodeMCU connects (or re-connects) to the Blynk server the BLYNK_WRITE(Virtual pin number) callback will be triggered and you’ll get the current value from the slider.

Pete.

Got it. Is it as simple as this to sync both the slider input and the vpin output?

BLYNK_CONNECTED() {
Blynk.syncAll();
}

Yes, that’s the good way to do.

Actually, I’d disagree.
Blynk.syncAll will do what it says on the tin - synchronise ALL 128 virtual pins, plus all of the digital pins.
A bit of a “sledgehammer to crack a nut” approach.

Much better su synchronise the single virtual pin whose value you want to pull back from the server, hence my suggestion to use

Pete.

1 Like

giphy

1 Like

:rofl::rofl::rofl:

1 Like

OK OK… I’ve refactored my code and included all the logic through vpins. But I then instantly hit a baffling issue… whenever I enter the following line in the loop function, the app disconnects.

int intMoisture = analogRead(A0);

It occasionally connects for a few seconds, and then disconnects. Otherwise just doesn’t connect at all.

I then updated the widget in the Blynk app to update every few seconds rather than Push and stripped everything back removing all logic and vpin functions and I still get the same issue. Connects and works fine without that line and fails as soon as I include just that line.

What’s going on?

Do you mean in your void loop()?
If so then you need to read this…

Pete.

Thanks. I’ve had a look, but can’t see how it relates to my current situation. I can see the issue and purpose for the timer loop, but in my case I only have the following in my void loop():

void loop() {
Blynk.run();

int currentMoisture = analogRead(A0);
}

I’ve simplified the logic to as minimal as possible of course and still getting the issue. I can’t see how this could be causing a flood error.