Seeed-Solution / SenseCAP_Indicator_ESP32

SenseCAP Indicator SDK.
https://wiki.seeedstudio.com/SenseCAP_Indicator_How_To_Flash_The_Default_Firmware/#ESP-IDF
Apache License 2.0
32 stars 22 forks source link

indicator_ha showing one hour less #48

Open jardous opened 4 months ago

jardous commented 4 months ago

indicator_hr is showing one hour less than it should

Time Auto Update: ON

timezone Europe/Berlin

two possible culprits:

  1. daylight saving time is not taken into account
  2. ntp is not working properly - I see some errors in the log:
    E (9522) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
    E (9523) esp-tls: create_ssl_handle failed
    E (9524) esp-tls: Failed to open new connection
    E (9534) city: Connection failed...
    I (10536) city: Get time zone...
    E (10583) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
    E (10584) esp-tls: create_ssl_handle failed
    E (10584) esp-tls: Failed to open new connection
    E (10595) city: Connection failed...
    I (11596) city: Get time zone...
    E (11642) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
    E (11643) esp-tls: create_ssl_handle failed
    E (11643) esp-tls: Failed to open new connection
metlinux commented 4 weeks ago

I hade the same issue, and it seems to be caused by a part of the code in indicator_city.c Actually there is no issue with ssl but with the zonestr

To be precise it occurs in "static void __indicator_http_task(void *p_arg)"

I adjusted:

        if(  net_flag && ip_flag && !time_zone_flag) {
            ESP_LOGI(TAG, "Get time zone...");
            err =  __time_zone_get(__g_city_model.ip); 
            if( err == 0) {
                char zone_str[32];
                float zone = __g_city_model.local_utc_offset / 3600.0;

                if( zone >= 0) {
                    snprintf(zone_str, sizeof(zone_str) - 1, "UTC-%.1f", zone);
                } else {
                    snprintf(zone_str, sizeof(zone_str) - 1, "UTC+%.1f", 0 - zone);
                }
                indicator_time_net_zone_set( zone_str );

                time_zone_flag = true;
            }
        }

into

         if(  net_flag && ip_flag && !time_zone_flag) {
            ESP_LOGI(TAG, "Get time zone...");
            char zone_str[32];
            snprintf(zone_str, sizeof(zone_str) - 1, "UTC-2:00");
            indicator_time_net_zone_set( zone_str );
            time_zone_flag = true;
       }

I agree it is somewhat radical, and limits my zone to UTC-2:00, so please if you use this adjust this to your own zone But it works till it gets fixed. With this error you have, it will continue to loop through this procedure which seems a waste of resources.

If others know of a better fix, please share

the-confused-genius commented 4 weeks ago

Hey @metlinux

The actual issue is that the code fetches the UTC based on you IP address using an API. This UTC is then not properly formatted in the code, which causes the time error.

Yes you can either hard code the UTC or change the snprintf line so that the UTC is formatted properly as expected by dependent code

You can check this https://github.com/Seeed-Solution/SenseCAP_Indicator_ESP32/issues/25 issue as it is a similar one and I have provided the fix there.

yupyvovarov commented 1 week ago

I have a similar issue

зображення

but only with indicator_ha, indicator_basis uses identical code and does not produce this error. I do not understand why and how to fix it.

the-confused-genius commented 1 week ago

@yupyvovarov It seems to be connection issue with your wifi ?

Is It able to connect with your wifi ? The internal chip used here is esp32 which has issue connecting with 5 GHz wifi, so is you wifi having 2.4 Ghz ?

Have you used the same code provided in the release build ? and have you tried flashing different (previous) release builds ?

yupyvovarov commented 1 week ago

@the-confused-genius No it's not. The WiFi connection is OK. It can connect to the internet, retrieve location, and send metrics to HA, but do not set a time zone. As I mentioned, the basic example firmware works perfectly, the ha example - doesn't. The Indicator HA update release firmware works as expected, but failed when I tried to build it by myself.

metlinux commented 1 week ago

I have a similar issue зображення but only with indicator_ha, indicator_basis uses identical code and does not produce this error. I do not understand why and how to fix it.

I also just had it with indicator_ha. Do try the workaround that I mentioned above....

yupyvovarov commented 1 week ago

@metlinux Your fix will probably work. But I am curious why the same indicator_city code works for indicator_basic. What is the difference?