All the code that runs on our water monitoring devices.
Our monitoring devices are the basis of our operation. They generate all the data that we use to find actionable insights. As such, it's extremely immportant that the data they create is consistent and the photo's of water are captured with specific hardware and configuration settings.
The big idea behind our system is to find patterns in lots of data. Taking a photo of water is relatively inexpensive. By taking the photo underwater, in a light-contained enclosure, we're removing all light as a variable in our data. Because the only light all our devices will use is the same, we can take photos regardless of external conditions (like time of day, weather, shade, etc) and ensure our data is consistent. For this reason, we also insist all our devices use the same camera. Different camera manufacteurers will have small differences in the image and light quality that can impact our data.
These devices will be bought and maintained by field volunteers. People who might have zero technical know-how. As such, ensure that any work you do is done in the spirit of making their lives and volunteer duties as easy as possible.
There are plenty of issues that are open that represent work that needs to be done. You can choose something there to get started or create your own issues. There is nothing too small. If you see any spelling or grammar errors, or no documentation at all, please feel free to create an issues and submit a pull request. All contributions / pull requests will need to be approved by Digital Waters engineering.
Also, feel free to introduce yourself in a comment or in our repo Discussions board! We'd love to connect and collaborate with like-minded people. Don't be a stranger :D
Before uploading the cam_code make sure the pi is tested for the camera module and working
We use SSH to connect to our RPi. On Windows: WinSCP, Putty. Visual Studio also has plugins that enable this.
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
Interfacing Options
> Camera
and select Enable
.sudo reboot
libcamera
utilities which include libcamera-hello
.
sudo apt-get install libcamera-apps
Check Camera Connection: After rebooting, verify that the camera module is detected by running:
vcgencmd get_camera
The output should be:
supported=1 detected=1
This indicates that the camera module is supported and detected.
Run libcamera-hello
Command: Use the libcamera-hello
command to test the camera module.
libcamera-hello
This command opens a preview window and displays the live camera feed. This is a good test to ensure that the camera module is working correctly.
Capture an Image: Use the libcamera-still
command to capture an image.
libcamera-still -o test_image.jpg
This command captures an image and saves it as test_image.jpg
in the current directory.
Record a Video: Use the libcamera-vid
command to record a video.
libcamera-vid -o test_video.h264 -t 10000
This command records a 10-second video and saves it as test_video.h264
in the current directory.
View the Captured Image and Video: Use an image viewer or media player to view the captured image and video to ensure the camera module is working correctly.
vcgencmd get_camera
returns detected=0
), check the ribbon cable connection and ensure it is properly seated in the CSI port.To run the sense_Temp1.py code on a Raspberry Pi Zero 2 W, which is designed to read temperature data from a DS18B20 sensor, you need to follow pre-requisite steps for both hardware and software setup:
Enable 1-Wire Interface:
sudo raspi-config
Interfacing Options
> 1-Wire
and select Enable
.sudo reboot
Install Required Packages:
sudo apt-get update
sudo apt-get install python3 python3-pip
Load 1-Wire Kernel Modules:
/boot/config.txt
:
dtoverlay=w1-gpio
sudo modprobe w1-gpio
sudo modprobe w1-therm
Check for the Sensor:
/sys/bus/w1/devices/
that contains directories with names starting with 28-
(the DS18B20 sensor's family code). You can check it by:
ls /sys/bus/w1/devices/
Create the Script File:
sense_Temp1.py'
).Run the Script:
Run the code in an IDE such as Thonny, Geany, etc.
OR
Make the script executable:
chmod +x sense_Temp1.py
Run the script using Python 3:
./sense_Temp1.py
To run the gpsSensor.py code on a Raspberry Pi Zero 2 W, which is designed to read GPS location and time data from a GT-U7 GPS module, you need to follow pre-requisite steps for both hardware and software setup:
Edit config.txt file:
sudo nano /boot/config.txt
insert the following lines at the bottom of the file:
droverlay=w1-gpio
dtoverlay=w1-gpio
core_freq=250
enable_uart=1
force_turbo=1
Edit raspberryPI config settings:
sudo raspi-config
Interfacing Options
> Serial
, disable serial login Shell and enable serial interface.Install Required Packages:
sudo apt-get update
pip install pynmea2
pip install pytz
Test Sensor:
sudo apt install minicom
sudo minicom -b 9600 -o -D /dev/serial0
Create the Script File:
gpsSensor.py'
).Run the Script:
Run the code in an IDE such as Thonny, Geany, etc.
OR
Make the script executable:
chmod +x gpsSensor.py
Run the script using Python 3:
./gpsSensor.py
This script (Payload.py
) is designed to upload photos taken by water monitoring devices to a specified server. The script ensures the data consistency required for analysis by uploading photos with specific hardware and configuration settings.
requests
, requests-toolbelt
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3 python3-pip
pip3 install requests requests-toolbelt
python3 -m venv myenv
source myenv/bin/activate
python3 Payload.py
heroku logs --tail --app your-heroku-app-name
The following instructions allow the mainloop to start at the start-up of the raspberryPI.
sudo nano /etc/systemd/system/myscript.service
readlink -f mainloop.py
in the working directory: [Unit]
Description=My Python Script
After=network.target
[Service]
ExecStart=/usr/bin/python3 [path to mainloop.py]
WorkingDirectory=[path to the directory that main.py is in]
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
next ctrl-s
to save and ctrl-x
to exit
sudo systemctl daemon-reload
sudo systemctl enable myscript.service
sudo systemctl start myscript.service
sudo systemctl status myscript.service
sudo systemctl stop myscript.service
sudo systemctl restart myscript.service
sudo systemctl disable myscript.service