LoginSignup
8
6

More than 5 years have passed since last update.

Arduino > Time > 日時設定 > setTime(hh, nn, ss, dd, mm, yyyy);

Last updated at Posted at 2016-06-19
動作確認
ESP-WROOM-02

参考 http://qiita.com/exabugs/items/fe46ec45ff2ffd6c5777

https://github.com/PaulStoffregen/Time
のTimeライブラリ使用

上記のライブラリを使用してESP8266の日時設定をする。
setTime()という関数があるようだ。

Functions for managing the timer services are:

setTime(t); // set the system time to the give time t
setTime(hr,min,sec,day,mnth,yr); // alternative to above, yr is 2 or 4 digit yr (2010 or 10 sets year to 2010)

eps8266_160619_timeLib.ino
#include <TimeLib.h>
#include <stdarg.h>

void setup() {

#if 1
  setTime(9, 43, 0, 19, 6, 2016);
#else
  setTime(86400); 
#endif  

  Serial.begin(115200);
}

void myPrintf(char *fmt, ...) 
{
  char buf[128];
  va_list args;
  va_start(args, fmt);
  vsnprintf(buf, 128, fmt, args);
  va_end(args);
  Serial.print(buf);  
}

void loop() {
  myPrintf("%02d:%02d:%02d", hour(), minute(), second() );
  myPrintf(",%02d/%02d/%04d", day(), month(), year() );
  Serial.println(); 

  delay(3000);
}
結果
09:43:03,19/06/2016
09:43:06,19/06/2016
09:43:09,19/06/2016
09:43:12,19/06/2016
09:43:15,19/06/2016
09:43:18,19/06/2016
09:43:21,19/06/2016
09:43:24,19/06/2016
8
6
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
8
6