I use a TimeInput widget as Input in my smartphone, but I would like to write to it in my arduino code, ie construct a
TimeInputParam object with my own values. I didn’t found any documentation about it, so I had a look at the code
but didn’t found any setters().
To be clear I remember looking at the docs or forums and I found something useful for virtualWrite parameters initialisation on-the-fly with something like a JSON string in C++ code, but I cannot retrieve it.
The code below works for the Input coming from my smartphone:
TimeInputParam *timeInputConsigne = NULL;
BLYNK_WRITE(V6) {
//TimeInputParam t(param);
if (timeInputConsigne != NULL) {
delete timeInputConsigne;
}
timeInputConsigne = new TimeInputParam(param);
}
void myTimerEventFunction() {
// How to modify timeInputConsigne member values ?
//...some code here...like timeInputConsigne->setDays(value) <=== ???
Blynk.virtualWrite(V6, timeInputConsigne);
}
Hi,
The purpose was to define one timeinput widget and to control it either by the graphical interface (smartphone) or by the code.
When this will work I can have a graphical interface with a menu (1, 2, 3) and when I select a menu entry, the arduino will write the appropriate TimeInputParam1, TimeInputParam2, TimeInputParam3 to the time widget via Blynk.virtualWrite(V6, timeInputParam2) for example.
See below my reply to Dmitriy (and to other user interested to) for another way to achieve this (for me and my needs of course).
Best regards
Can you tell me if it’s on the roadmap, and vaguely a date of implementation if you already know it ?.
My point of view is that this widget should work the same way other widgets do, so timeInput should be compliant to virtualWrite().
Anyway, I’ve bought 13k energy points last week.
I didn’t needed as much points for my project, but I though you just deserve it, so thanks again for the great job you’ve done there.
A workaround, for those interested, is:
-define a TimeInput widget V6, for defining or erasing
-define a menu widget V5 with values 1, 2, 3, to choose which fixed (or computed) TimeInput values you would like to show in the TimeInput widget
-define two value widgets V7 and V8, for hour and minute display
-define 7 LED widgets V9,V10,V11,V12,V13,V14,V15, for each week day (Monday->Sunday)
-rather than doing virtualWrite(V6, new TimeInputParam(days, hour, minute));
-do this in a BLYNK_WRITE(V5) function (the menu change value function):
-virtualWrite(V7, 21); // hour
-virtualWrite(V8, 21); // minutes
-for (int i =0; i < 7; i++) { virtualWrite(V9+i, days[i]); }
-do this in a BLYNK_WRITE(V6) function (the time input change value function)
-get TimeInputParam of the V6 time input widget and put it in memory
The principle is that when you change the menu V5 value in your smartphone, time values for this menu entry are changed back, but as we cannot write to the TimeInput widget, we write to V6-V15 widgets.
Hi,
I didn’t found a better workaround than the one explained above with 7 LEDs widgets for days and two value widgets for hour and minute. May be I’ll give a try to the LCD widget
Hi,
Here is the code. It compiles but I cannot test it, and don"t have the time to create and share a small APP.
Anyway as it is a cut out of a bigger app it should work.
Hope it helps.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include "SimpleTimer.h"
// Timer to send data to BlinkServer
SimpleTimer timer;
/*
WIDGETS EXPLANATION:
V6 : advanced time input
V7 : menu with numbers (1,2,3) to choose which predefined time value we want to see in V12->V20 widgets
V12 : value widget: hour for time "output"
V13 : value widget: minute for time "output"
V14 -> V20: LED widget (MONDAY->SUNDAY)
*/
// Widget LED to display days of week of the current consigne selected
WidgetLED ledMon(V14);
WidgetLED ledTue(V15);
WidgetLED ledWed(V16);
WidgetLED ledThu(V17);
WidgetLED ledFri(V18);
WidgetLED ledSat(V19);
WidgetLED ledSun(V20);
WidgetLED *arrLEDS[7] = { &ledMon, &ledTue, &ledWed, &ledThu, &ledFri, &ledSat, &ledSun };
// Consigne associated with a time input value
typedef struct {
int hour;
int minute;
char days[8]; // '1' => day is on, else it is off; 7 (+1 char for the '\0', because we use strcpy())
} Consigne;
Consigne tab[3];
// Current index in tab[]
int current = 0;
void myTimerEvent()
{
Blynk.virtualWrite(V12, tab[current].hour);
Blynk.virtualWrite(V13, tab[current].minute);
// V14-V20 LEDS days for current consigne
for (int d = 0; d < 7; d++) {
if (tab[current].days[d] == '1') {
arrLEDS[d]->on();
} else {
arrLEDS[d]->off();
}
}
}
void setup() {
// Define here your own time consignes
strcpy(tab[0].days, "1111100"); // working days
strcpy(tab[1].days, "0000011"); // week end
strcpy(tab[2].days, "1000000"); // monday
for (int i = 0; i < 3; i++) {
tab[i].hour = 18;
tab[i].minute = 5;
}
Blynk.begin("<auth>", "<ssid>", "<pass>");
while (Blynk.connect() == false) {
// Wait until connected
}
timer.setInterval(10000L, myTimerEvent);
}
//---------------------------
// CONSIGNE TIME INPUT
//---------------------------
BLYNK_WRITE(V6) {
TimeInputParam t(param);
// Process hour and minute
tab[current].hour = t.getStartHour();
tab[current].minute = t.getStartMinute();
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
tab[current].days[i - 1] = t.isWeekdaySelected(i) ? '1' : '0';
}
}
//---------------------------
// CONSIGNE NUMBER
//---------------------------
BLYNK_WRITE(V7)
{
current = param[0].asInt() - 1;
// With future versions of Blynk, I hope we can replace 70% of this sketch with just this single line:
// Blynk.virtualWrite(V6, new TimeInputParam(tab[numCons].days, tab[numCons].hour, tab[numCons].minute))
// Widgets V6/V7 and V12/V13/V14-V20/
// will be updated at next timer event
}
void loop() {
if (Blynk.connected()) {
Blynk.run();
}
timer.run(); // Initiates SimpleTimer
delay(20);
}
Is it possible to make it possible to editing the start/stop time while project is running? Now when I want to set the timer for 08:00:00, I need to stop the project to edit this. While TimeInput has the ability to edit while running the project.
I am currently working with iOS (sorry guys).
So you cannot live edit AdvancedTimeInput, but it works with TimeInput ?
In the arduino IDE, does the example->Blynk->TimeInput->AdvancedTimeInput works, with of cours a Advanced Time Input widget on your phone ?