|Product Performed to Expectations:||10|
|Specifications were sufficient to design with:||9|
|Demo Software was of good quality:||10|
|Product was easy to use:||10|
|Support materials were available:||9|
|The price to performance ratio was good:||10|
|TotalScore:||58 / 60|
Backup Sump Pump & Flood Alarm
My review comprise two parts: the first part is a brief evaluation of Raspberry Pi 4 as a potential replacement of low end desktop computer and the second part is the focus of my review - my backup sump pump project.
Here's a list of hardware pieces for my roadtest:
1. Raspberry Pi 4 Mode B (2GB)
2. Three heat sinks for CPU, DDR4 and USB chips
3. Quiet 5V fan (I almost cannot hear any noise from a couple of feet away)
4. 5V/3A AC/DC power supply with ON/OFF switch
5. microHDMI to HDMI adapter
6. SanDisk Ultra 16GB microSD & card reader
7. CyberPower UPS CP1500PFCLCD
8. Water level sensor
9. Liquid overflow floor sensor
10. Wireless keyboard & mouse (not shown below)
Raspberry Pi 4, heat sinks, 5V fan, card reader & 5V/3A power supply
microHDMI to HDMI adapter
Water level sensor
Liquid overflow floor sensor
CyberPower UPS CP1500PFCLCD
Like many Pi hobbyists, I always ask myself when Pi can really become a practical replacement for a low end Linux laptop. After playing with the Raspberry Pi 4 Mode B (2GB) for a few days, I would say it has comparable capability to a low end desktop computer for a basic laptop user. Below is quick performance evaluation of a few common laptop activities:
|Activity||Startup Time (seconds)||Comments|
|Board Boot up||23.1||temperature ~35C, CPU usage very light|
|Start Internet Browser||7.9||Feel as smooth as browsing on my Dell laptop after startup|
|Start LiberOffice Suite||4.5 ~ 9||No noticeable delay after startup|
|Switch Youtube Video to Full Screen (1080p)||3.8||temperature ~49C, CPU usage ~85%|
|Browse Google Map (Street View)||-||Feel as smooth as browsing on my Dell laptop after startup|
|Start Thonny Python IDE||3.5||No noticeable delay after startup|
Not bad at all. I think it can definitely be kid's first computer. It can also be a very portable supplemental Linux computer for Windows PC users who occasionally need Linux environment.
One quick note: I used Raspbian as the OS for my roadtest. Here's the version I am using:
I'm using Raspberry Pi to design a smart backup sump pump and flood alert system. We had quite lot of thunder storms recently. While I was on vacation, I had to ask my neighbor to check out my sump pump to make sure no flooding in my basement. To create peace of mind for my wife, I'd like to use a Raspberry Pi to control an uninterrupted power supply (UPS) to power the sump pump when there's a power outage. The water level sensors will detect the dangerous water level so the alarm system can be triggered and send text message to my wife and myself. In the worst case, if any flooding occurs on the floor, the alarm system will send text message. Here's the system diagram.
For my project, there is no need of a display. Instead, I enabled SSH so I can remotely access Pi through command line. If you need help to set up SSH on Pi, please refer to this link. To make the project a little bit more secure, I disabled the default pi user and created a new username pi4home. It belongs to the following user groups:
User group sudo is required for installing software, nut group for UPS access and gpio group for Pi's I/O access. To add pi4home user to those groups, simply type the following command:
sudo usermod -a -G sudo,nut,gpio pi4home
The CyberPower UPS CP1500PFCLCD can be monitored and controlled by either CyberPower PowerPanel software or open source software Network UPS Tools. However, CyberPower PowerPanel software doesn't have an ARM version so I have to use Network UPS Tools. You can find tons of information about the Network UPS Tools from here. If you just want to quickly set up your UPS to work with Pi, here's the best article I found (thanks to Logan Marchione for the great job). The following is a step-by-step process I have used to setup my UPS access.
The CyberPower UPS CP1500PFCLCD has two potential interfaces to Pi: RS-232 and USB. In order to use RS-232 on Pi, a USB/RS-232 adapter is required. Obviously, directly using USB is preferred.
First of all, connect a USB type A to type B cable between the Pi and the UPS. Then type lsusb command to see verify the highlighted line shows up.
Next, I installed the NUT software tools using the following command:
sudo apt-get update && sudo apt-get install nut nut-client nut-server
Create the file /etc/nut/ups.conf if it doesn't exist using the following command
then add the following lines
cyberpower1500w is the name I gave to my UPS. usbhid-ups is the USB driver option I mentioned before. auto is the default port number 3493.
Create the file /etc/nut/upsd.conf if it doesn't exist using the following command then add a LISTEN line as shown in the following screenshot.
Create the file /etc/nut/upsd.users if it doesn't exist using the following command
then add my pi4home user as shown in the screenshot.
Create the file /etc/nut/nut.conf if it doesn't exist using the following command
then add MODE=standalone line as shown in the screenshot.
Once the above configuration is done, reboot the Pi and the UPS driver and the server will automatically start up.
To verify the driver and the server, type upsc cyberpower1500w@localhost command
You can see the input voltage is 121.0V and the UPS status is online (OL). If you unplug the UPS power cord and type the same command again,
You can see the input voltage becomes 0.0V and the UPS status becomes offline (OB DISCHRG).
According to the above UPS status messages, I wrote a Python function to detect if the power is out or not. When function is_power_out() returns True, it means we have a power outage.
import os def is_power_out(): read_ups_cmd = 'upsc cyberpower1500w@localhost' ups_output = os.popen(read_ups_cmd).read() ups_properties = dict(item.split(":") for item in ups_output.split("\n") if item) if ups_properties["ups.status"].strip() == 'OL': return False else: return True
When power is out, I'd like to receive a text message and/or an email to alert me. I am using Verizon cell phone network. If an email sends to email@example.com, I will receive a text message on my cell phone.
To have the Pi sending emails, I created a new Gmail account for my Pi - pi4home2019. By default, Gmail doesn't allow unknown apps and devices to access the account. I have to turn on "Less secure app access" security setting. You can refer the following screenshot to enable this feature.
Then write a Python function to send text message
import smtplib def send_text_msg(msg): gmail_user = 'firstname.lastname@example.org' gmail_password = 'your_gmail_password' recipient = ['email@example.com', 'firstname.lastname@example.org'] try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(gmail_user, gmail_password) server.sendmail(gmail_user, recipient, msg) server.close() return True except: return False
The water level sensor is a simple ON/OFF switch (NC switch in my application). When water level is high enough which make the float move upwards, the switch then becomes open. We can use Pi's Python gpiozero library to create an input I/O, but the library has a Button class which is more convenient to use. Here's the code to detect if the water level is too high.
from gpiozero import Button water_level_alarm = Button('BOARD37') def is_water_level_too_high(): if water_level_alarm.is_pressed: return False else: return True
The floor water sensor can be used as a simple ON/OFF switch (NO switch in my application) using the same Python Button class. When the floor is flooding, water make the sensor start conducting and the Button will detect in pressed state. Here's the code.
from gpiozero import Button flood_alarm = Button('BOARD11') def is_flooding(): if flood_alarm.is_pressed: return True else: return False
Combine the above code snippets and create a main() function to put them together. Here's the code:
import os import time import smtplib from gpiozero import Button flood_alarm = Button('BOARD11') water_level_alarm = Button('BOARD37') def is_flooding(): if flood_alarm.is_pressed: return True else: return False def is_water_level_too_high(): if water_level_alarm.is_pressed: return False else: return True def is_power_out(): read_ups_cmd = 'upsc cyberpower1500w@localhost' ups_output = os.popen(read_ups_cmd).read() ups_properties = dict(item.split(":") for item in ups_output.split("\n") if item) if ups_properties["ups.status"].strip() == 'OL': return False else: return True def send_text_msg(msg): gmail_user = 'email@example.com' gmail_password = 'your_gmail_password' recipient = ['firstname.lastname@example.org', 'email@example.com'] try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(gmail_user, gmail_password) server.sendmail(gmail_user, recipient, msg) server.close() return True except: return False def main(): prev_power_out_status = False prev_water_too_high = False prev_flood_status = False while True: time.sleep(15) if is_power_out(): if not prev_power_out_status: prev_power_out_status = True send_text_msg("Power is out!") else: if prev_power_out_status: prev_power_out_status = False send_text_msg("Power is back!") if is_water_level_too_high(): if not prev_water_too_high: prev_water_too_high = True send_text_msg("Sump pump water level too high!") else: if prev_water_too_high: prev_water_too_high = False send_text_msg("Sump pump water level normal!") if is_flooding(): if not prev_flood_status: prev_flood_status = True send_text_msg("Basement is flooding!") else: if prev_flood_status: prev_flood_status = False send_text_msg("Basement not flood!") if __name__ == "__main__": main()
If the above code is stored on your PC, you can use the following command to copy it to the Pi.
scp your_code.py pi_username@pi_ip_address:/remote/directory/
Then you can modify rc.local file using the following command
sudo vi /etc/rc.local
And add the highlighted line as shown in the following screenshot.
I created a few events and successfully received all text messages and emails. Here's my text message screenshot.
Comparing to previous generations of Raspberry Pis, I think Pi 4 is a big step up in power. In my opinion, it has the similar power to a low end Linux laptop and can be used for kid's computer or as a supplemental Linux box for Windows users. For makers, it's a very powerful, cost effective and low power consumption platform for many hobby projects. It may also be used for low volume consumer and/or commercial equipment.