This API:
- collects live data from remote, microcontroller-based environmental sensors and stores to a cloud-hosted PostgreSQL database
- provides quantitative time series aggregation and analysis based on SQL queries
- creates a source material database for LLM chat queries from periodic data snapshots and uploaded PDFs and web links
- combines numeric data calculations and semantic retrieval in summarizing current conditions and responding to chat queries
The MVP prototype uses an Espressif ESP32-S3-DevKitC-1 microcontroller with an AM2320 Digital Temperature & Humidity Sensor (I2C interface).
The PostgreSQL database is hosted on a Supabase free tier plan with the pgvector extension that enables vector storage and similarity search.
The backend API uses the Python FastAPI framework, hosted in a Google Cloud Run serverless container on a free tier plan.
The frontend (separate repo - esp32_ui) uses the Next.js server-side TypeScript-React framework, hosted on a Vercel free tier plan at https://esp32ui.vercel.app with Material UI design system and components from Devias Material Kit Pro.
Vector embedding, RAG retrieval, and LLM chat run on a local machine with Ollama. I am testing a variety of free open-weight LLMs running on Ollama, including gemma2 (Google), llama3 (Meta), gpt-oss (OpenAI), and qwen2.5 (Alibaba). For text embedding, I am testing the bge-m3 and nomic-embed-text models.
The LLM chat uses a multi-agent framework with Planning, Retrieval, and Execution personas.
- Planning
- interpret the user question
- infer intent, metric, and time range
- choose deterministic SQL retrieval, vector retrieval, or a hybrid path
- Retrieval
- fetch raw readings, aggregated readings, snapshots, or literature/doc chunks
- combine structured and unstructured context for grounded answers
- UI Execution
- surface answers, charts, citations, and next actions in the separate
esp32_uifrontend - keep the backend focused on APIs, grounding, and orchestration rather than presentation
- surface answers, charts, citations, and next actions in the separate
I am currently testing three open source agent development frameworks:
- langchain-ollama integration
- langchain-text-splitters - packages for splitting up PDFs and websites as embeddable chunks of text with metadata
- llama-index-llms-ollama integration
- SentenceSplitter, SimpleWebPageReader, SimpleDirectoryReader split up PDFs and websites
- SQLAutoVectorQueryEngine integrates SQL queries with RAG retrieval
- (details to come)
esp32_api/
├── server/ # Server root
│ ├── app/ # FastAPI application package
│ │ ├── api/ # HTTP routes (ingest, timeseries, weather, rag)
│ │ ├── db/ # Supabase/Postgres query helpers
│ │ ├── rag/ # Agentic planning + retrieval + indexing
│ │ ├── scripts/ # Background loop(s)
│ │ └── main.py # FastAPI entry point
├── device/ # MicroPython scripts for ESP32-S3-DevKitC-1
├── docs/ # Project documentation and architecture notes
├── .env.example # Example environment vars
├── requirements.txt # Python dependencies
└── README.md # This file
POST /ingest
Ingests sensor payloads from devices.
GET /ping
Basic health check for API and backend service wiring.
GET /latest
Returns the latest ingested reading when authorized.
GET /timeseries
Returns filtered time-series data based on query parameters such as table, start_ts, end_ts, device_id, bucket, and aggregate_mode.
GET /timeseries/summary
Returns summary statistics for the raw readings table over an optional time range and device filter.
GET /weather/hourly
Fetches hourly weather data from NOAA or Open-Meteo for comparison with sensor readings.
GET /rag/queryandPOST /rag/query— answer natural-language questions using planning plus hybrid retrieval over structured sensor data and indexed documentsPOST /rag/index— batch-embed recent time-series snapshots into the vector storePOST /rag/rebuild— rebuild snapshot indexing from the full historyPOST /rag/ingest_docs— split PDFs and web pages into chunks and embed them in the document vector store
-
Python 3.11+
-
PostgreSQL instance with credentials available (e.g. Supabase)
-
pgvectorextension installed in PostgreSQL for vector embeddings (in Supabase UI, installvectorunder Database > Extensions)
Clone the repository and install dependencies:
git clone https://github.com/postoccupancy/esp32_api.git
cd esp32_api
pip install -r requirements.txt
Set up environment variables (see Configuration below), then start the API:
cd server
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
Environment variables are used to control database connections. Copy .env.example to .env and fill in the required values.
This repository follows a structured documentation layout inspired by best practices. The primary documentation is housed under the docs/ folder. Key sections include:
Technical Notes
docs/2025-12-17-open-source-agent-stack.md— Mapping out the open source agent development toolkit.docs/2026-01-27-rag-setup-and-next-steps.md— Discussion of how the RAG endpoints work, and how I plan to use them in the visualization interface.docs/architecture.md— Current architecture with explicit Planning, Retrieval, and UI Execution layers.
Contributions are welcome! For structured guidelines, see the CONTRIBUTING.md once created. For now:
-
Fork the repo
-
Create a descriptive branch
-
Open a pull request with context and tests (when available)
This project is open source and released under the BSD-3 Clause License.
Details to come...