Smart Cities - Tiny House at Home (Alternate way)

From Sensors in Schools
Jump to navigation Jump to search

Tiny House: Smart Temperature Monitoring System

Tiny House is a weather and temperature monitoring system for small homes, using a Raspberry Pi Pico W, multiple sensors, and MQTT for remote data access. This wiki provides setup, usage, troubleshooting, and API documentation.

Contents

Introduction

Tiny House monitors temperatures in multiple locations using high-accuracy sensors. Data is sent to an MQTT broker for real-time viewing via graphs or a web dashboard. The system is robust, supports offline data storage, and is easy to set up.

Hardware Setup

Required Components

  • Raspberry Pi Pico W
  • PiicoDev TMP117 sensor
  • 3x DS18X20 temperature sensors
  • PiicoDev RTC module
  • Relay, motor, and wiring
  • WiFi access

Pin Connections

Component Pin on Pico W
Motor DIR GP21 Motor PWM GP26 Relay GP15 UART GPIO 0 (pin 1 pair) Temp Sensors GPIOs 0 / 2 / 3 Reset Button GP22 I2C (TMP117 + RTC) SDA = GP4, SCL = GP5
  • Daisy-chain TMP117 and RTC using PiicoDev connectors.
  • Connect temp sensors to the appropriate GPIO pins.
  • Power on your Pico W.

Software Setup

  1. Install MicroPython on your Pico W.
  2. Install Thonny IDE (or another MicroPython IDE).
  3. Upload all project files to the Pico W.
  4. Edit env.py with your WiFi and MQTT details.
  5. Run main.py using Thonny.

Configuration

Edit env.py to set:

  • WLANSSID: WiFi network name
  • WLANPASSWD: WiFi password
  • MQTT_CLIENT_ID: Unique MQTT client ID
  • MQTT_SERVER: MQTT broker address
  • MQTT_USER: MQTT username
  • MQTT_PASSWORD: MQTT password
  • MQTT_TOPIC_DATA: Topic for temperature data
  • MQTT_TOPIC_STATUS: Topic for system status

File Structure

MicroPico/
├── main.py               # Main logic
├── env.py                # WiFi & MQTT config
├── lib/
│   ├── PiicoDev_TMP117.py
│   ├── PiicoDev_Unified.py
│   ├── PiicoDev_RV3028.py
│   └── umqtt/simple.py
weatherGraph.py           # Local graphing
dummy_data_publisher.py   # Simulated test data
Graph-Site-Docker/
├── flaskSite.py
├── Docker_Build-and-Run.sh

Usage

  1. Flash the MicroPico files to your Raspberry Pi Pico W.
  2. Ensure env.py is configured with your WiFi and MQTT credentials.
  3. Set up an MQTT broker (e.g., Mosquitto, HiveMQ, or Adafruit IO).
  4. Power up the Pico W to start collecting and publishing temperature data.

Pump and Relay Control

  • The system can control a pump (forward/backward/stop) and a relay for automation.
  • See main.py for example usage.

Local Graphing

  1. Install Python 3 and required packages: pip install -r requirements.txt
  2. Run python weatherGraph.py to display real-time temperature graphs.

Web Dashboard

  1. Navigate to Graph-Site-Docker directory.
  2. Create a .env file with your API keys and MQTT settings.
  3. Run ./Docker_Build-and-Run.sh false true 1.0.0 to launch the web server.
  4. Access the dashboard at http://localhost:5000

Manual Docker Build/Run

docker buildx build --platform linux/amd64,linux/arm64 \
  -t jezzcomputers/pyapp-image:latest \
  --push .
docker run -d --restart unless-stopped --name pyapp-container --env-file <path-to-your-env-file> -p 5000:5000 jezzcomputers/pyapp-image:latest

Testing Without Sensors

Run python dummy_data_publisher.py to simulate temperature data for testing the dashboard and graphing tools.

Troubleshooting

Problem Solution
Pico not connecting Check env.py WiFi settings, ensure network is available. MQTT issues Ensure broker is running, test with simulator, check credentials. Sensor errors Recheck wiring or use dummy_data_publisher.py. Docker site not working Verify Docker is installed and .env is valid.

Additional Tips

  • Check the status LED on the Pico W (solid means connected).
  • Use docker logs pyapp-container for Docker troubleshooting.
  • For sensor problems, try running the dummy data publisher.

API Documentation

MQTT Topics

  • JezzComputers/feeds/data: Publishes temperature data.
  • JezzComputers/feeds/status: Publishes system status.

Data Format Example

{
  "timestamp": {
    "year": 2023,
    "month": 6,
    "day": 15,
    "hour": 14,
    "minute": 30,
    "second": 45
  },
  "outdoor_temp": 25.5,
  "in_house_temp": 22.3,
  "thermal_mass_temp": 20.8,
  "cont_box_temp": 24.1,
  "error": null
}

Status Format Example

{
  "context": "System Status",
  "doClearLogs": "false",
  "year": 2023,
  "month": 6,
  "day": 15,
  "hour": 14,
  "ampm": "PM",
  "minute": 30,
  "second": 45
}

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this code as long as you include the original copyright.


For questions, improvements, or to contribute, visit the project repository or use the discussion page.