Skip to content

Latest commit

 

History

History
84 lines (49 loc) · 3.5 KB

File metadata and controls

84 lines (49 loc) · 3.5 KB

⏱️ ESP32-MongoTimer: Full Stack IoT Data Logger

Project Overview

This project demonstrates a complete, end-to-end Internet of Things (IoT) data pipeline. An ESP32 microcontroller (the client) sends time data (or any sensor data) via HTTP POST requests to a Node.js server (the API). The server then securely logs this data into a MongoDB Atlas cloud database (the backend).

This setup is ideal for logging sensor readings, environmental data, or simple time stamps from a remote device to a centralized cloud database for analysis and visualization.

🚀 Getting Started

To get this project running, you will need to set up three main components: the MongoDB Atlas database, the Node.js server, and the ESP32 client.

📝 Prerequisites

Before starting, ensure you have the following installed:

  • Node.js & npm (Node Package Manager)
  • Arduino IDE (with ESP32 board support)
  • Git (for version control)

Project Commands

You will need to install the necessary Node.js packages. Run the following commands in your server directory:

npm init -y
npm install express body-parser mongodb

⚙️ Setup and Installation

Follow these steps precisely to get your entire data pipeline running.

1. Backend Setup: MongoDB Atlas

Steps:

  • Create MongoDB account
  • Create a cluster and db user pw
  • Copy username password and connection string (This will be placed in your Node.js server code).

2. Middleware Setup: Node.js Server

The server listens for incoming HTTP POST requests from the ESP32 and performs the database write operation.

  1. Create your server files (server.js, package.json, etc.).
  2. Replace your connection string in server.js with the full URI copied from MongoDB Atlas.
  3. Set the hostname to '0.0.0.0' to allow connections from your ESP32 device.
  4. Run the server: node server.js

3. ESP32 Client Setup

The ESP32 needs to be configured with the network details and the specific IP address of your running server.

  • Write ESP32 code, replace with your ssid, pw and local ip address using ipconfig
  • Upload the code to your ESP32.

4. Windows Networking Configuration (Crucial for Connection)

Your Windows machine's firewall and network settings must be configured to allow external connections from the ESP32. These steps often fix the common "Connection Refused" error.

  • Make the Wifi network private in settings (Settings $\rightarrow$ Network & Internet $\rightarrow$ Properties $\rightarrow$ Network profile type: Private).
  • Make a new inbound rule in windows defender firewall to accept from port you want to use for POST request (Port 3000, or whichever port you are using).

✅ Testing and Verification

Once everything is set up, you can verify the data flow.

  • Upload your code and see in serial monito if it works! Look for HTTP response code 200 to confirm a successful POST.
  • Open MongoDB Database Explorer to find your newly created database with some entries that ESP32 sent! Confirm that the data is arriving in your collection.

⚠️ Security Warning

DO NOT COMMIT SECRETS TO GIT.

Your MongoDB Atlas connection URI contains your username and password. This URI should NEVER be committed to your repository. Use Environment Variables and a .gitignore file to exclude the file containing the URI (e.g., a .env file).

If you leaked your URI, immediately rotate your database password in MongoDB Atlas!