Cov txheej txheem:

Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai: 6 Kauj Ruam
Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai: 6 Kauj Ruam

Video: Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai: 6 Kauj Ruam

Video: Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai: 6 Kauj Ruam
Video: Zoo Siab Nrog Koj - Paj Tsua Thoj [ Official MV ] Nkauj Tawm Tshiab 2022 2024, Kaum ib hlis
Anonim
Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai
Mloog Internet: Zaum Hnub thiab Sijhawm Nrog OLED Siv ESP8266 NodeMCU Nrog NTP Raws Cai

Nyob zoo cov txiv neej hauv cov lus qhia no peb yuav tsim lub moos internet uas yuav tau txais sijhawm los ntawm internet yog li qhov haujlwm no yuav tsis xav tau RTC los ua haujlwm, nws tsuas yog xav tau kev ua haujlwm internet txuas

Thiab rau txoj haujlwm no koj xav tau esp8266 uas yuav muaj wifi kom tau txais kev siv internet thiab tso saib kom pom lub sijhawm ntawm nws thiab esp8266 yuav nqa sijhawm los ntawm internet siv NTP raws tu qauv, ntp sawv rau lub sijhawm network raws tu qauv, yog li muaj cov ntp servers ntawm lub vev xaib uas tau siv los ua haujlwm sib tham hauv computer thiab peb yuav siv bthose servers kom tau sijhawm nyob hauv peb qhov haujlwm.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

rau qhov project no koj yuav xav tau cov hauv qab no:

Esp8266/nodemcu

Oled ssd1306 0.96"

Jumper xov hlau

Cov qhob cij

Usb kab

Kauj ruam 2: Kev sib txuas

Kev sib txuas
Kev sib txuas

Qhov 4-pin OLED zaub sib txuas lus nrog ESP8266 tus qauv siv I2C raws tu qauv, hauv qab no yog daim duab kos duab thiab cov rooj sib txuas los txuas OLED I2C pins nrog NodeMCU los tso saib Internet sijhawm.

Kauj ruam 3: Rub cov tsev qiv ntawv

Rub tawm Tsev Qiv Ntawv
Rub tawm Tsev Qiv Ntawv
Rub tawm Tsev Qiv Ntawv
Rub tawm Tsev Qiv Ntawv

Nco ntsoov tias koj rub tawm SD1306 cov tsev qiv ntawv hauv Koj li Arduino lub tswv yim raws li qhia hauv duab thiab kom ntseeg tau tias koj Adafruit GFX lub tsev qiv ntawv ib yam, yog tias tsis yog ces nruab ob lub tsev qiv ntawv no.

Hauv koj Arduino IDE mus rau Libraries tus thawj coj thiab tshawb rau NTP thiab tsuas yog rub NTP cov tsev qiv ntawv raws li kuv rub tawm, xa duab rau kev pab ntxiv.

Kauj ruam 4: NTP yog dab tsi

NTP yog dab tsi
NTP yog dab tsi

NTP yog ib qhov qub tshaj plaws kev sib tham Internet raws tu qauv (IP) rau synchronizing moos ntawm lub computer network. Nws tau tsim los ntawm David L. Mills ntawm Tsev Kawm Qib Siab Delaware xyoo 1981. Cov txheej txheem no tuaj yeem siv los sib txuas ntau lub network rau Kev Sib Koom Ua Haujlwm Sijhawm (UTC) hauv ob peb milliseconds. UTC yog thawj lub sijhawm tus qauv uas lub ntiaj teb tswj hwm lub moos thiab sijhawm. UTC tsis hloov pauv thiab txawv rau thaj chaw sib txawv. NTP siv UTC raws li lub sijhawm siv thiab muab sijhawm raug thiab sib koom ua ke thoob plaws Internet.

NTP ua haujlwm ntawm tus qauv hierarchical client-server. Tus qauv saum toj kawg nkaus muaj lub moos siv hu ua "stratum0" zoo li lub moos atomic, xov tooj cua tsis zoo, GPS, GSM uas tau txais sijhawm los ntawm lub hnub qub. Cov servers uas tau txais sijhawm los ntawm stratum0 raug hu ua "stratum1" thiab cov servers uas tau txais sijhawm los ntawm stratum1 hu ua "stratum2" thiab ntxiv rau. Qhov no mus ntxiv thiab qhov tseeb ntawm lub sijhawm mus zuj zus tom qab txhua theem. NTP txiav txim siab xaiv qhov zoo tshaj plaws ntawm ob peb lub sijhawm muaj peev xwm los ua ke uas ua rau nws ua txhaum-ua siab ntev tuaj yeem ua raws. Yog li ntawm no hauv txoj haujlwm no, peb tau txais sijhawm los ntawm NTP server siv ESP8266 NodeMCU thiab qhia nws ntawm OLED zaub. Qhov zoo ib yam ntawm Internet moos yog tsim los ntawm kev siv ESP32 hauv kev qhia yav dhau los.

Kauj Ruam 5: Coding Tshooj

Coding Tshooj
Coding Tshooj

Txhawm rau thov hnub thiab sijhawm, pib lub sijhawm cov neeg siv nrog chaw nyob ntawm NTP servers. Txhawm rau kom raug dua xaiv qhov chaw nyob ntawm NTP cov servers uas nyob ze rau koj thaj chaw. Nov peb siv “pool.ntp.org” uas muab cov servers los ntawm thoob ntiaj teb. Yog tias koj xav xaiv cov servers los ntawm Asia koj tuaj yeem siv "asia.pool.ntp.org". timeClient kuj tseem siv UTC lub sijhawm offset hauv milliseconds ntawm koj lub sijhawm. Piv txwv li, UTC offset rau Is Nrias teb yog +5: 30 yog li peb hloov qhov no offset hauv milliseconds uas yog sib npaug 5*60*60 +30*60 = 19800.

Thaj tsam. UTC lub sijhawm offset (teev thiab feeb). UTC lub sijhawm offset (vib nas this)

INDIA +5: 30 19800

LONDON 0:00 TS 0

NEW YORK -5: 00 -18000

Thov luam cov cai hauv qab no & nkag mus rau koj li wifi & password hauv tus lej & Nkag mus rau lub sijhawm offset hauv cov cai ces rub nws mus rau koj cov laug esp8266.:

#include "NTPClient.h" #include "ESP8266WiFi.h" // muab ESP8266 cov haujlwm Wi-nkaus tshwj xeeb uas peb tau hu los txuas rau network #suav nrog "WiFiUdp.h" // ua haujlwm xa thiab tau txais UDP pob

#suav nrog "SPI.h" // SPI rau cuam tshuam nrog OLED nrog NodeMCu

#suav nrog "Adafruit_GFX.h"

#suav nrog "Adafruit_SSD1306.h"

#define SCREEN_WIDTH 128 // OLED zaub dav, hauv pixels

#define SCREEN_HEIGHT 64 // OLED zaub siab, hauv pixels

#define OLED_RESET -1

Adafruit_SSD1306 zaub (SCREEN_WIDTH, SCREEN_HEIGHT, & Hlau, OLED_RESET);

constchar *ssid = "yourwifissid";

const char *password = "yourwifipass";

WiFiUDP ntpUDP;

NTPClient timeClient (ntpUDP, "pool.ntp.org", 19800, 60000);

String arr_days = {"Hnub Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

Txoj hlua hnub tim _ sijhawm; // Koj tuaj yeem hais qhia lub sijhawm server pas thiab qhov offset (hauv vib nas this, tuaj yeem hloov pauv tom qab nrog setTimeOffset ()). Ntxiv rau koj tuaj yeem hais qhia // ncua sijhawm hloov tshiab (hauv milliseconds, tuaj yeem hloov pauv siv setUpdateInterval ()).

void teeb tsa ()

{

Serial.begin (115200);

WiFi.begin (ssid, password);

thaum (WiFi.status ()! = WL_CONNECTED)

{

ncua (500);

Serial.print (".");

}

yog (! display.begin (SSD1306_SWITCHCAPVCC, 0x3C))

{

Serial.println (F ("SSD1306 faib tsis tau"));

rau (;;); // Tsis txhob ua ntxiv, voj ib si

}

display.clearDisplay ();

display.setTextSize (2); // Kos 2X-teev cov ntawv

display.setTextColor (WHITE);

display.setCursor (5, 2);

display.println ("Zoo Siab Txais Tos");

display.println ("qhia");

display.println ("Project");

display.display ();

ncua (3000);

timeClient.begin ();

}

void lub voj ()

{

timeClient.update ();

display.clearDisplay ();

Serial.println (timeClient.getFormattedTime ());

display.setTextSize (2); // Kos 2X-teev cov ntawv

display.setTextColor (XEEB);

display.setCursor (0, 2);

int hh = timeClient.getHours ();

int hli = timeClient.getMinutes ();

int ss = timeClient.getSeconds ();

yog tias (hh> 12)

{

hh = hh-12;

display.print (hh);

display.print (":");

display.print (hli);

display.print (":");

display.print (ss);

display.println ("PM");

}

lwm tus

{

display.print (hh);

display.print (":");

display.print (hli);

display.print (":");

display.print (ss);

display.println ("AM");

}

int hnub = timeClient.getDay ();

display.println ("'"+arr_days [hnub]+"'");

date_time = timeClient.getFormattedDate ();

int index_date = date_time.indexOf ("T");

Txoj hlua hnub = date_time.substring (0, index_date);

Serial.println (hnub tim);

display.println (hnub tim);

display.display ();

// Qhia thawj kab ntawv}

Kauj Ruam 6: Tau Hnub & Sijhawm

Tau Hnub & Sijhawm
Tau Hnub & Sijhawm

yog tias koj txuas txhua yam kom raug thiab tso cov cai kom raug zoo ib yam ces koj yuav tuaj yeem pom koj ntp moos ua haujlwm ntawm oled zaub li kuv li hauv kev ua haujlwm hauv oled zaub. Thov xa daim duab rau tso tawm.

Pom zoo: