First time setup on Raspberry Pi? Follow our complete guide: 👉 Raspberry Pi Setup Guide
Need to fix script permissions?
bash scripts/fix_permissions.shFind your Arduino:
python3 scripts/find_arduino.pyTest connection:
python3 scripts/test_arduino.pyRepository Name: MASH-IoT
Tech Stack:
- Microcontroller (Arduino): C++ (Hardware Interface)
- Gateway (Raspberry Pi): Python 3.9+
- GUI: Flask Web App (running locally in Chromium Kiosk Mode)
- Database: SQLite (Local) + Firebase (Cloud)
This structure integrates your old utils into a cleaner layout and reflects your tested WiFi provisioning modules.
MASH-IoT/
├── arduino_firmware/ # THE HANDS
│ ├── src/
│ │ ├── main.cpp # Loops: 1. Read Sensors 2. Listen for Serial cmds
│ │ ├── sensors.cpp # SCD41 Logic (SoftWire + Wire)
│ │ ├── actuators.cpp # Relay control (Fan, Mist, Light)
│ │ └── safety.cpp # Watchdog: Turn off all relays if Serial disconnects
│ └── platformio.ini
│
├── rpi_gateway/ # THE BRAIN
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # Orchestrator: Starts Web Server + Serial Loop
│ │ │
│ │ ├── core/ # Core Logic
│ │ │ ├── serial_comm.py # Talks to Arduino (sends commands, gets data)
│ │ │ ├── logic_engine.py # The "Brain": If Temp > 30 -> Fan ON
│ │ │ └── screen.py # Turns HDMI on/off (Energy Saving)
│ │ │
│ │ ├── cloud/ # Connectivity
│ │ │ ├── firebase.py # *Migrated from old repo*
│ │ │ └── sync.py # Offline -> Online syncing logic
│ │ │
│ │ ├── database/
│ │ │ ├── db_manager.py # *Migrated from old repo*
│ │ │ └── models.py # SQL Alchemy or raw SQL schemas
│ │ │
│ │ ├── utils/ # *Heavily Migrated from old repo*
│ │ │ ├── wifi_manager.py # *NEW: Combined Hotspot + Connection logic (Tested)*
│ │ │ └── identity.py # Device ID generation
│ │ │
│ │ └── web/ # The New GUI
│ │ ├── routes.py # Flask Endpoints (Integrates logic from tested app.py)
│ │ ├── templates/ # HTML Files (Jinja2 Templates)
│ │ │ ├── dashboard.html
│ │ │ ├── settings.html
│ │ │ └── wifi_setup.html # *Use HTML_TEMPLATE from app.py here*
│ │ └── static/ # STATIC ASSETS (Served by Flask)
│ │ ├── css/ # Stylesheets (Tailwind output or custom.css)
│ │ ├── js/ # Client-side JavaScript
│ │ └── assets/ # Images, Icons, Fonts
│ │ ├── icons/ # SVG/PNG Icons (Fan, Temp, etc.)
│ │ ├── images/ # Logos, QR Code placeholder
│ │ └── fonts/ # Custom fonts (if offline)
│ │
│ ├── config/
│ │ ├── config.yaml # Thresholds (Temp targets, etc.)
│ │ └── .env # Secrets
│ │
│ └── requirements.txt
│
├── scripts/ # Setup/Install scripts
│ ├── install_dependencies.sh
│ └── setup_kiosk.sh # Auto-configures Chromium boot
│
└── README.md
-
Calibration:
- Able to calibrate SCD41 sensors to standard (using
performForcedRecalibrationor autoCalibration).
- Able to calibrate SCD41 sensors to standard (using
-
Dual Sensor Reading:
- Able to read data from two SCD41 sensors simultaneously.
- Implementation: 1 via Hardware I2C (Grove Hub), 1 via Software I2C (Pins 10/11).
- Differentiation: Tag data as room: "fruiting" vs room: "spawning".
-
Anomaly Filtering (Edge Processing):
- Able to filter out anomalies in data gathering.
- Logic: Filter sudden significant changes (spikes) that last only a short time (e.g., Temp 70+ for 1 sec then back to 23).
- Method: Moving Average Buffer (size 10) or Median Filter.
-
Data Transmission:
- Able to send JSON-formatted data string to Raspberry Pi 3 Model B via USB Serial.
-
Data Ingestion:
- Able to receive and parse JSON data from Arduino Uno R3.
-
Local Storage (Offline Capability):
- Able to save every reading to a local SQLite database immediately.
- Data must persist even if power is lost or internet is down.
-
Cloud Synchronization:
- Able to send aggregated sensor data to record in Cloud (Firebase).
- Logic: Check for internet -> If connected, upload unsynced rows from SQLite -> Mark as synced.
-
Actuation Logic (The "Brain")
- Able to compare sensor readings against
config.yamlthresholds. - Able to send command strings (e.g.,
FAN_ON) back to Arduino.
- Able to compare sensor readings against
-
GUI Hosting:
- Able to host a local Web Server (Flask) accessible via
localhost:5000(Kiosk) andhttp://mash-device.local(Network).
- Able to host a local Web Server (Flask) accessible via
- Flow:
- Onboarding: If no WiFi, show Hotspot setup screen.
- WiFi Connection: User selects SSID and enters password.
- QR Page: Display generated QR code for Mobile App pairing.
- Dashboard: Live view of Fruiting vs. Spawning status.
- Goal: Arduino reads 2x SCD41s (using the Software I2C hack) and accepts Relay commands.
- Test: Open Serial Monitor. You should see:
{ "fruiting": { "co2": 800 }, "spawning": { "co2": 2000 } }. - Test: Type
FAN_ONin Serial Monitor -> Relay clicks.
- Goal: Python script reads that Serial JSON and saves it to SQLite.
- Migration: Adapt
database_manager.pyto specifically store this JSON structure.
- Goal: A Flask page shows the live data.
- Task: Create
dashboard.htmlusing Tailwind CSS (CDN or local). - Task: Use HTMX or simple JS polling (
setInterval) to fetch data from Python every 2 seconds. No complex WebSockets needed yet.
- Goal: Connect to WiFi via GUI.
- Migration: Hook up
wifi_setup.htmlforms to your existingwifi.pyfunctions. - Goal: Sync to Firebase.
| Component | Model/Type | Role | Voltage | Notes |
|---|---|---|---|---|
| Gateway | Raspberry Pi 3 Model B | Master Controller, Web Server, DB Host | 5V (Micro USB) | Logic Level: 3.3V (needs shifter for 5V sensors, but routed via Arduino). WiFi 2.4GHz, Bluetooth 4.1 |
| Microcontroller | Arduino Uno R3 | Hardware Interface (Sensors/Relays), Safety Watchdog | 5V (USB/DC) | Communication: USB Serial (to RPi) |
| Sensor | Model/Type | Qty | Protocol | Voltage | Range (CO2) | Range (Temp) | Range (RH) | Wiring Strategy |
|---|---|---|---|---|---|---|---|---|
| CO2/Temp/Humidity | Sensirion SCD41 | 2 | I2C (0x62) | 3.3V - 5V | 400-5000 ppm | -10°C to 60°C | 0% to 100% | 1: HW I2C (A4/A5) via Grove Hub; 2: SW I2C (D10/D11) |
| Device | Model/Type | Role | Trigger | Load Capacity |
|---|---|---|---|---|
| Relay Module | 8-Channel 5V Relay Module | Switch High Voltage AC Loads | Logic Low/High | 10A @ 250VAC |
| Exhaust Fans | 12V DC | Airflow | - | - |
| Intake Fans | 12V DC | Airflow | - | - |
| Humidifier Fan | 24V DC | Humidity Control | - | - |
| Humidifier | 45V Mist Maker | Humidity Control | - | - |
| Grow Lights | 5V LED Strips | Lighting | - | - |
- Grove I2C Hub: Passive Splitter (used for Sensor 1)
- Power Supplies: - 5V 2.5A+ Adapter for Raspberry Pi - 12V Adapter for Fans/Lights (if DC) - 12V 3A Adapter for Relay Power Supply - 9V for USB for Arduino - 48V Power supply for Mist