Konijn
January 29, 2022, 3:45pm
1
Hello,
I am a bit fighting with my project. I want to control a relay and use the slider for time that the relay is HIGH.
I used the code which I read in the forum.
What I not understand: mytimer.setTimeout(1000L, ActionOFF); What means the L behind the milliseconds?
How can use a slider with the seconds in this function?
How can reduce BLYNK_WRITE that there is not so much data use. We use this aplication a few times a day.
Enclosed a schreenshot of the app.
Thanks a lot
Jack
• Lilygo SIM800L
• Smartphone Android 8.0
• Blynk server
{
// Set console baud rate
SerialMon.begin(115200);
// Set to true to define Relay as Normally Open (NO)
delay(10);
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
SerialMon.print(F("Connecting to APN: "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, user, pass)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
Blynk.begin(auth, modem, apn, user, pass);
}
BLYNK_WRITE(V4)
{
SLID = param.asInt();
}
BLYNK_WRITE(V1) // Virtual button on Vx to activate action
{
int BTN = param.asInt();
if (BTN == 1) {
digitalWrite(relayGPIOs[1], HIGH); // Set pin high
mytimer.setTimeout(5000L, ActionOFF); // Run ActionOFF function in 5 seconds
}
}
void ActionOFF()
{
digitalWrite(relayGPIOs[1], LOW); // Set pin Low
}
void loop()
{
Blynk.run();
mytimer.run();
}
Long Integer.
I don’t really understand the question, but the Blynk timer works in milliseconds, so you would need to multiply the slider value by 1000.
The BLYNK_WRITE(vPin) function only triggers when the value of the virtual pin changes.
Pete.
Konijn
January 29, 2022, 4:27pm
3
Thanks Peter for your answer.
Long integer? Means calculated to seconds?
I don’t really understand the question, but the Blynk timer works in milliseconds, so you would need to multiply the slider value by 1000.
I want the slider value*1000 use in this fuction:
mytimer.setTimeout(1000L, ActionOFF);
So replace the the 100"0L with the value from the slider.
Thanks
If you don’t know what a Long Integer is in C++ then you should google it.
The value from the slider multiplied by 1000
Pete.
John93
January 29, 2022, 4:56pm
5
Also, I recommend you to read this very useful article
Many users seem to struggle with the basic concepts of using BlynkTimer in their projects, despite the excellent discussions and tutorials that exist on this forum, so I thought I’d write a guide that will hopefully help clarify things. It’s rather long, as it attempts to explain the reasoning behind why and how we use timers, and covers some more advanced subjects, but I’ve tried to organise it in a way that helps people to find answers to specific questions…
Why use a timer at all?
Let’s say …
If you want to reduce GSM data traffic caused by the Blynk handshake and ping processes then you should read this…
Добрый день!
Использую приложение Blynk на Андроид 4.4.4. Blynk Library 0.6.1, Arduino IDE 1.8.13
Для визуализации использую виджет ValueDispley - 2 графика с опросом по 5сек каждый (или Push)
Схема: два датчика DS18B20 сидят на GPIO 0 модуля ESP-01. Опрос вызывается по таймеру.
Если делаю:
3000L = раз в 3 секунды, 1час = 264кб (185 МБ/мес)
30000L = раз в 30сек, 1час = 75кб (54 МБ/мес)
60000L = раз в 1мин, 1час = 61кб (42 МБ/мес)
Т.е. трафик складывается из:
неуменьшаемого остатка 0.93…
Pete.
1 Like
Konijn
January 29, 2022, 6:29pm
7
[/quote]
know what a Long Integer is in C++ then you should google it.
The value from the slider multiplied by 1000
[/quote]
Can I use this:
mytimer.setTimeout(slider*1000), ActionOFF);
And is the long integer needed then?
Why not declare slider
as a Long variable type?
Pete.
Konijn
January 29, 2022, 6:41pm
9
How to do? Sorry just a beginner
John93
January 29, 2022, 7:14pm
10
Check the article I sent you,
" Using blynk timer or simple timer "
Konijn:
How to do?
I’m guessing that you didn’t take my advice…
The forum is for helping people with Blynk related issues, not teaching C++ programming basics.
Pete.
Konijn
February 7, 2022, 8:33am
12
Oke I think I find it:
mytimer.setTimeout((long int)tijd, ActionOFF);
It seems working allright now. Only thing when I abrupt the timer by ActionOff and the timer did not finished his time. Then the next time I pressed its not the correct time anymore. Wait I a minute then its normal. Must I clear the buffer of the timer?
I’m surprised that works. It’s certainly not the correct way to do it.
I’m guessing that you didn’t read the link in post #5
Pete.
Konijn
February 7, 2022, 8:49am
14
Nog good enough
timer.deleteTimer(timer_ID);
or with enable and disable
I will try what happend withe the delete....
If you just want the relay to be on for x amount of time when a widget button is pressed then you are using the wrong type of timer.
I’d use a timeout timer in a lambda function.
Pete.