This guide provides step-by-step instructions to set up the Smart Guardian system, which involves capturing images using a Raspberry Pi, reading sensor data using an Arduino, and logging the data to an InfluxDB database.
- Raspberry Pi Setup
- InfluxDB Configuration
- Building and Running the Docker Container
- Arduino Setup
- Hardware Setup
- Setting a Fixed IP Address for Raspberry Pi
-
Create a directory for InfluxDB data:
mkdir -p /home/pi/influxdb/data
-
Generate the InfluxDB configuration file:
docker run --rm influxdb:2.0 influxd print-config > /home/pi/influxdb/config.yml
-
Create a
docker-compose.yml
file:version: '3.1' services: influxdb: image: influxdb:2.0 container_name: influxdb ports: - "8086:8086" volumes: - /home/pi/influxdb/data:/var/lib/influxdb2 - /home/pi/influxdb/config.yml:/etc/influxdb2/influxdb2.conf
-
Start the InfluxDB container:
docker compose up -d influxdb
-
Access the InfluxDB web interface:
- Open a browser and navigate to:
http://<rpi-url>:8086
- Open a browser and navigate to:
-
Set up InfluxDB:
- Follow the on-screen instructions to set up the InfluxDB instance, create an initial user, and set up the database.
-
Create a
requirements.txt
file:picamera2 influxdb requests openai langchain
-
Create a Dockerfile:
# Use the balenalib base image for Raspberry Pi 4 (ARM architecture) FROM balenalib/raspberrypi4-64-python:latest # Install system dependencies RUN apt-get update && apt-get install -y \ libjpeg-dev \ zlib1g-dev \ libopenjp2-7 \ libtiff5 \ libatlas-base-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Set the working directory WORKDIR /app # Copy the requirements file COPY requirements.txt . # Install Python dependencies RUN pip install --upgrade pip RUN pip install -r requirements.txt # Copy the rest of the application code COPY . . # Set environment variables for InfluxDB ENV INFLUXDB_HOST=localhost ENV INFLUXDB_PORT=8086 ENV INFLUXDB_USER=user ENV INFLUXDB_PASSWORD=password ENV INFLUXDB_DATABASE=sensors ENV INFLUXDB_MEASUREMENT=environment # Run the script CMD ["python", "your_script.py"]
-
Build and run the Docker container:
docker build -t smart_guardian . docker run --privileged -e INFLUXDB_HOST=<your_host> -e INFLUXDB_PORT=<your_port> -e INFLUXDB_USER=<your_user> -e INFLUXDB_PASSWORD=<your_password> -e INFLUXDB_DATABASE=<your_database> -e INFLUXDB_MEASUREMENT=<your_measurement> smart_guardian
-
Install required libraries:
- DHT sensor library: DHT library
- Ethernet library (included with the Arduino IDE)
- HTTP client library: ArduinoHttpClient
-
Upload the Arduino script
-
Connect the sensors to the Arduino:
- DHT11 Sensor:
- VCC to 5V
- GND to GND
- Data pin to digital pin 2
- Moisture Sensor:
- VCC to 5V
- GND to GND
- Analog output to analog pin A0
- DHT11 Sensor:
-
Connect the Arduino to the Ethernet shield/module.
-
Ensure the Raspberry Pi and Arduino are on the same network.
-
Edit the
dhcpcd.conf
file:sudo nano /etc/dhcpcd.conf
-
Add the following lines at the end of the file:
interface eth0 static ip_address=192.168.1.100/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
Replace
192.168.1.100
with the desired IP address for your Raspberry Pi and192.168.1.1
with your router’s IP address. -
Restart the DHCP service:
sudo systemctl restart dhcpcd
-
Reboot the Raspberry Pi:
sudo reboot
After following these steps, your Smart Guardian system should be set up and running, with sensor data being captured and stored in InfluxDB, ready for further analysis or monitoring.