Skip to content

configTime() method not implemented #29

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
forthlightning opened this issue Nov 3, 2016 · 5 comments
Closed

configTime() method not implemented #29

forthlightning opened this issue Nov 3, 2016 · 5 comments

Comments

@forthlightning
Copy link

forthlightning commented Nov 3, 2016

Porting over code from ESP8266 and hoping for an analog to time.c in the 8266 core

I was digging around in time.h but the types and pointers were out of my comfort zone.

Specifically configTime() was a very easy way to get the system clock synced with internet time.

@igrr
Copy link
Member

igrr commented Nov 12, 2016

There is an sntp example in esp-idf, you can it in Arduino as well.

On Sat, Nov 12, 2016, 08:28 lbernstone notifications@github.com wrote:

This depends on sntp.c, which in turn depends on lwip components that are
not working yet.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#29 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEJcep2SGRmYZ3pwMDnrImvK5KgGyfk7ks5q9QhAgaJpZM4Kn5rM
.

@me-no-dev me-no-dev added the Status: To be implemented Selected for Development label Nov 16, 2016
@forthlightning
Copy link
Author

Hi, has anyone confirmed this works?

I'm using this function, as called from my wifi_event_handler()'s SYSTEM_EVENT_STA_GOT_IP event. These calls are unsuccessful in getting time.

void init_time()
{
    long int gmt_offset_sec = -25200;
    int dst_offset_sec = 0;
    configTime( gmt_offset_sec, dst_offset_sec , "pool.ntp.org" );
    struct tm timeinfo;
    if( !getLocalTime( &timeinfo, 2000 ) )
    {
    	printf( "failed to obtain time\n" );
    	return;
    }
    time_t now;
    printf( "%ld\n",time( &now ) );
}

void wifi_event_handler( WiFiEvent_t event )
{
    printf("[WiFi-event] (%d)\n", event);

    switch(event)
    {
    case SYSTEM_EVENT_STA_GOT_IP:
    	wifi_got_ip_addr = true;
        break;

    case SYSTEM_EVENT_STA_DISCONNECTED:
    	wifi_got_ip_addr = false;
        break;

    default:
    	break;
    }
}

@me-no-dev
Copy link
Member

I init time on SYSTEM_EVENT_STA_GOT_IP and have no problems.
almost that same code above ;)

@me-no-dev
Copy link
Member

I do not see you calling init_time anywhere above

@forthlightning
Copy link
Author

Not sure what I was doing wrong but it works now! Thanks.

@VojtechBartoska VojtechBartoska removed the Status: To be implemented Selected for Development label Apr 6, 2022
blue-2357 pushed a commit to blue-2357/arduino-esp32 that referenced this issue Jul 17, 2024
example:
```cpp
//done once on WiFi init
configTime(-7200, 3600, "pool.ntp.org");
//get local time
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
}
//print time
Serial.println(&timeinfo);
//print time with different format
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
```
fixes: espressif/arduino-esp32#29
brentru pushed a commit to adafruit/arduino-esp32 that referenced this issue Oct 22, 2024
* Use stable esp32 library

* Fixes

* Version bump + cleanup

* Bump IDE version

* Fix

* Switch to old version for testing purposes

* Switch back to newer version of IDE
dash0820 added a commit to dash0820/arduino-esp32-stripped that referenced this issue Mar 10, 2025
example:
```cpp
//done once on WiFi init
configTime(-7200, 3600, "pool.ntp.org");
//get local time
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
}
//print time
Serial.println(&timeinfo);
//print time with different format
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
```
fixes: espressif/arduino-esp32#29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants