Difference between revisions of "WeMOS: NTP Jam Digital"

From OnnoWiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
#include <NTPClient.h>
+
==Code==
#include <ESP8266WiFi.h>
 
#include <WiFiUdp.h>
 
  
const char *ssid    = "ssid";
+
#include <NTPClient.h>
const char *password = "password";
+
#include <ESP8266WiFi.h>
 +
#include <WiFiUdp.h>
 +
 +
const char *ssid    = "ssid";
 +
const char *password = "password";
 +
 +
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()+6);
 +
  Serial.print(":");
 +
  Serial.print(timeClient.getMinutes());
 +
  Serial.print(":");
 +
  Serial.println(timeClient.getSeconds());
 +
  //Serial.println(timeClient.getFormattedTime());
 +
 +
  delay(1000);
 +
}
  
const long utcOffsetInSeconds = 3600;
 
  
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
  
// Define NTP Client to get time
+
==Pranala Menarik==
WiFiUDP ntpUDP;
 
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
 
  
void setup(){
+
* [[WeMOS]]
  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()+6);
 
  Serial.print(":");
 
  Serial.print(timeClient.getMinutes());
 
  Serial.print(":");
 
  Serial.println(timeClient.getSeconds());
 
  //Serial.println(timeClient.getFormattedTime());
 
 
 
  delay(1000);
 
}
 

Latest revision as of 13:34, 23 November 2019

Code

#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char *ssid     = "ssid";
const char *password = "password";

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()+6);
  Serial.print(":");
  Serial.print(timeClient.getMinutes());
  Serial.print(":");
  Serial.println(timeClient.getSeconds());
  //Serial.println(timeClient.getFormattedTime());

  delay(1000);
}


Pranala Menarik