//
//----------------------------------------------
// Include
//----------------------------------------------
#include <Helper.h>
#include <SerialUart.h>
#include <NtpDateTime.h>
//
//----------------------------------------------
// Constant
//----------------------------------------------
const char* WIFI_SSID     = "FritzBoxSA7";
const char* WIFI_PASSWORD = "01234567890123456789";
//
const char* NTPSERVER = "pool.ntp.org";
const long  GMTOFFSET = 0; // [s]
const int   DAYLIGHTOFSET = 3600; // [s]
//
//----------------------------------------------
// Global Variable
//----------------------------------------------
CSerialUart UartPC(SerialUartPC);
CNtpDateTime NtpDateTime;  
//
//const char Buffer[128];
long unsigned MillisPreset;
//
// 
//----------------------------------------------
// Main - Setup
//----------------------------------------------
void setup() 
{ //--------------------------------------------
  //  UartPC Initialisation
  //--------------------------------------------
  UartPC.begin(BAUDRATE_115200);
  Message(HEADER_00);
  Message(HEADER_01);
  Message(HEADER_00);
  Message(HEADER_02);
  Message(HEADER_03);
  Message(HEADER_04);
  Message(HEADER_00);
  Message("UartPC started");
  //--------------------------------------------
  //  NtpDateTime Initialisation 
  //--------------------------------------------
  UartPC.print("Connecting to ");
  UartPC.println(WIFI_SSID);
  NtpDateTime.ConnectWifi(WIFI_SSID, WIFI_PASSWORD);
  UartPC.print("try connection: ");
  while (!NtpDateTime.IsConnected()) 
  {
    UartPC.print(".");
    delay(333);
  }
  UartPC.print("\r\nConnected to IPAddress: ");
  UartPC.println(NtpDateTime.GetLocalIPAddress());
  NtpDateTime.Initialise(NTPSERVER, GMTOFFSET, DAYLIGHTOFSET);
  Message("NtpDateTime started");
}
//
//
//----------------------------------------------
// Main - Loop
//----------------------------------------------
void loop() 
{ 
  UartPC.print("NtpDateTime["); 
  UartPC.print(NtpDateTime.GetDateTimeS()); 
  UartPC.print("]yymmddhsmsss   Date["); 
  UartPC.print(NtpDateTime.GetDateS());
  UartPC.print("]dd.mm.yyyy    Time["); 
  UartPC.print(NtpDateTime.GetTimeS());
  UartPC.print("]hh:mm:ss"); 
  UartPC.println(); 
  delay(2000);
}
//
//




