Skip to content

Bochaberii/carenuity_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Email Monitor IoT Application - Carenuity Level 3 Challenge

Project Overview

This project is a submission for the Carenuity Level 3 Challenge: API Usage & App Development. It demonstrates practical API integration, IoT development, and power management in an Arduino-based application that monitors important emails and displays them on a real-time OLED screen.

Challenge Context

The Carenuity Level 3 challenge focuses on:

  • Creating custom applications using the Arduino IDE
  • Integrating third-party APIs into IoT projects
  • Leveraging AI assistance (ChatGPT) for code optimization
  • Uploading and sharing projects on the Solution Builder platform
  • Building practical IoT solutions that solve real-world problems

Project Description

This Email Monitor application transforms an ESP32-S2 Mini microcontroller into an intelligent email notification device. It connects to the internet, fetches important email metadata via a Google Apps Script API, and displays the information on an OLED screen—all while optimizing power consumption through deep sleep cycles.

Key Features

WiFi Connectivity - Connects to home/office network for internet access
Google Apps Script Integration - Fetches email data via custom API endpoint
OLED Display - Shows email count and latest subject on 128x64 display
Power Management - Uses deep sleep (~5-minute intervals) for extended battery operation
Real-time Updates - Automatically polls for new important emails
Trim & Parse - Cleans and formats incoming data for reliable display

Hardware Components

Component Details
Microcontroller ESP32-S2 Mini
Display Adafruit SSD1306 OLED (128x64, I2C)
Communication WiFi (built-in) & I2C (display connection)
Pins Used SDA: GPIO 33, SCL: GPIO 35
Power USB or Battery (deep sleep optimized)

Technical Architecture

System Components

┌─────────────────────┐
│   ESP32-S2 Mini     │
│  (Microcontroller)  │
└──────────┬──────────┘
           │
     ┌─────┴─────┐
     │           │
     ▼           ▼
  [WiFi]    [I2C Bus]
     │           │
     │           ▼
     │    ┌────────────────┐
     │    │ SSD1306 OLED   │
     │    │ Display 128x64 │
     │    └────────────────┘
     │
     ▼
 [Google Apps Script API]
     │
     ▼
 [Gmail / Email Service]

Application Flow

  1. Initialization Phase

    • ESP32 boots and initializes I2C communication
    • OLED display activates and displays connection status
    • Device attempts WiFi connection
  2. Connected State

    • Displays "WiFi Online!" confirmation
  3. Main Loop - Data Fetching

    • Makes HTTP GET request to Google Apps Script
    • Receives payload: count|subject
    • Parses data and updates display
  4. Display Update

    • Shows: "IMPORTANT EMAILS:" header
    • Shows: Email count
    • Shows: "LATEST SUBJECT:" header
    • Shows: Most recent email subject
  5. Power Management

    • Logs "Going to sleep for 5 minutes..."
    • Enables deep sleep timer (5 × 60 × 1,000,000 microseconds)
    • Enters ESP deep sleep mode
    • Wakes automatically, repeats from Main Loop

Code Breakdown

Network Configuration

const char* ssid = "Barbara";           // WiFi SSID
const char* password = "Cleopatra123";  // WiFi Password
const char* scriptUrl = "...";          // Google Apps Script endpoint

Display Initialization

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Custom I2C pins for ESP32-S2 Mini
Wire.begin(33, 35);  // SDA=33, SCL=35

HTTP Request & Response Parsing

// Fetches data from Google Apps Script
http.begin(scriptUrl);
int httpCode = http.GET();
String payload = http.getString();
// Parses format: "count|subject"
int splitIndex = payload.indexOf('|');
String count = payload.substring(0, splitIndex);
String subject = payload.substring(splitIndex + 1);

Deep Sleep Implementation

// Converts 5 minutes to microseconds
uint64_t sleepTime = 5 * 60 * 1000000;
esp_sleep_enable_timer_wakeup(sleepTime);
esp_deep_sleep_start();  // The "Magic" Level 3 command

Display Functions

  • showStatus(String msg) - Shows large status messages (WiFi connection, errors)
  • updateDisplay(String count, String subject) - Displays formatted email information

Setup & Installation

Prerequisites

  • Arduino IDE installed
  • ESP32 board support added to Arduino IDE
  • Required libraries:
    • WiFi.h (built-in with ESP32)
    • HTTPClient.h (built-in with ESP32)
    • Wire.h (built-in with ESP32)
    • Adafruit_GFX.h
    • Adafruit_SSD1306.h

Steps

  1. Install Dependencies

    • In Arduino IDE: Sketch → Include Library → Manage Libraries
    • Search and install: "Adafruit GFX" and "Adafruit SSD1306"
  2. Configure WiFi Credentials

    const char* ssid = "Your_Network_SSID";
    const char* password = "Your_Network_Password";
  3. Set Google Apps Script URL

    • Create a Google Apps Script that monitors Gmail
    • Deploy as web app with appropriate permissions
    • Update scriptUrl with your endpoint
  4. Board Selection

    • Tools → Board → ESP32S2 (or your specific variant)
    • Tools → Port → Select your ESP32 port
  5. Upload

    • Sketch → Upload
    • Open Serial Monitor (115200 baud) to verify connection

Google Apps Script Integration

The backend uses Google Apps Script to:

  • Access Gmail API
  • Filter for important emails/labels
  • Return data in format: count|subject
  • Handle authentication and caching

Example response structure:

5|Re: Urgent Project Update - Q1 2025

Power Consumption Optimization

This project uses ESP32 Deep Sleep for power efficiency:

  • Active Time: ~3-5 seconds (WiFi + HTTP + Display)
  • Sleep Time: 5 minutes (uses minimal power)
  • Deep Sleep Current: ~10-100 µA (compared to ~80 mA active)

Result: Approximately 96-98% power reduction compared to continuous operation!

Expected Behavior

Serial Output Example

...
Going to sleep for 5 minutes...

Display States

State 1 - Connecting:

Connecting WiFi...

State 2 - Connected:

WiFi Online!

State 3 - Email Data:

IMPORTANT EMAILS:
> 5

LATEST SUBJECT:
Team Meeting Notes - March

Troubleshooting

Issue Solution
Display not showing Verify I2C address (0x3C), check SDA/SCL pin connections
WiFi won't connect Check SSID/password, verify network compatibility (2.4GHz)
HTTP Error messages Verify Google Apps Script URL is correct and deployed
No data displayed Check Google Apps Script returns correct format (count|subject)
Frequent reboots May indicate power issues or memory problems

Learning Outcomes (Carenuity Level 3)

Technical Competencies Gained

✓ Real-world API integration and HTTP communication
✓ IoT device programming with microcontrollers
✓ I2C display communication protocols
✓ Power management and deep sleep optimization
✓ WiFi connectivity and network debugging

Soft Skills Developed

✓ Problem-solving through API debugging
✓ Time management in multi-component projects
✓ Technical documentation and communication
✓ Community engagement through project sharing

Future Enhancements

  • Add multiple email labels/filters
  • Display email sender information
  • Button control for manual refresh or configuration
  • Battery level indicator
  • Multiple OLED screens for more data
  • Mobile app integration
  • Cloud logging of email trends

References & Resources

Repository Structure

Carenuity_project/
├── code.cpp          # Main Arduino sketch
├── README.md         # This file
└── binary/           # Compiled binary (for Solution Builder)

Submission Information

Challenge Level: 3 - API Usage & App Development
Platform: Solution Builder (https://solutions.carenuity.com)
Reward: DS18B20 Sensor / Oximeter Sensor
Difficulty: Basic
Tutor: Paul


Status: ✅ Completed and Ready for Submission

For questions or to share this project, contact: team@carenuity.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages