0
1

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、NTP(ネット時計)で遊ぶ。

0
Posted at

いろいろ注意

  • 過去ログを見よ!!!
  • タイミングは、適度に調整の事(なんのこと
  • ESP32 3.3.7
  • 適度に修正

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

結果

Screenshot from 2026-02-21 07-31-29.png

イメージ(実際とは、違う(SSD1306が無い((画像の使い回し)

IMG_9741.jpeg

プログラム




//ser_SNTP_HH_MM_test4n_m5nanoc6_1


//ヘッダーファイル
#include <Arduino.h>
#include <WiFi.h>
#include <time.h>


//定義 (NTP)
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";


//初期化
void setup() {

  //シリアルポートの初期化
  Serial.begin(9600);

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

  //Wifi、シリアルの接続待ち
  delay(3000);  //決め打ちなので、おかしかったら調整してね! wifiの待ち0.5*6

}  //setup


//メインループ
void loop() {

  //時間-->

  time_t t;       //経過秒
  struct tm *tm;  //時間の実体とポインター

  t = time(NULL);      //経過秒を取得する
  tm = localtime(&t);  //経過秒を時間の構造体に変換する

  //set time 時間合わせの再設定
  static int set_1H = 0xFFFF;      //適当な大きい値
  if (set_1H > ((60 * 60) - 1)) {  // 1 hour ?
    set_1H = 0;  //counter reset
    configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
  }  //endif
  set_1H++;  //カウントアップ

  //-->時間


  //表示-->

  //時分秒
  Serial.printf("%02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec);  //時刻を表示する

  //-->表示


  delay(1000);  //1秒待つ

}  //loop



0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?