Skip to content

former configTime method no longer works. #7141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
whyameye opened this issue Mar 8, 2020 · 10 comments
Closed
6 tasks done

former configTime method no longer works. #7141

whyameye opened this issue Mar 8, 2020 · 10 comments
Assignees
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Milestone

Comments

@whyameye
Copy link

whyameye commented Mar 8, 2020

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12F
  • Core Version: commit 2522403
  • Development Env: 1.8.9
  • Operating System: Ubuntu 18.04

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600

Problem Description

configTime appears to now have a new format for calls --- a welcome change. Unfortunately the previous format no longer works despite the documentation saying that it does.

MCVE Sketch

using example included in core NTP-TZ-DST.ino , line 223 reads former configTime is still valid... which I interpret to mean:

  • line 218 can be commented out: //configTime(MYTZ, "pool.ntp.org");
  • and line 225 can be uncommented: //configTime(7 * 3600, 3600 / 2, "pool.ntp.org");

and the example should still work. It crashes instead. Decoded stack dump below.

I discovered this when my own code for getting time via NTP stopped working after I updated to latest commit on master branch.

Debug Messages

Decoding stack results
0x40206e15: _printf_i at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_i.c line 226
0x4020ad56: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x4020b187: _svfprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 667
0x40203d89: uart_tx_fifo_available(int) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/uart.cpp line 463
0x40203db4: uart_do_write_char(int, char) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/uart.cpp line 476
0x4020866d: _vsnprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vsnprintf.c line 73
0x4020866d: _vsnprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vsnprintf.c line 73
0x40203e79: uart_write(uart_t*, char const*, size_t) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/uart.cpp line 509
0x40201bfc: ESP8266WiFiSTAClass::status() at /home/user/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp line 634
0x402086b0: vsnprintf at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vsnprintf.c line 42
0x40201ebc: HardwareSerial::write(unsigned char const*, unsigned int) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.h line 165
0x40201eb0: HardwareSerial::write(unsigned char const*, unsigned int) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.h line 164
0x40201eb0: HardwareSerial::write(unsigned char const*, unsigned int) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.h line 164
0x40202248: Print::printf(char const*, ...) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Print.cpp line 63
0x402021e9: Print::write(char const*) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Print.h line 62
0x4020240d: Print::printNumber(unsigned long, unsigned char) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Print.cpp line 268
0x40203e79: uart_write(uart_t*, char const*, size_t) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/uart.cpp line 509
0x40205d39: _findenv_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/getenv_r.c line 99
0x40201eb0: HardwareSerial::write(unsigned char const*, unsigned int) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.h line 164
0x4020126a: showTime() at /tmp/arduino_modified_sketch_870741/NTP-TZ-DST.ino line 140
0x402014b2: setup() at /tmp/arduino_modified_sketch_870741/NTP-TZ-DST.ino line 239
0x40202398: Print::println(char const*) at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Print.cpp line 198
0x40202da8: loop_wrapper() at /home/user/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 182
@d-a-v d-a-v self-assigned this Mar 9, 2020
@d-a-v d-a-v added this to the 2.7.0 milestone Mar 9, 2020
@d-a-v
Copy link
Collaborator

d-a-v commented Mar 9, 2020

Thanks for reporting, this bug is in the example, not in the core.
It is fixed by #7144.

@whyameye
Copy link
Author

whyameye commented Mar 9, 2020

Perhaps, but there has been a regression because as I noted: "I discovered this when my own code for getting time via NTP stopped working after I updated to latest commit on master branch." So code that used to work with configTime no longer does. I suspect if we look at a previous version of the example we will discover it no longer works, but I have not confirmed. I can look into that when I have a chance.

@d-a-v
Copy link
Collaborator

d-a-v commented Mar 9, 2020

An MCVE would be great

@d-a-v d-a-v removed the fixed-by-PR label Mar 14, 2020
@d-a-v
Copy link
Collaborator

d-a-v commented Mar 16, 2020

@whyameye Any news ?

@d-a-v d-a-v modified the milestones: 2.7.0, 3.0.0 Mar 25, 2020
@dontsovcmc
Copy link
Contributor

dontsovcmc commented May 16, 2020

I confirm configTime error!

Good version 2.6.3:

PLATFORM: Espressif 8266 2.4.0 #4a9e74d > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20603.200130 (2.6.3) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)

Broken version 2.7.0:

PLATFORM: Espressif 8266 2.5.0 #772ec50 > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20700.200502 (2.7.0) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
#include <Arduino.h>
#include "time.h"
#include <ESP8266WiFi.h>


const char *ssid     = "YOUR_SSID";
const char *password = "YOUR_PASS";

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
      delay ( 500 );
      Serial.print ( "." );
  }

  configTime(0, 0, "pool.ntp.org");

  Serial.println("Waiting for NTP time sync");
  unsigned long start = millis();

  time_t now = time(nullptr);

  while (now < 50000 && millis() - start < 3000UL) 
  {
    delay(100);
    now = time(nullptr);
  }

  if (millis() - start >= 3000UL)
  {
    Serial.print("NTP error");
  } 
  else
  {
    time_t now = time(nullptr);
    struct tm timeinfo;
    gmtime_r(&now, &timeinfo);
    Serial.print("Current time: ");
    Serial.print(asctime(&timeinfo));
  } 
}

void loop() 
{

}

@d-a-v
Copy link
Collaborator

d-a-v commented May 16, 2020

(edit: fixed)

@dontsovcmc With your MCVE I get with current master (2.7.1+):

Leaving...
Hard resetting via RTS pin...
--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
.......Waiting for NTP time sync
Current time: Sat May 16 13:37:32 2020

So it's working.

However, these loops look suspicious:

  while (now < 50000 && millis() - start < 3000UL) 
  {
    delay(100);
    now = time(nullptr);
  }

  if (millis() - start >= 3000UL)
  {
    Serial.print("NTP error");
  } 

If you need to wait until time is set, you can use a callback like in the provided example in something like:

bool time_is_set = false;
...
void time_is_set ()
{
    time_is_set = true;
    // or do something
}
...
void setup ()
{
...
    // install callback - called when settimeofday is called (by SNTP or us)
    // once enabled (by DHCP), SNTP is updated every hour
    settimeofday_cb(time_is_set);
...
    // one can wait here
    while (!time_is_set)
    {
        delay(100);
    }
}

void loop ()
{
   // one can do something here
    if (time_is_set)
    {
        // do something
    }
}

with a functional :

bool time_is_set = false;
...
void setup ()
{
...
    // install callback - called when settimeofday is called (by SNTP or us)
    // once enabled (by DHCP), SNTP is updated every hour
    settimeofday_cb([](){ time_is_set = true; /* or do something else */ });
...
    // one can wait here
    while (!time_is_set)
    {
        delay(100);
    }
}

void loop ()
{
   // one can do something here
    if (time_is_set)
    {
        // do something
    }
}

@dontsovcmc
Copy link
Contributor

dontsovcmc commented May 16, 2020

Ok, I'll try callback and master branch.
2.7.1 also doesn't work.
You think, till 2.7.0 it's spend more than 3 seconds to get time? I think no..

@d-a-v
Copy link
Collaborator

d-a-v commented May 16, 2020

Please try and check with the callback and report.
If it works, I'm interested in duration between start and when time is reported to be set.

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 9, 2020

@whyameye Do you still have issues with the master branch ?

@d-a-v d-a-v added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Mar 6, 2021
@d-a-v
Copy link
Collaborator

d-a-v commented Mar 31, 2021

Closing per fixed in current master.
Please open a new issue if there's still a problem with configTime.

@d-a-v d-a-v closed this as completed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

3 participants