Wio LTE for Arduino에서 시간 얻기

다음 페이지를 참고했습니다.
GetTime.ino

get_time/get_time.ino
// ---------------------------------------------------------------
/*
    get_time.ino

                    Jul/30/2021
*/
// ---------------------------------------------------------------
#include <WioLTEforArduino.h>

#define APN               "soracom.io"
#define USERNAME          "sora"
#define PASSWORD          "sora"
#define INTERVAL  (5000)

WioLTE Wio;
// ---------------------------------------------------------------
void setupLTE() {
  delay(200);

  SerialUSB.println("");
  SerialUSB.println("*** START *** seupLTE ***");

  SerialUSB.println("### I/O Initialize.");
  Wio.Init();

  SerialUSB.println("### Power supply ON.");
  Wio.PowerSupplyLTE(true);
  delay(500);

  SerialUSB.println("### Turn on or reset.");
  if (!Wio.TurnOnOrReset()) {
    SerialUSB.println("### ERROR! TurnOnOrReset ###");
    return;
  }

  SerialUSB.println("### Connecting to \"soracom.io\".");
  if (!Wio.Activate(APN, USERNAME, PASSWORD)) {
    SerialUSB.println("### ERROR! Activate ###");
    return;
  }

  SerialUSB.println("*** SetupLTE completed ***");
}

// ---------------------------------------------------------------
void setup() {
    delay(500);

    SerialUSB.println("");
    SerialUSB.println("*** START ***");

    SerialUSB.println("### I/O Initialize.");
    setupLTE();


  SerialUSB.println("### Sync time.");
  if (!Wio.SyncTime("ntp.nict.jp")) {
    SerialUSB.println("### ERROR! SyncTime ###");
    return;
  }

  SerialUSB.println("*** setup *** ccc");

  SerialUSB.println("### Setup completed.");
}

// ---------------------------------------------------------------
void loop() {
  SerialUSB.println("*** Get time ***");

  struct tm now;

  if (!Wio.GetTime(&now)) {
    SerialUSB.println("### ERROR! GetTime ###");
  }
  else
  {
  SerialUSB.print("UTC:");
  SerialUSB.println(asctime(&now));
  delay(100);
  }

  delay(INTERVAL);
}

// ---------------------------------------------------------------

실행 결과

좋은 웹페이지 즐겨찾기