This project shows you how to connect to NTP server using ESP32 simulator and update the time on the LCD!

I will show you how to simulate ESP32 and create an IoT project in this project. You will learn how to read the NTC time over the internet and display the time on the LCD!

ESP32 IoT demo project is an easy-to-use project that will help you understand the ESP32 Wi-Fi NTP (Network Time Protocol). Let us get started...👷‍♂️

What will this ESP32 simulation project do?

  1. Initializes LCD to display status messages and Time information
  2. Connect to a WiFi network 
  3. Call ConfigTime to configure time from NTP server

NTP Server -> pool.ntp.org

Below you will find the connection diagram

Wokwi ESP32 IoT simulator

Connection diagram for the NTP IoT demo for Wokwi Arduino Simulator

        The Complete code

#include <WiFi.h>

#include <TimeLib.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);

#define NTP_SERVER "pool.ntp.org"

#define UTC_OFFSET 0

#define UTC_OFFSET_DST 0

void spinner() {

static int8_t counter = 0;

const char* glyphs = "\xa1\xa5\xdb";

LCD.setCursor(15, 1);

LCD.print(glyphs[counter++]);

if (counter == strlen(glyphs)) {

counter = 0;

}

}

void printLocalTime() {

struct tm timeinfo;

if (!getLocalTime(&timeinfo)) {

LCD.setCursor(0, 1);

LCD.println("Connection Err");

return;

}

LCD.setCursor(8, 0);

LCD.println(&timeinfo, "%H:%M:%S");

LCD.setCursor(0, 1);

LCD.println(&timeinfo, "%d/%m/%Y %Z");

}

void setup() {

Serial.begin(115200);

delay(10);

LCD.init();

LCD.backlight();

LCD.setCursor(0, 0);

LCD.print("Connecting to ");

LCD.setCursor(0, 1);

LCD.print("WiFi ");

WiFi.begin("Wokwi-GUEST", "");

while (WiFi.status() != WL_CONNECTED) {

delay(250);

spinner();

}

Serial.println("");

Serial.println("WiFi connected");

Serial.print("IP address: ");

Serial.println(WiFi.localIP());

LCD.clear();

LCD.setCursor(0, 0);

LCD.println("Online");

LCD.setCursor(0, 1);

LCD.println("Updating time...");

configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);

}

void loop() {

printLocalTime();

delay(250);

}
    

ESP32 Simulation link

https://wokwi.com/arduino/projects/321525495180034642


ESP32 NTP Client.gif

More about Wokwi ESP32 Simulator

ESP32 Simulator - Wokwi supports two ESP32 boards..(more on the way ;) ). Most of the features are available or in progress.. at the time of writing this article following components of the ESP32 simulator were fully functional

  • Processor core
  • GPIO
  • PSRAM
  • UART
  • I2C
  • LEDC PWM
  • WiFi
  • ADC
  • RNG
  • AES Accelerator
  • SHA Accelerator
  • RSA Accelerator 

Please follow the link for the latest updates on the Wokwi ESP32 simulator features

More about Wokwi ESP32 Wi-Fi

You can provide full internet access to the ESP32 component on the simulator  using a Wokwi gateway. You can use the Wokwi ESP32 simulator and simulate an IoT virtual project in several use case scenarios.. for example: 

  • Connect to MQTT servers to send sensor data
  • Query web services over HTTP, HTTPS, and web sockets
  • Run an HTTP server inside the ESP32 and connect to it from your browser (requires the Wokwi IoT Gateway)

Suggestions/comments?

Suppose you need any help with the simulator; many Wokwi users are happy to help. You can also share what you liked and did not like in the article. Could you share it in the comments below 😉?

Facebook group: https://facebook.com/groups/wokwi

Discord: https://wokwi.com/discord

see you until next time 🌟

share Open-Tech
Hardware enthusiast with ample interest in Arduino projects