🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    I am looking for internet time M5Stack for Arduino ide

    Scheduled Pinned Locked Moved Arduino
    12 Posts 3 Posters 13.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      Stoni99
      last edited by

      Unfortunately, ezTime.h does not work on the M5Stack.

      Does anyone know of a simple, working way to get the time and date from the internet?

      1 Reply Last reply Reply Quote 0
      • felmueF Offline
        felmue
        last edited by

        Hello @Stoni99

        are you sure? From the description Rob developed ezTime together with M5ez for M5Stack.

        What exactly doesn't work for you? Care to share your code?

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • S Offline
          Stoni99
          last edited by

          I tried example codes. After establishing the Internet connection, the M5Stack crashes and restarts. He doesn't seem to tolerate waitForSync();

          #include <M5Stack.h>
          #include "WiFi.h"
          #include "ezTime.h"

          const char *ssid = "xxxxxxxxxxx";
          const char *password = "xxxxxxxxxxx";

          void setup(){
          //Serial.begin(115200);
          M5.begin();
          M5.Power.begin();
          WiFi.mode(WIFI_STA);
          WiFi.disconnect();
          delay(100);
          WiFi.begin(ssid, password);
          M5.Lcd.print("Call to " + String(ssid));
          while (WiFi.status() != WL_CONNECTED) {
          M5.Lcd.print('.');
          delay(1000);
          }
          M5.Lcd.println(" ");
          M5.Lcd.println(WiFi.localIP());
          M5.Lcd.print("Signalstearke: ");
          M5.Lcd.println(WiFi.RSSI());
          //server.begin();
          delay(2000);
          M5.Lcd.clear();

          waitForSync();
          M5.Lcd.println();
          M5.Lcd.println("Time in various internet standard formats ...");
          M5.Lcd.println();
          M5.Lcd.println("ATOM: " + dateTime(ATOM));
          M5.Lcd.println("COOKIE: " + dateTime(COOKIE));
          M5.Lcd.println("IS8601: " + dateTime(ISO8601));
          M5.Lcd.println("RFC822: " + dateTime(RFC822));
          M5.Lcd.println("RFC850: " + dateTime(RFC850));
          M5.Lcd.println("RFC1036: " + dateTime(RFC1036));
          M5.Lcd.println("RFC1123: " + dateTime(RFC1123));
          M5.Lcd.println("RFC2822: " + dateTime(RFC2822));
          M5.Lcd.println("RFC3339: " + dateTime(RFC3339));
          M5.Lcd.println("RFC3339_EXT: " + dateTime(RFC3339_EXT));
          M5.Lcd.println("RSS: " + dateTime(RSS));
          M5.Lcd.println("W3C: " + dateTime(W3C));
          M5.Lcd.println();
          M5.Lcd.println(" ... and any other format, like "" + dateTime("l ~t~h~e jS ~o~f F Y, g:i A") + """);
          delay(6000);
          }

          void loop() {
          events();
          }

          M 1 Reply Last reply Reply Quote 0
          • felmueF Offline
            felmue
            last edited by

            Hello @Stoni99

            your code runs fine on my M5Stack.

            • what happens if you comment out waitForSync()?
            • what is the log output of the crash?

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            1 Reply Last reply Reply Quote 0
            • M Offline
              macsbug
              last edited by macsbug

              Hell@Stoni99

              I'm using the World Time API.
              It is good to use it according to the area.

              World Time API : http://worldtimeapi.org/

              Example

              //===========================================================
              // Web WorldTime M5Stack : 2022.07.01 : macsbug
              // 開発環境 : Arduino IDE 1.8.19
              // : Board : ”M5Stack-Core-ESP32”
              // : Board Manager : arduino-esp32 2.0.3-RC1
              // Device : M5Stack
              // Library : M5Stack.h , WiFi.h , HTTPClient.h
              //===========================================================
              // WorldTimeAPI : http://worldtimeapi.org/
              // TomeZpone : https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
              // Tokyo : http://worldtimeapi.org/api/timezone/Asia/Bangkok
              // Chicago : http://worldtimeapi.org/api/timezone/America/Chicago
              //===========================================================

              #include <M5Stack.h>
              #include <WiFi.h>
              #include <HTTPClient.h>

              const char *ssid = "xxxx";// Wi-Fi access point
              const char *pass = "xxxx";// Wi-Fi password
              const char *WTA = "http://worldtimeapi.org/api/timezone/Asia/Bangkok"; // WTA,BANGKOK
              int _year, _mon, _day, _hour, _min, _sec;

              //============================================================
              // WorldTime : web dada = {
              // "abbreviation":"JST","client_ip":"127.0.0.0",
              // "datetime":"2022-06-25T08:18:17.061071+09:00",
              // "_day_of_week":6,"_day_of_year":176,"dst":false,
              // "dst_from":null,"dst_offset":0,"dst_until":null,
              // "raw_offset":25200"timezone":"Asia/Bangkok",
              // "unixtime":1656112697,
              // "utc_datetime":"2022-06-24T23:18:17.061071+00:00",
              // "utc_offset":"+09:00","week_number":25}
              //============================================================
              void WorldTimeAPI(){
              if ((WiFi.status() == WL_CONNECTED)){
              HTTPClient http;
              http.begin(WTA); // Specify URL
              int httpCode = http.GET(); // Send GET request
              if (httpCode > 0) { // If there is a reply
              String web = http.getString(); // WEB Data acquisition
              // Serial.print("web dada = ");Serial.println(web);

                // "datetime":"2022-06-25T08:06:30.948882+09:00",
                //  00000000001111111111222222222233333333334444
                //  01234567890123456789012345678901234567890123
                int pos = web.indexOf("datetime") + 11;    
                _year = web.substring(pos   , pos+ 4  ).toInt();
                _mon  = web.substring(pos +5, pos+ 5+2).toInt();
                _day  = web.substring(pos +8, pos+ 8+2).toInt();
                _hour = web.substring(pos+11, pos+11+2).toInt();
                _min  = web.substring(pos+14, pos+14+2).toInt();
                _sec  = web.substring(pos+17, pos+17+2).toInt();
              
                char ymm[12];sprintf(ymm,"%4d/%02d/%02d"   ,_year,_mon,_day);
                char hms[10];sprintf(hms,"%02d:%02d:%02d\n",_hour,_min,_sec);
                M5.Lcd.print(ymm);M5.Lcd.print(" ");M5.Lcd.println(hms);
                
              }else{ Serial.println("Error on HTTP request");}
              http.end();   // Free the resources
              

              }
              }

              //===========================================================
              void setup(){
              M5.begin();
              M5.Lcd.setSwapBytes(true);
              M5.Lcd.setRotation(1);
              M5.Lcd.fillScreen(TFT_BLUE);
              M5.Lcd.setTextColor(TFT_WHITE);
              M5.Lcd.setTextSize(2);
              M5.Lcd.printf(" Wi-Fi Connecting to %s\n", ssid);
              WiFi.begin(ssid, pass);
              while (WiFi.status() != WL_CONNECTED){delay(500);M5.Lcd.print(".");}
              M5.Lcd.println();
              }

              //===========================================================
              void loop(){
              WorldTimeAPI();
              delay(1000);
              }
              //===========================================================

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                Stoni99
                last edited by

                @felmue said in I am looking for internet time M5Stack for Arduino ide:

                Hello @Stoni99

                your code runs fine on my M5Stack.

                • what happens if you comment out waitForSync()?
                • what is the log output of the crash?

                Thanks
                Felix

                What do you mean by comment out?
                I don't have log output , it just restarts.

                1 Reply Last reply Reply Quote 0
                • S Offline
                  Stoni99 @macsbug
                  last edited by Stoni99

                  @macsbug said in I am looking for internet time M5Stack for Arduino ide:

                  Hell@Stoni99

                  I'm using the World Time API.
                  It is good to use it according to the area.

                  World Time API : http://worldtimeapi.org/

                  Example
                  ......

                  Code works - thanks!

                  1 Reply Last reply Reply Quote 0
                  • felmueF Offline
                    felmue
                    last edited by

                    Hi guys

                    @macsbug : thank you for presenting the World Time API as alternative solution.

                    @Stoni99 : never mind - I am glad to read you have working code now.

                    Thanks
                    Felix

                    GPIO translation table M5Stack / M5Core2
                    Information about various M5Stack products.
                    Code examples

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      Stoni99
                      last edited by

                      ezTime.h seems easier to condition?!🤔

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        Stoni99
                        last edited by

                        ezTime.h works now. I have updated to new Version. Thx!

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          macsbug @Stoni99
                          last edited by

                          Hello@stoni99

                          ezTime.h

                          I modified the following and got the result.

                          Fix;
                          #include <WiFi.h>
                          #include <ezTime.h>
                          //waitForSync();

                          result;
                          Time in various internet standard formats ...

                          ATOM: 1970-01-01T00:00:09-00:00
                          COOKIE: Thursday, 01-Jan-1970 00:00:09 UTC
                          IS8601: 1970-01-01T00:00:09-0000
                          RFC822: Thu, 01 Jan 70 00:00:09 -0000
                          RFC850: Thursday, 01-Jan-1970 00:00:09 UTC
                          RFC1036: Thu, 01 Jan 70 00:00:09 -0000
                          RFC1123: Thu, 01 Jan 70 00:00:09 -0000
                          RFC2822: Thu, 01 Jan 70 00:00:09 -0000
                          RFC3339: 1970-01-01T00:00:09-00:00
                          RFC3339_EXT: 1970-01-01T00:00:09.771-00:00
                          RSS: Thu, 01 Jan 70 00:00:09 -0000
                          W3C: 1970-01-01T00:00:09-00:00

                          ... and any other format, like Thursday the 1st of January 1970, 12:00 AM

                          1 Reply Last reply Reply Quote 0
                          • S Offline
                            Stoni99
                            last edited by

                            Ahhh - ok: "//waitForSync();" 👍

                            1 Reply Last reply Reply Quote 0

                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                            With your input, this post could be even better 💗

                            Register Login
                            • First post
                              Last post