Introduction: How to Publish ESP32 Data With NTP Timestamp to the IoT Cloud

About: IoT Maker, co-founder of asksensors.com

In many applications, users need to send their data along with he local timestamp of the values to be sent in the payload to the AskSensors IoT cloud.

The timestamp format is UNIX Epoch time : the number of milliseconds that have elapsed since January 1, 1970 (midnight UTC/GMT)

This tutorial presents how to connect your ESP32 to the NTP servers, timestamp measurements, and publish these measurements with timestamps to the cloud over HTTPS.

Step 1: Prerequisites

  • Active AskSensors account: Subscribe to a 15 days free trial(SIMPLE, PRO or GURU).
  • Follow this quick start guide to create a new sensor device and get familiar with AskSensors.
  • Connect ESP32 to the AskSensors Cloud as shown in the this guide.

Step 2: Material You Need

  • ESP32 development board.
  • Computer running Arduino software (version 1.8.7 or higher).
  • USB micro cable to connect the ESP32 board to the computer.

Step 3: Software

  • Install the NTP Client library for the Arduino IDE: Navigate to the Sketch > Include Library > Manage Libraries.
  • Look for NTPClient by Fabrice Weinberg. Click on that entry, and then select Install.
  • Download this demo from the AskSensors Github page.

Modify the following :

const char* wifi_ssid = ".........."; // SSID

const char* wifi_password = ".........."; // WIFI

const char* apiKeyIn = ".........."; // API KEY IN

const unsigned int writeInterval = 25000; // write interval (in ms)

Step 4: Run Your Test

  • Connect your ESP32 board to the computer via serial/USB and upload the code using the Arduino IDE.
  • Open a serial terminal. It should show your ESP32 connected to the NTP server, timestamp data and send it to the AskSensors IoT cloud.

  • Return back to the AskSensors App and check your sensor data stream.

Step 5: Share Your Experience!

A detailed documentation for connecting devices to the AskSensors is available here.

You are welcome to join the AskSensors community, and share your experience.