[Solved] Time Input issue - 8266 system crash

Hi guys,
just using Time Input Widget couple days now and experiencing system crash whenever I open/change the value of the widget, this is the trace on my serial:

[4248] Connected to WiFi
[4248] IP: 192.168.1.109
[4249] Blynk v0.3.8 on NodeMCU
[5001] Connecting to blynk-cloud.com:8442
[5073] Ready (ping: 1ms).
========================
= Sync to NTP Server   =
========================
6-9-2016 [3] - 16:47:27

++++++++++++++++++
1473180447
++++++++++++++++++
Now: 1473180467
Date: Tue, 6-Sep-2016 ---- 16:47
Now: 1473180487
Date: Tue, 6-Sep-2016 ---- 16:48
65460
65640
25200

Exception (28):
epc1=0x402018f0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3ffefb20 end: 3ffefea0 offset: 01a0

>>>stack>>>
3ffefcc0:  3ffe9ae0 00000001 00000001 00007fff  
3ffefcd0:  00000000 00006270 32cccccc 30303235  
3ffefce0:  00000000 00000001 3ffe8cd5 40205d90  
3ffefcf0:  00000009 0000000b 0ccccccc 00007776  
3ffefd00:  3ffefdf8 3ffefd80 3ffeee48 4020101c  
3ffefd10:  3ffe8cd4 00006270 3ffeee48 40205347  
3ffefd20:  3ffefdf8 3ffefdf8 00000001 4020102c  
3ffefd30:  3ffefdf8 3ffefd80 3ffeee48 40202280  
3ffefd40:  402240a6 3ffefd80 3ffeee48 4020251b  
3ffefd50:  00000000 00000030 00000000 40202280  
3ffefd60:  ffffffff 00000012 0000000b 40202cd4  
3ffefd70:  3ffefde0 3fff111c 3fff0fec 40203d99  
3ffefd80:  3ffefde6 00000012 00000012 40203dfa  
3ffefd90:  3ffeea0b 000005df 3ffeee80 3ffefde6  
3ffefda0:  3ffeec10 00000018 402058b8 3ffeee80  
3ffefdb0:  00000000 3ffeea14 3ffeec10 3ffefdf0  
3ffefdc0:  00000018 00000001 3ffeec10 40202faa  
3ffefdd0:  00000000 3fffdad0 3ffeec10 40205930  
3ffefde0:  31007776 35360031 00303634 34363536  
3ffefdf0:  35320030 00303032 3ffefe00 402025ee <
3ffefe00:  18008814 3ffefe00 3ffeee80 3ffeec30  
3ffefe10:  00000018 3ffefde0 402058b8 3ffeee80  
3ffefe20:  00000000 00000000 3ffeec10 00000000  
3ffefe30:  00000001 3ffeec30 3ffeec10 40203141  
3ffefe40:  00000000 00000000 00000000 00000000  
3ffefe50:  3ffeec30 00000000 00000000 40205274  
3ffefe60:  3ffeee48 00000000 3ffeee6c 3ffeee74  
3ffefe70:  3fffdad0 00000000 3ffeee6c 402032b7  
3ffefe80:  3fffdad0 00000000 3ffeee6c 40205904  
3ffefe90:  feefeffe feefeffe 3ffeee80 40100718  
<<<stack<<<
(��ԅ��DH{�[256] Connecting to Camar-24
[4259] Connected to WiFi
[4259] IP: 192.168.1.109
[4260] Blynk v0.3.8 on NodeMCU
[5001] Connecting to blynk-cloud.com:8442
[5071] Ready (ping: 1ms).
========================
= Sync to NTP Server   =
========================
6-9-2016 [3] - 16:48:24

++++++++++++++++++
1473180504
++++++++++++++++++

And this is my sketch:

#define DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <NTPtimeESP.h>


// -- NodeMCU PIN to ESP8266 ESP-12 Pinout
#define D0 16
#define D1 5               // LED 1 (Yellow)
#define D2 4               // LED 4 (White)
#define D3 0               // LED 2 (Green)  
#define LED_internal_PIN 2 // LED Built In = GPIO-2 --> D4
#define D5 14              // LED 3 (Red)
#define D6 12
#define D7 13
#define D8 15
#define D9 3
#define D10 1

#define VDisplayTime V25
#define VDisplayDate V26
#define VTimeInput V27

const char auth[] = "9999999999999999999999999999"; //insert here your token generated by Blynk
const char ssid[] = "Camar-24";
const char pass[] = "*****************";

const String MyDayOfWeek[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
const String MyMonth[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


NTPtime MyNTP("id.pool.ntp.org");
SimpleTimer timer;

int startTimeInSecs;
strDateTime dateTime;


// Utility function for digital clock display: prints preceding colon and leading 0
String printDigits(int digits)
{
  String new_digits = ":";
  if (digits < 10) {
    new_digits += "0";
  }
  new_digits += String(digits);
  return new_digits;
}

BLYNK_WRITE(V11) {
  startTimeInSecs = param[0].asInt(); // GMT+7

  
  #ifdef DEBUG
  Serial.println(startTimeInSecs);
  Serial.println(param[1].asInt());
  Serial.println(param[2].asInt());
  Serial.println(param[3].asInt());
  Serial.println(param[4].asInt());
  Serial.println(param[5].asInt());
  Serial.println(param[6].asInt());
  Serial.println(param[7].asInt());
  #endif
}

void CalibrateTimeWithNTP()
{
  // first parameter: Time zone in floating point; second parameter: 0 no daylight saving, 1 for European summer time;
  dateTime = MyNTP.getNTPtime(7.0, 0);

/*
  byte actualhour = dateTime.hour;
  byte actualminute = dateTime.minute;
  byte actualsecond = dateTime.second;
  int actualyear = dateTime.year;
  byte actualmonth = dateTime.month;
  byte actualday = dateTime.day;
  byte actualdayofWeek = dateTime.dayofWeek;
*/
  setTime(dateTime.hour, dateTime.minute, dateTime.second, dateTime.day, dateTime.month, dateTime.year); //(hours, minutes, seconds, days, months, years)
  
  #ifdef DEBUG
  Serial.println("========================");
  Serial.println("= Sync to NTP Server   =");
  Serial.println("========================");  
  MyNTP.printDateTime(dateTime);
  #endif
}
 
void DisplayClock()
{
  String MyTime = String(hour())+ printDigits(minute());
  String MyDate = MyDayOfWeek[weekday()-1]+", "+String(day())+"-"+MyMonth[month()-1]+"-"+String(year());
  Blynk.virtualWrite(VDisplayTime, MyTime);
  Blynk.virtualWrite(VDisplayDate, MyDate);

  #ifdef DEBUG
  Serial.print("Now: "); 
  Serial.println(now()); 
  Serial.print("Date: "); 
  Serial.print(MyDate); 
  Serial.print(" ---- "); 
  Serial.println(MyTime); 
  #endif

} // End: sendUptime()


/****************************************************
 * SETUP: Initialize for the first Time
 *****************************************************/
void setup()
{
  #ifdef DEBUG
  Serial.begin(9600); // See the connection status in Serial Monitor
  #endif
  
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) { } // Wait until connected
    // Wait until connected
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(LED_internal_PIN, OUTPUT);

  CalibrateTimeWithNTP();
  timer.setInterval(20000L, DisplayClock); // every 20 second
  timer.setInterval(3600000L, CalibrateTimeWithNTP); // every hour sync with NTP Server
  
  #ifdef DEBUG
  Serial.println();
  Serial.println("++++++++++++++++++");
  Serial.println(now());
  Serial.println("++++++++++++++++++");
  #endif
} // End: setup()


/****************************************************
 * LOOP: all the time
 *****************************************************/
void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer  
} // End: loop()

I’m using NodeMCU ESP8266 and Android,

BTW I’m using “Simple Time Input for start time”, and always getting crash whenever I’m using “Advanced Time Input”

best regards and TIA

Thanks for reporting. We’ll check.

@noersaleh can I ask what do you have attached to V11?

Yes, V11 is attach to Time Input Widget, in my sketch above, I’m still not putting any code yet, except print the param value.

TIA

I thought time input was v27, what is v27 then?

I think V27 / V11 is your problem.

Shouldn’t this line:

#define VTimeInput V27

be:

#define VTimeInput V11

Perhaps not. still crashes with the change.

Hahaha … I’m sure thats not the issue,

#define VTimeInput V27

Is my next step coding for simplifying / documentation purposes (not implemented yet), even if I deleted this line is not related to the issue…

While in my existing code currently im using Hard coded “V11”

BLYNK_WRITE(V11) {
  startTimeInSecs = param[0].asInt(); // GMT+7

As you can see in my Android Screenshot below, V11 is a Time Input Widget,

Nice catch anyway …

the issue relates to:

  //Serial.println(param[3].asInt());
  //Serial.println(param[4].asInt());
  //Serial.println(param[5].asInt());
  //Serial.println(param[6].asInt());
  //Serial.println(param[7].asInt());

with them commented out (as above) it runs fine.

So [0] start seconds, [1] stop seconds and [2] gmt offset seconds are ok but not the others (whatever they are).

@noersaleh Looking in WidgetTimeInput.h [3] is weekdays and the following line is ok as long as at least one trigger day is chosen in Time Input.

Serial.println(param[3].asInt()); // this gives first day of the week chosen as trigger

Now: 1473172071
Date: Tue, 6-Sep-2016 ---- 14:27
57600
61200
10800
4
Now: 1473172091
Date: Tue, 6-Sep-2016 ---- 14:28

but I think you really need the advanced example if you want access to the weekdays.

Yey… upon your suggestion, now is stop crashing, BIG THANKS to you … unfortunately I stumble on another issue, it seems the Time Zone is incorrect, mine is GMT+7 but always giving me wrong second in startTimeInSec value, but if I set GMT to 0, then giving me the correct value

I set the start time 18:32 (GMT+7), see the trace on Serial.print

[25063] Connected to WiFi
[25063] IP: 192.168.1.109
[25063] Blynk v0.3.8 on NodeMCU
[25063] Connecting to blynk-cloud.com:8442
[25146] Ready (ping: 0ms).
========================
= Sync to NTP Server:  =
========================
6-9-2016 [3] - 18:32:20
========================
Now: 1473186760 --> Date: Tue, 6-Sep-2016 -- 18:32
Now: 1473186780 --> Date: Tue, 6-Sep-2016 -- 18:33
Start: 41520
Stop: 41580
Now: 66780
Now: 1473186800 --> Date: Tue, 6-Sep-2016 -- 18:33

This is my code:


BLYNK_WRITE(V11) {
  startTimeInSecs = param[0].asInt(); // GMT+7

  
  #ifdef DEBUG
  Serial.print("Start: ");
  Serial.println(startTimeInSecs);
  Serial.print("Stop: ");
  Serial.println(param[1].asInt());
  Serial.print("Now: ");
  Serial.println(hour()*3600+minute()*60);
  #endif
}

TIA

I think your problem is that the start and stop times are given as UTC and then you need to adjust for the timezone seconds.

Makes sense to be this way.

If I have misunderstood your problem let me know and I will check further.

So what should I do? Should I always use the GMT+0 for my Time Input?, when I select “NO” on ALLOW TIMEZONE SELECTION on Time Input Widget Setting, automatically giving me wrong seconds, since its calculation is using GMT+7.
As you can see my “now” calculation is based on GMT+7

This the illustration to make it clear:

“Now” on 00:00 giving me 0 seconds
Time Input (GMT+7) on 00:00 giving me 61200 seconds

[1258] Connected to WiFi
[1259] IP: 192.168.10.97
[1259] Blynk v0.3.8 on ESP8266
[5001] Connecting to blynk-cloud.com:8442
[5157] Ready (ping: 4ms).
Waiting for NTP packet
202.65.114.202
sending NTP packet...

NTP packet received, length=48
========================
= Sync to NTP Server   =
========================
2016-9-6-3 14H 48M 47S 

++++++++++++++++++
1473173327
++++++++++++++++++
Now: 1473173347
Date: Tue, 6-Sep-2016 ---- 14:49
Now: 1473173367
Date: Tue, 6-Sep-2016 ---- 14:49
UTC start seconds: 57600
UTC stop seconds: 61200
TZ adj seconds: 10800
First trigger day: 2

You should still use the timezone adjustment but add these seconds to the start and stop times in your sketch.

In that case your default (from phone setting) timezone will be used.

But are start and stop seconds still UTC based or local time?

Hardware will get UTC seconds of day for start/stop time based on selected timezone (default user timezone if it wasn’t selected).

Is that means the Time Input with GMT+0 is realy my phone Time Zone?
The work arround is adjust the value on my sketch as Costas suggested, but I’m struggle with the correct adjustment value … :slight_smile:

TIA

1 Like

Does this extract help you:

stophourwd = (t.hour() + (time_input.getTZ() / 3600));  // time zone adjustment
stopsecondswd = (stophourwd * 3600) + (t.minute() * 60) + t.second();
nowseconds = (hour() * 3600) + (minute() * 60) + second();
if(nowseconds >= stopsecondswd){
  Serial.println("Weekdays Schedule Stopped");
  terminal.println("Weekdays Schedule Stopped");
}
else{
  Serial.println("Weekdays Schedule NOT Stopped");
  terminal.println("Weekdays Schedule NOT Stopped");
}
1 Like

No. Your timezone is +7. So UTC time for 18:32 would be 11:32 that is 41520. So why it is wrong?

Oh Ok, so Time Input always giving me the UTC value … So have to adjust in my sketch to refer back to GMT+7

Thanks

Its considered solved …

Appreciated with all of your support … (and Costas too …) :slight_smile:

1 Like