Open vijay13sagar opened 2 years ago
Did A research on Time stamp of various Methods and selected a software method to access the time using NTP:
! image
The fundamental operating principle is as follows:
step 1: The client device, such as the ESP8266 (which we use for the project, connects to the NTP server via the User Datagram Protocol (UDP) on port 123. step 2: The client then sends a request packet to the NTP server.
step 3: In response to this request, the NTP server sends a time stamp packet. A time stamp packet contains a variety of data, such as a UNIX timestamp, accuracy, delay, or time zone. step 4: A client can then extract the current date and time from it.
Code to access the Time via using NTP Server
const char ssid = "YOUR_SSID"; const char password = "YOUR_PASS";
const long utcOffsetInSeconds = 3600;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Define NTP Client to get time WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
void setup(){ Serial.begin(115200);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); }
timeClient.begin(); }
void loop() { timeClient.update();
Serial.print(daysOfTheWeek[timeClient.getDay()]); Serial.print(", "); Serial.print(timeClient.getHours()); Serial.print(":"); Serial.print(timeClient.getMinutes()); Serial.print(":"); Serial.println(timeClient.getSeconds()); //Serial.println(timeClient.getFormattedTime());
delay(1000); }
Worked on adding timestamp to the JSON format of the data we are receiving from AWS Node.
// Adding the header files
include
include
// Using the function to get time from millis() function t = millis(); t = t/1000;
// Code in the datafile writing File dataFile = SD.open("Vaisala.txt", FILE_WRITE); if (dataFile) { dataFile.print(t); Serial.print(t); }