Creating a Simple Temperature Monitoring App with Raspberry Pi

Oct 9, 2021 | Programming

In this article, we will take you through the process of setting up a simple temperature monitoring application using Raspberry Pi devices. You will learn how to aggregate temperature data from various remote Pi devices and display it on a master Pi dashboard. Get ready to transform your home into a smarter, more temperature-aware space!

Application Overview

The architecture of this project uses one master Raspberry Pi to collect and display temperature data from multiple remote Pi devices placed throughout your home. It emphasizes the lightweight nature of remote devices, making it possible to use lower power Raspberry Pi models effectively.

Prerequisites

  • Raspberry Pi Model 2 B for master Pi
  • Raspberry Pi A+ or Zero for remote Pis
  • Raspbian OS installed on microSD cards
  • Networking (either LAN or WiFi) configured for each Pi

Quickstart with Vagrant

Before diving into setup, make sure you have your environment ready for hacking using Vagrant:

  1. Install Vagrant, VirtualBox, and Ansible.
  2. Navigate to the playbooks directory and run:
  3. ansible-galaxy install -r requirements.yml
  4. Return to the main directory and execute
  5. vagrant up

Overall Setup

Before installing any software, ensure Ansible is available on your system. Follow these steps:

  1. Copy example.config.yml to config.yml and inventory-example to inventory.
  2. Update the values in both files to reflect your environment and Raspberry Pi IP addresses.
  3. Run ansible-galaxy install -r requirements.yml in the playbooks directory to install Ansible roles.

Setting Up the Master Raspberry Pi

The master Pi functions as the primary data logger and dashboard for temperature readings. Here’s how to get started:

  1. Run the Ansible playbook to build the master Pi:
  2. ansible-playbook -i config/inventory playbooks/master/main.yml

Setting Up the Remote Raspberry Pis

The remote Pis will collect temperature data and send it to the master Pi. Follow these steps:

  1. Before running the playbook for the remote devices, create a file named after each remote’s hostname or IP inside config/host_vars.
  2. Run the appropriate Ansible playbook to set up the remote Pis:
  3. ansible-playbook -i config/inventory playbooks/remote-monitor/main.yml

Connecting Sensors to the Raspberry Pi

To accurately monitor temperature, you’ll need to connect the DS18B20 temperature sensor to your Raspberry Pi. Here’s a simple analogy to relate:

Think of the Raspberry Pi as a receptionist at a hotel. The DS18B20 sensor is a guest checking in to give updates about the weather. The receptionist (Raspberry Pi) has a specific channel (GPIO) to receive these updates, ensuring that the information goes to the right place (the dashboard).

Follow these steps to connect the DS18B20:

  • Wire it to your Pi as follows:
    • 3V3 (Red wire)
    • Ground (Black wire)
    • GPIO 4 (Yellow wire with a 4.7K pull-up resistor)
  • Edit boot/config.txt to include dtoverlay=w1-gpio and reboot.
  • Test the connection by checking /sys/bus/w1/devices.

Logging Outdoor and Nest Temperatures

Utilize weather APIs or the Nest API for logging external temperatures. Specific scripts are available for both, and instructions will be included in each respective script. These APIs will help you fetch and log temperature data seamlessly.

Viewing Temperature Data on Dashboard

Once the master Pi is set up, you can view the dashboard at the IP address:

http://[raspberry-pi-ip]:3000

Troubleshooting Tips

If you encounter issues, consider the following troubleshooting steps:

  • Ensure all Pis are powered and connected to the network.
  • Check that the correct IP addresses are entered in your configuration files.
  • Review the Ansible playbook errors for any missing roles or dependencies.
  • If cron jobs don’t seem to be working, confirm the postfix setup and remove /dev/null from cron entries.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

With your simple temperature monitoring application now set up, you can keep track of your home’s environment seamlessly. Enjoy experimenting with various features and refining the monitoring capabilities over time.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox