Do you mean it in this Function? “void blynk_update()”
Yes.
Thanks. I have modified it as below:
void sensorDataSend()
{
float t = dht.readTemperature();
Blynk.virtualWrite(V100,t);
if (isnan(dht.readTemperature()))
{
Serial.println(F("Error Reading Temperature"));
}
else
{
Serial.println(F("Temp: "));
Serial.print(dht.readTemperature());
Serial.println(F("C"));
if(dht.readTemperature() >= 35){
digitalWrite(TRELAY,HIGH);
Serial.print(F("T-RELAY"));
Serial.println(F(" ON"));
}
else{
digitalWrite(TRELAY,LOW);
Serial.print(F("T-RELAY"));
Serial.println(F(" OFF"));
}
}
}
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
pinMode(24, OUTPUT);
pinMode(13, OUTPUT);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(12, OUTPUT);
pinMode(27, OUTPUT);
pinMode(28, OUTPUT);
pinMode(29, OUTPUT);
pinMode(30, OUTPUT);
pinMode(31, OUTPUT);
pinMode(32, OUTPUT);
pinMode(33, OUTPUT);
pinMode(34, OUTPUT); pinMode(35, OUTPUT); pinMode(36, OUTPUT);pinMode(37, OUTPUT); pinMode(38, OUTPUT); pinMode(39, OUTPUT);
pinMode(40, OUTPUT); pinMode(41, OUTPUT); pinMode(42, OUTPUT);pinMode(43, OUTPUT); pinMode(44, OUTPUT); pinMode(45, OUTPUT);
pinMode(46, OUTPUT); pinMode(47, OUTPUT); pinMode(48, OUTPUT);pinMode(49, OUTPUT); pinMode(50, OUTPUT); pinMode(51, OUTPUT);
pinMode(52, OUTPUT);
pinMode(OnlineLED, OUTPUT);
pinMode(OfflineLED, OUTPUT);
digitalWrite(13, HIGH);
timer.setInterval(1000L, checkTime);
timer.setInterval(10000L, sensorDataSend);
timer.setInterval(1000L, blynk_update);
May I ask, would there be any problems if I have set 3 timer as shown above?
That’s fine, you can have up to 16
Pete.
Thanks, I will try run the device and check the Time input widget working as expected. Will try later because now had passed midnight.
The problem still not solve. Is there any way I can simplify the logic in “void led_mng()”?
int i;
for (i=0; i<60; i++)
{
led_status_buf[i] = led_status[i];
time_set_overflow = 0;
if ( timer_start_set[i] != 0xFFFF && timer_stop_set[i] != 0xFFFF)
{
if ( timer_stop_set[i] < timer_start_set[i] ) time_set_overflow = 1;
if ((((time_set_overflow == 0 && (rtc_sec >= timer_start_set[i]) && (rtc_sec < timer_stop_set[i])) ||
(time_set_overflow && ((rtc_sec >= timer_start_set[i]) || (rtc_sec < timer_stop_set[i])))) &&
(weekday_set[i] == 0x00 || (weekday_set[i] & (0x01 << (day_of_week - 1) )))) )
{
led_timer_on_set[i] = 1;
}
else
led_timer_on_set[i] = 0;
}
else
led_timer_on_set[i] = 0;
if ( led_timer_on_set[i] )
{
led_status[i] = 0;
led_set[i] = 1;
}
else
{
led_status[i] = led_set[i];
}
if ( led_status_buf[i] != led_status[i] )
update_blynk_status[i] = 0;
}
Try this
for (i = 0; i < 60; i++) {
led_status_buf[i] = led_status[i];
bool time_set_overflow = timer_stop_set[i] < timer_start_set[i];
bool within_time_range = (time_set_overflow && (rtc_sec >= timer_start_set[i] || rtc_sec < timer_stop_set[i])) ||
(!time_set_overflow && rtc_sec >= timer_start_set[i] && rtc_sec < timer_stop_set[i]);
bool within_day_range = weekday_set[i] == 0x00 || (weekday_set[i] & (0x01 << (day_of_week - 1)));
led_timer_on_set[i] = within_time_range && within_day_range;
led_status[i] = led_timer_on_set[i] ? 0 : led_set[i];
if (led_status_buf[i] != led_status[i]) {
update_blynk_status[i] = 0;
}
}
Or this
for (i = 0; i < 60; i++) {
bool within_time_range = (rtc_sec >= timer_start_set[i] && rtc_sec < timer_stop_set[i]) ||
(timer_stop_set[i] < timer_start_set[i] && (rtc_sec >= timer_start_set[i] || rtc_sec < timer_stop_set[i]));
bool within_day_range = weekday_set[i] == 0x00 || (weekday_set[i] & (0x01 << (day_of_week - 1)));
led_status[i] = !(within_time_range && within_day_range);
update_blynk_status[i] = led_status_buf[i] != led_status[i];
led_status_buf[i] = led_status[i];
}
Hi
It seems you did not have this in your code
#include <WidgetRTC.h>
WidgetRTC rtc;
/Torben
this is the Legacy way of using Blynk RTC.
The IoT method is described here:
Pete.
Hi Pete ´
Thanks for the info, but time sync works perfectly on my device
I will try the new way out
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
Serial.println("Blynk Connected");
Blynk.virtualWrite(V100, 0);
Blynk.virtualWrite(V101, Version);
Blynk.virtualWrite(V9, 255);
Blynk.syncVirtual(V10, V12, V13);
}
/Torben
It does at the moment, but at some point I suspect that this legacy method will be removed in future versions of the library.
Pete.