1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5NanoC6、SNTPで時間を取得して遊ぶ。(ESP32-C6)((簡素(S))NTP)

Last updated at Posted at 2025-02-03

x 過去ログを見よ!!
x 3.1.1
x なぜか、なんかいか「ツール」-「シリアルモニター」を開くと成功する(Windows系)
x なぜか、り、こんぱいる、すると「内蔵USBシリアル」が上手く(linux系)

いろいろ
m5stamps3とほぼ、おなじ(なんのこと)

目的
時間を取得する

各自、書き換える


const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";

結果

Screenshot from 2025-02-04 08-01-23.jpg

プログラム




//ser_time_h_1_esp32_c6_1
//
//https://www.autumn-color.com/archives/839
//


//インクルド
#include <WiFi.h>
#include <time.h>

//定義
#define JST 3600 * 9

const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";


void setup() {

  //WiFiの初期化
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  //シリアルの初期化 esp32-s3 usb-serial
  Serial.begin(9600);
  Serial.println();
  //シリアルの待ちが0.5*9
  //delay(3000);//決め打ちなので、おかしかったら調整してね! wifiの待ち0.5*6
  for (int i = 0; i < (9 + 6); i++) {
    delay(500);  //接続待ち
    Serial.print('.');
  }  //for
  Serial.println();

  Serial.println("\nSTART\n");

  Serial.println();
  Serial.printf("Connected, IP address: ");
  Serial.println(WiFi.localIP());

  configTime(JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");

}  //setup


void loop() {

  time_t t;
  struct tm *tm;
  static const char *wd[7] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };

  t = time(NULL);
  tm = localtime(&t);
  Serial.printf(" %04d/%02d/%02d(%s) %02d:%02d:%02d\n",
                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                wd[tm->tm_wday],
                tm->tm_hour, tm->tm_min, tm->tm_sec);
  delay(1000);

}  //loop




1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?