@tzo_mats I’m not familiar with LUA but it looks like you are connecting to the Blynk server OK.
Have you connected the slider to digital pin 13 or virtual pin V0?
It needs to be V0 and then make a couple of changes in the sketch to actually send ON / OFF to your relay.
Make the change for V0 at your side and I will do a quick mod of the sketch for your relay and post it here.
Edit: if you have version 2 of the D1 then I don’t think you should be looking at pin13. D5 on the rev2 and the Mini is GPIO 14. So my sketch mod will use 14 not 13. Are the relays active HIGH or LOW (I’ll assume active HIGH for now).
// thirtysecondtimer.ino by Costas 12 Dec 2016
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // library for SimpleTimer
SimpleTimer timer; // define a timer for use by SimpleTimer library
int Countdown; // Global variable used in Slider widget and runEveryMinute()
bool ONstatus = false; // variable to switch device ON and OFF
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
BLYNK_WRITE(V0){ // add a slider to your project on V0 range 0 to 30 (minutes)
Countdown = param.asInt(); // set variable as Slider value
}
void runEveryMinute(){ // runs every 60s, will do noting when Slider is at zero
if((Countdown > 0)&& (ONstatus == true)){
Countdown--; // reduce Countdown by 1 minute every 60s
Serial.print(F("Device will switch OFF in "));
Serial.print(Countdown);
Serial.println(F(" minute(s)"));
}
if((Countdown > 0) && (ONstatus == false)){
Serial.println(F("Device was switched ON"));
ONstatus = true; // to ensure device is only turned ON once
// code here to turn your device ON
digitalWrite(14, HIGH); // send ON signal to relay
}
if((Countdown == 0) && (ONstatus == true)){
Serial.println(F("Device is now OFF"));
ONstatus = false; // to ensure device is only turned OFF once
// code here to turn your device OFF
digitalWrite(14, LOW); // send OFF signal to relay
}
}
void setup()
{
pinMode(14, OUTPUT); // think D5 WeMos is GPIO 14
digitalWrite(14, LOW); // ensure relay is OFF on reboot
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); // this is now a blocking function - more on this later
timer.setInterval(60000L, runEveryMinute); // start the 60s timer function
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer to ensure the 60s timer keeps running
}
To test your relays you can add a Blynk button in Switch mode to digital pin 14 and it should turn the relays on and off, irrespective of the Slider position.
It is working in a fashion but you should be looking to use the super powerful virtual pins for the slider not the digital pins. Then inside the slider function you have the code to control the digital pins. Virtual pins have a lot of features that digital pins don’t have, for example their state can be saved to and from the server which you can’t do with digital pins.
With Blynk the Virtual pins are more flexible (powerful) than digital pins. Actually the virtual pins have “no power” as they are not real pins but they work alongside the digital pins, which obviously do have power.
Code is using virtual pin (V0) and then it sends high and low to digital pin. You just need to ensure your slider is connected to V0 in the Blynk app. Also change 14 to 13 in the sketch if your relay is connected to D7 on the WeMos.
Are you saying it is all working with Blynk but that there is a delay between moving the slider and the relay turning on?
The delay is “coded” into the sketch and covered by the following text in the thread for the Slider sketch.
“We have tried to keep the sketch as basic as possible and as such it has some limitations. For example when you move the Slider it will take up to 60 seconds for “Device was switched ON” to appear in Serial Monitor.
There are many ways to remove this limitation and guidance can be found by studying SimpleTimer in detail at http://playground.arduino.cc/Code/SimpleTimer”
If you don’t want to wait up to 60 seconds, simply add a Blynk button in Switch mode and tie it to digital pin 14. With the Blynk button you don’t need any extra lines of code in the sketch, it just works!
ok cool works
you are the best
i have many many of questions but for now all i wan to know if i took life report with sirial monitor like to see countdowning?
with button ho just add if the slide is alredy on and the button is off when i swich the button to on its start countdown 30sec?
Serial Monitor is already showing the countdown and you can add the countdown easily to your Smartphone (Blynk Display widget etc).
Not sure what you mean about the 30 seconds but what I will say is that the existing code has a 60s (60000ms) loop that is processed even if you do nothing in the app. The if statements look to see if you have moved the slider etc. With the 60s loop it can be anywhere within this 60s period when you move the slider and that is why I say it will take 0 to 60s to respond.
For most real life situations this is fine as it doesn’t matter if your Sprinkler, Central Heating, Washing Machine etc starts now or some time in the next 60 seconds. It is just important that it does start within 1 minute of you making the request.
Obviously there are some applications (emergency breaking etc) when the action must be processed immediately and SimpleTimer has many ways to handle this.
If you need the project to work without an internet connection you need a local Blynk server at your location. Depends how reliable your internet connection is but most users don’t need a local server.
To get the total hours that the sprinkler has been running you have a second variable alongside Countdown (perhaps called TotalTime) and you increment it every time Countdown is reset and send it to a Blynk display widget on a virtual pin. Blynk then has a function called Blynk.syncVirtual(Vx) which can be called at any time to retrieve the total Sprinkler time from their server.
That depends on specific project. Read cloning, sharing and bridge in the documentation.[quote=“tzo_mats, post:39, topic:9997”]
and what other board I can use with this sketch?
[/quote]
Blynk supoorts a huge list of hardware and the sketch should work on all supported hardware.