How rajkhare05/smart-bin works
Purpose
Smart Bin is an IoT waste-bin monitoring system. An ESP8266/Arduino-side sketch collects hardware signals (documented components include HC-SR04 distance sensing and SIM800L connectivity), while Node.js services expose bin data and Telegram-based user interaction.
Device Firmware Boundary
The embedded device program is concentrated in esp.ino. It is the physical-system boundary: it should read bin/sensor state and communicate it upstream over the ESP8266’s network connection. Hardware dependencies are described in README.md, including ESP8266, Arduino Nano, SIM800L, and HC-SR04.
Backend Service
The server is a Node.js application rooted at server/index.js, with runtime settings in server/config.js and dependencies declared by server/package.json. This service is the likely ingestion/API boundary between deployed bins and client-facing automation.
Persistent State
server/dump.rdb indicates Redis is used for persisted server state. Redis likely holds current bin readings, location/status records, or other fast-changing device data. The backend owns the boundary between incoming device updates and this datastore.
Telegram Bot Interface
A separate Node.js Telegram bot process is rooted at telegram-bot/index.js, configured by telegram-bot/config.js, and packaged independently in telegram-bot/package.json. This separation allows messaging credentials, polling/webhook behavior, and conversational handling to evolve independently from the device/API service.
Command and Callback Routing
Bot interactions are organized by Telegram interaction type:
• Text/basic commands: telegram-bot/commands/basic.js
• Inline callback handling: telegram-bot/callbackQueries/city.js
The city callback module suggests a user flow where users select or filter bin information by city. The bot is the human-facing control/read boundary; it should query backend-owned state rather than communicate directly with embedded devices.
Primary Flow
1. Sensors attached to the bin produce measurements in esp.ino.
2. The firmware sends measurements/status to the Node backend at server/index.js.
3. The backend validates or transforms updates and stores operational state in Redis, represented by server/dump.rdb.
4. Telegram users issue commands or select city callbacks through telegram-bot/index.js.
5. Bot handlers in telegram-bot/commands/basic.js and telegram-bot/callbackQueries/city.js retrieve and present relevant bin information.
Runtime Topology
There are three material runtimes: embedded ESP8266 firmware, the Node.js backend, and the Node.js Telegram bot. Redis is the state infrastructure, and Telegram is the external messaging platform. Configuration is split per Node process (server/config.js and telegram-bot/config.js), implying deployment and credential boundaries between API/storage concerns and bot concerns.
Main entry points: telegram-bot/index.js Bot Runtime · server/index.js Ingestion API · esp.ino ESP8266 Firmware · basic.js Basic Commands
Components 12
Embedded Device
- Bin Sensors · HC-SR04 and bin hardware provide measurements.
README.md - ESP8266 Firmware · Reads bin state and sends upstream updates.
esp.ino
Backend Service
- Backend Settings
server/config.js - Ingestion API · Validates device updates and serves bin state.
server/index.js - Backend Dependencies
server/package.json - Redis State · Stores current operational bin data.
server/dump.rdb
Telegram Bot
- Bot Runtime · Human-facing Telegram interaction boundary.
telegram-bot/index.js - Bot Settings
telegram-bot/config.js - Basic Commands
telegram-bot/commands/basic.js - City Callbacks · Handles city selection or filtering.
telegram-bot/callbackQueries/city.js - Bot Dependencies
telegram-bot/package.json
Other components
- Telegram Platform
Connections 13
- Bin Sensors → ESP8266 Firmware: measurements
- ESP8266 Firmware → Ingestion API: bin updates
- Backend Settings → Ingestion API: configures
- Backend Dependencies → Ingestion API: packages
- Ingestion API → Redis State: stores state
- Telegram Platform → Bot Runtime: updates
- Bot Runtime → Telegram Platform: responses
- Bot Settings → Bot Runtime: configures
- Bot Dependencies → Bot Runtime: packages
- Bot Runtime → Basic Commands: routes commands
- Bot Runtime → City Callbacks: routes callbacks
- Basic Commands → Ingestion API: queries bin data
- City Callbacks → Ingestion API: filters by city