Introduction: How to Publish ESP32 Data With NTP Timestamp to the IoT Cloud
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)
Step 1: Prerequisites
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.