Most of the times, I want my ESP8266 board to communicate with the server through a securer channel such as MQTT over TLS or HTTPS. However, to verify the certification, system’s date/time has to be in a proper configuration.
Since ESP8266 is designed to have the network, I believe NTP is definitely the first choice and is the easiest one to use. In this post, I will show you how to get date/time and set it by using NTP.
Dummy project
A dummy project is set up for this post. And of course, it can be a part of a real project since the WWW is very important to my most of side projects. The board will do,
- Connect to the WiFi network;
- Use the
GET
method communicate with www.example.com every 5 seconds; - Flash build-in LED twice if 200 was returned by the server;
- Or flash build-in LED 5 times if an error occurred.
Flash LED is the easiest part. But remember to put pinMode(LED_BUILTIN, OUTPUT);
in the very beginning to initialise the output pin.
void blink(int t) {
for(int i = 0; i < t; i ++) {
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
}
}