Documentation for Urban Gardening
This project provides an infrastructure to implement a self sustaining smart garden. It uses state-of-the-art technologies to implement a variety of useful tools to monitor, alert and explore on the basis of the data. The core of our work is the implementation of a greenhouse which provides sensors and actuators controlled via cloud systems to provide an optimal environment for plants.
In figure 1 we can see in the general overview the idea to connect multiple greenhouses via a wifi network mesh to a Cloud service. Whereby particular greenhouses can serves as a gateway and are directly connected to the cloud.
The greenhouses themselves contain a variety of sensors and actuators, as shown in figure 2. These sensors and actuators are connected via the GPIO connectors to an Raspberry pi. The Raspberry pi gathers the sensor data and distributes this data via the above mentioned mesh network. The Pi also receives instructions for the connected actuators and executes them.
Figure 3 gives an overview about the Software implementation. In the lower part we see Multiple Pi's which implement the mesh network via B.A.T.M.A.N (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The sensor & actuator logic is implemented via Python and containerized in Docker. Each Raspberry is a Worker Node in a K3s cluster. K3s is a lightweight Kubernetes built for IoT & Edge computing. It perfect to for running on something as small as a Raspberry Pi.
The sensor communication is realized via MQTT. In particular we use Paho mqtt for pyhton on the Pi side and a Mosquitto MQTT Broker on the cloud side.
The cloud environment consists of four services. A Mosquitto MQTT broker for the communication with the greenhouse instances. Telegraf which subscribes to the published topics by the greenhouse sensors and saves the data in an influxdb database. And lastly Grafana which is used for data visualization and alerting.
For the creation of the project we used a desktop computer as cloud environment(Master node) and raspberry pi's as worker nodes
Component | Description |
---|---|
Raspberry Pi 3B / 4 | - |
MicroSD Card 32GB | - |
DHT22 Sensor | Temperature & Humidity Sensor |
Water Level Sensor | Analog Water Level Sensor |
Soil Moisture Sensor | Analog Soil Moisture Sensor |
LDR | Light Dependent Resistor |
MCP3008 | 8 Channel 10-bit ADC |
Breadboard | 1 Piece |
Male to Male Connectors | 100 Pieces |
Male to Female Connectors | 100 Pieces |
5v Power Supply | Power supply for Raspberry Pi. 2.5A Power Supply recommended |
5v Waterpump | Water pump (Not implemented) |
RGB LED | NeoPixel Ring - 12 x RGB LED |
Jumper-Cabel | 5v power supply for LED |
Custom raspbian OS creation is part of this repository which installs necessary packages and configurations for setting up gateway
and node
Pis respectively. The configuration files are listed under the folder batman
. These files could further be modified according to the needs of the project. Also the image creation, requires Ubuntu/Debian OS.
To create an image:
Clone this git repository
Run the script build-batman-node.sh in the folder garden-adventure
./build-batman-node.sh -t [gateway|node] -n [hostname] -u [k3s_url] -k [k3s_token] -d [dns_ip]
Specify the required options for the above command(type, hostname, k3s url, k3s token). Mention your dns_ip when creating an image for node
(eg: 8.8.8.8).
build-raspbian
.raspberry
. This can also be modified in the file build-batman-node.sh
brcm
for wlan interface). Other firmwares could be installed from here. They should be copied at the time of image creation. Refer the script build-batman-node.sh
.Using Raspberry Pi Imager, burn the created image onto a SD card. The created image could be found under the folder images
after running above script.
First setup the gateway Pi by connecting it to ethernet and inserting the SD card that contains the raspbian OS for gateway and powering it on. The first boot steps will be performed and you can login with the details provided above. Under the root user following scripts can be found:
smart-garden-mesh.sh
k3s_installation.sh
Running the first script, brings up the B.A.T.M.A.N inteface for mesh network along with the Pi configured as a gateway. It starts a dhcp server for the inteface bat0
and enables a custom service called port-forwarding.service
that forwards packets across batman and ethernet interface.
Running the second script, installs K3s and adds the Pi as a worker to a K3s cluster. If the k3s master is not part of the same network as gateway and belongs to the public network, then k3s installation should be done via VPN. This is currently out of the scope of this repository. Refer OpenVPN or Wiregaurd for more information about setting up VPN.
Setup the node by inserting the SD card that contains the raspbian OS for the node. The ethernet connection is not needed for the node setup. Also under the root user, the above mentioned scripts could be found.
First run smart-garden-mesh.sh to setup the B.A.T.M.A.N
Wait until the interface bat0
gets an ip address from DHCP server within the range 172.27.0.100 - 172.27.0.200
. This may take a time of 20-30s.
Before running the K3s installation script, make sure the k3s master can direct packets to the node using ping
command. If the packet loss is 100%, then you need to add necessary route in the k3s master using the command ip
.
Eg: ip route add 172.27.0.0/24 via 192.168.10.74 dev eth0
This chapter describes the implementation of the Cloud services. In detail the installation of Grafana, Influxdb, Mosquitto MQTT Broker and Telegraf.
We use for all the cloud service installations Helm scripts. For the installation of Helm, please refer to the documentation.
Notice: We used for all services the standard username: "admin" and password: "dspj2020"
First add the Mosquitto Broker helom chart via: helm repo add smizy https://smizy.github.io/charts
To start the services you can run the script in gardening-adventure/cloud_garden/deployment/cloud_deployment.sh
This will start Grafana, Influxdb, Mosquitto MQTT Broker and Telegraf via helm.
Notice: This will start the services without any node selection. For that edit the corresponding settings in the yaml files. For adding a label to a node use the following command : kubectl label nodes <nodename> <key>=<value> --overwrite
The Section gives examples for possible post deployment application of the services. This includes Database connections, charts and alerts.
Login to the grafana UI. Use kubectl get svc
to get the IP's and ports of all services.
hhtp://<Influxdb IP>:8086
garden
as databaseadmin
and password is dspj2020
Save and Test
After the datasource has been added the next step is to add the dashboard which displays the data from the datasource.
New dashboard
(Create -> New Dashboard -> Graph).FROM
line, select the sensor name in the second dropdown. This will be the sensor that the graph will depict values from. In the SELECT
line, pick the appropriate field, for example temperature
. Pick the desired grouping time interval on line 3 and save the graph by clicking the save icon on the top right hand side.We used Grafana's Alerts to receive notifications when, for example, humidity drops below a certain level. As an example we show here to configure an alert sent to telegram. For more options please have a look at the Grafana's alert documentation.
https://api.telegram.org/bot<TOKEN>/getUpdates
This should return an JSON object, you need to find key “chat” like this one:"chat":{"id":-456343576,"title":"Super Dooper Alert Group","type":"group","all_members_are_administrators":true}
This chapter describes the installation of a new smart greenhouse. The installation includes the hardware and the software configuration of the sensors/actuators and the Pi.
Figure 4 shows the wiring of the sensors with the Raspberry Pi. Please note that an external 5V power supply is required when using several sensors and actuators. This is especially true if you use an LED light or a water pump.
Each sensor has its own docker image. We use Balenalib Raspbian images which is optimized for the use in IoT devices. Use the -f option in the scripts directory to make sure Docker finds all the files it needs. Example to build the dht sensor:
.../gardening-adventure/scripts$ docker build -f dht_sensor/Dockerfile -t dht .
The Raspberry Pi Camera module supports a variety of resolutions, ISO settings, Interval between Capture of Photos. All of these parameters are configurable. The camera_module.yml file takes all these parameters and deploys the camera module with the parameters requested. In the spec
section, under container
section, the options for the camera can be set under arguments
section.
If no options under this section is set in the camera_module.yml file, the camera module is deployed with the default values. The default values and the supported values are described in the table below.
Argument | Description | Supported Values | Default Value |
---|---|---|---|
resolution | Image resolution | 1920-1080, 3280-2464, 1640-1232, 1640-922, 1280-720, 640-480 | 1920-1080 |
output | Location to store output. | Any valid *nix path | /camera_output/continuous_captures/ |
interval | Number of seconds between captures. | Must be an Integer. | 10 |
iso | ISO Sensitivity Settings | 100 - 800 | 100 |
If all required sensors are wired you can continue with the software installation. The installation of the desired devices is happening via a shell script. For that it is required that K3s is running on the Pi controlling the sensors and the IP address for the MQTT Broker is known.
To start the Sensors run the gardening-adventure/scripts/sensor_deployment.sh
script in an environment with kubectl configured. After the deployment the sensors immediately start sending data to the MQTT Broker
Note: if you use your own Docker image reposetory please change this in the yml files.