SmartGarden3 Test, Fix and Scan Programs

SmartGarden3 is a an easy to put together system for managing your garden inside and outside.   This posting talks about how you can do SmartGarden3 Test, Fix and Scanning.

What is  SmartGarden3?

The SmartGarden3  system (available here) allows you to build your own remote monitoring and management system for your indoor or outdoor garden.   Do you want to share your garden and the weather world wide?  You can learn the Raspberry Pi and how to connect to the real world through this easy to build no-soldering kit.   You can measure soil moisture and then use that as feedback to provide your plant or garden just the right about of water.

The Block Diagram of SmartGarden3 Hydroponics

SmartGarden3 comes in two flavors, the SmartGarden3 base unit and the SmartGarden3 Hydroponics unit.   Below is the block diagram for the SmartGarden3 Hydroponics kit.

SmartGarden3

 

Test, Fix and Calibration Programs for SmartGarden3

 

SwitchDoc Labs has written a series of Python3 programs to test and fix various problems that you might run into while using your unit and also to test the functions of SmartGarden3.  This article shows you how to:

  • Checking for Active SG3 Extenders
  • Fix Extenders after a Wireless Reboot (allocating different IP Numbers)
  • Test Your Bluetooth Moisture Sensor Devices
  • Seeing What is on your MQTT Channels being received and sent by your SmartGarden3 System
  • Test Entire SmartGarden3 System
  • Check Your Email Notification Setup
  • Testing Your Text Notifications
  • Testing Your Optional pH Sensor in SmartGarden3 Hydroponics
  • Testing TimeLapse and Picture Management
  • Calibrate your Hydroponics Water Level Sensor
  • Checking for Active SG3 Extenders

 

Fix Extenders after a Wireless Reboot (allocating different IP Numbers)

Some WiFi Access Points (Netgear Orbi is one example of these) will reallocate IP numbers after rebooting the router or a power failure.  This causes the Raspberry SmartGarden3 Extenders to loose communications.   If your router does this, research how to set static IPs for specific MAC addresses (your extenders and Raspberry Pi) for your WiFi access point.  Each WiFi access point brand is different, so this is beyond the scope of this article.

Most routers will not reassign IP addresses and will return the same IP address, but some will.    Running this program will scan your local network for Extenders and wire them back up to the Raspberry Pi. This will also correct the MQTT broker (on your Raspberry Pi) IP address if your Pi changes IP addresses.

If your SmartGarden3 is working correctly, you will see something like this:

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 scanAndFixExtenders.py
before running, stop SG3.py if it is running (hit return when ready)
SGS.JSON File exists
Wireless Device ID 149D Active
Wireless Device ID 1335 Active
All devices found
Scan and Fix Extenders Complete
Restart SG3.py
pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ 

To show you what will show up if there is a disconnect, we edited the SG3.JSON file to fake a change to IP numbers for the extender. This can easily take 15 minutes to run.

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 scanAndFixExtenders.py
before running, stop SG3.py if it is running (hit return when ready)
SGS.JSON File exists
Wireless Device ID 149D Not Active
Wireless Device ID 1335 Not Active
Missing Extenders.  Scan for Missing and Fix? (y or n)y
Scanning for missing extender.  This will take up to 10 minutes.
Your Computer IP Address is:192.168.1.17
Your Computer CIDR is: 192.168.1.0/24
Start Time = 2022-02-27 10:49:55.606891
checking IP: 192.168.1.0
checking IP: 192.168.1.1
checking IP: 192.168.1.2
checking IP: 192.168.1.3
checking IP: 192.168.1.4
checking IP: 192.168.1.5
checking IP: 192.168.1.6
checking IP: 192.168.1.7
checking IP: 192.168.1.8
checking IP: 192.168.1.9
checking IP: 192.168.1.10
checking IP: 192.168.1.11
checking IP: 192.168.1.12
checking IP: 192.168.1.13
checking IP: 192.168.1.14
checking IP: 192.168.1.15
checking IP: 192.168.1.16
checking IP: 192.168.1.17
checking IP: 192.168.1.18
checking IP: 192.168.1.19
checking IP: 192.168.1.20
checking IP: 192.168.1.21
checking IP: 192.168.1.22
checking IP: 192.168.1.23
checking IP: 192.168.1.24
checking IP: 192.168.1.25
checking IP: 192.168.1.26
checking IP: 192.168.1.27
checking IP: 192.168.1.28
checking IP: 192.168.1.29
checking IP: 192.168.1.30
checking IP: 192.168.1.31
checking IP: 192.168.1.32
checking IP: 192.168.1.33
checking IP: 192.168.1.34
SGS Wireless Extender Found.  ID= 149D
check for wirelsssJSON match - if so update IP
IP Number Fixed for Extender
checking IP: 192.168.1.35
checking IP: 192.168.1.36
SGS Wireless Extender Found.  ID= 1335
check for wirelsssJSON match - if so update IP
IP Number Fixed for Extender
checking IP: 192.168.1.37
checking IP: 192.168.1.38
checking IP: 192.168.1.39
checking IP: 192.168.1.40
.
.
. (more lines)
.
.
checking IP: 192.168.1.245
checking IP: 192.168.1.246
checking IP: 192.168.1.247
checking IP: 192.168.1.248
checking IP: 192.168.1.249
checking IP: 192.168.1.250
checking IP: 192.168.1.251
checking IP: 192.168.1.252
checking IP: 192.168.1.253
checking IP: 192.168.1.254
checking IP: 192.168.1.255
Finish Time = 2022-02-27 10:54:11.098953
Scan and Fix Extenders Complete
Restart SG3.py


Test Your Bluetooth Moisture Sensor Devices

This program will scan for any Bluetooth Moisture Sensors in the Area of the Raspberry Pi.

testBluetooth.py

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testBluetooth.py
Starting Bluetooth Reset
Starting Bluetooth Read
This is the raw data: C4:7C:8D:6C:9B:E7 Flower care

This is the raw data: C4:7C:8D:6D:E8:0B Flower care

This is the raw data: C4:7C:8D:6C:99:AB Flower care

This is the raw data: C4:7C:8D:6B:90:39 Flower care

This is the raw data: C4:7C:8D:6C:9B:E7 Flower care

This is the raw data: C4:7C:8D:6D:E8:0B Flower care

 

Seeing What is on your MQTT Channels being received and sent by your SmartGarden3 System

testMQTT.py

 

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testMQTT.py
log:  Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k60) client_id=b'SGS'
log:  Received CONNACK (0, 0)
Connected to broker
SGS.JSON File exists
subscribing to  SGS/149D
log:  Sending SUBSCRIBE (d0, m1) [(b'SGS/149D', 0)]
log:  Received SUBACK
subscribing to  SGS/149D/Valves
log:  Sending SUBSCRIBE (d0, m2) [(b'SGS/149D/Valves', 0)]
subscribing to  SGS/1335
log:  Sending SUBSCRIBE (d0, m3) [(b'SGS/1335', 0)]
subscribing to  SGS/1335/Valves
log:  Sending SUBSCRIBE (d0, m4) [(b'SGS/1335/Valves', 0)]
log:  Received SUBACK
log:  Received SUBACK
log:  Received SUBACK
log:  Sending PUBLISH (d0, q0, r0, m5), 'b'SGS/529D/Valves'', ... (113 bytes)
log:  Sending PUBLISH (d0, q0, r0, m6), 'b'SGS/529D/Valves'', ... (113 bytes)
log:  Sending PUBLISH (d0, q0, r0, m7), 'b'SGS/529D/Valves'', ... (113 bytes)
log:  Received PUBLISH (d0, q0, r0, m0), 'SGS/1335', ...  (247 bytes)
Message received:  b'{"id": "1335", "messagetype": "5", "timestamp": "2022-02-26 00:23:13", "macaddress": "C4:7C:8D:6B:90:39", "temperature": "212", "brightness": "389", "moisture": "73", "conductivity": "1123", "battery": "31", "readCount": "10", "sensorType": "BT1"}'

Test Entire SmartGarden3 System

This is the overall Test for the SmartGarden3 system usually used right after initial configuration as in the manual.

testSG3System.py

Using your favorite text editor, edit the testSG3System.py file and change the SG3EXT_IP variable to the IP address of your SG3 Wireless Extender that you copied down in the last section.  For example, our test SG3 WirelessExtender has an IP address of “192.168.1.70”.

So in our example, we changed the line:

SG3EXT_IP = “”

To:

SG3EXT_IP = “192.168.1.70”

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testSG3System.py
###########################
SmartGarden3 System Test
###########################
2022-02-27 09:23:08.146556

Wireless Extender Address =  192.168.1.34
###########################
Starting Wireless Extender Test
###########################
sending REST URL =  http://192.168.1.34/checkForID?params=192.168.1.17,1883
sending REST URL =  http://192.168.1.34/setSingleValve?params=admin,1,1,20
###########################
Turning On USB1 Valve for 10 seconds on Extender:  192.168.1.34
###########################
Wireless Extender:  192.168.1.34
Successfuly Responding
###########################
{'return_value': 0, 'id': '149D', 'name': 'Hydroponics', 'ipaddress': '192.168.1.34', 'hardware': 'esp32', 'hydroponicsmode': 'true', 'return_string': '', 'connected': True}
###########################
ADC Sensors:
sending REST URL =  http://192.168.1.34/testHydroponicsSensors?params=admin
{'return_value': 0, 'id': '149D', 'name': 'Hydroponics', 'ipaddress': '192.168.1.34', 'hardware': 'esp32', 'hydroponicsmode': 'true', 'return_string': '19.62,131,1312,436,473,', 'connected'

Check Your Email Notification Setup

testEmail.py

If you have configured Email Notifications in the SG3Configuration program, then you can test those settings here.    Below is an example of the a successful test (you should receive an email in about 5 minutes).

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testEmail.py
SGS.JSON File exists
config.mailUser yourgoogleaccount@gmail.com
config.notifyAddress= toemail@switchdoc.com
config.fromAddress= yourgoogleaddress@gmail.com
config.mailPassword= your google password
pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ 

And a bad test:

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testEmail.py
SGS.JSON File exists
config.mailUser yourgoogleaccount@gmail.com
config.notifyAddress= toemail@switchdoc.com
config.fromAddress= yourgoogleaddress@gmail.com
config.mailPassword= your google password
Traceback (most recent call last):
  File "/home/pi/SDL_Pi_SmartGarden3/sendemail.py", line 51, in sendEmail
    s.login(config.mailUser, config.mailPassword)
  File "/usr/lib/python3.7/smtplib.py", line 730, in login
    raise last_exception
  File "/usr/lib/python3.7/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.7/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials j22-20020a17090a7e9600b001bc67215a52sm8129053pjl.56 - gsmtp')


This usually happens if you have your username/password wrong is some fashion or you have a security setting wrong in your google account. Search the error on the Web.

Testing Your Text Notifications

testText.py

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testText.py
SGS.JSON File exists
config.mailUser yourgoogleaccount@gmail.com
config.textnotifyAddress= yourphonenumber@yourprovider
config.fromAddress= yourgoogleaddress@gmail.com
config.mailPassword= yourgooglepassword
pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ 


And a bad test:

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testText.py
SGS.JSON File exists
config.mailUser xohn.shovic@gmail.com
config.textnotifyAddress= 2086595772@mms.att.net
config.fromAddress= john.shovic@gmail.com
config.mailPassword= Irvine4914-01111
Traceback (most recent call last):
  File "/home/pi/SDL_Pi_SmartGarden3/sendemail.py", line 51, in sendEmail
    s.login(config.mailUser, config.mailPassword)
  File "/usr/lib/python3.7/smtplib.py", line 730, in login
    raise last_exception
  File "/usr/lib/python3.7/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.7/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials c9-20020a655a89000000b003747b9ed5a1sm8458426pgt.49 - gsmtp')

sendmail exception raised

This usually happens if you have your username/password wrong is some fashion or you have a security setting wrong in your google account. Search the error on the Web.

Testing Your Optional pH Sensor in SmartGarden3 Hydroponics

testpHSensor.py

You have to configure your hydroponics extender as shown in the manual before running this test using SG3Configure.py

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testpHSensor.py
SGS.JSON File exists
###########################
Get pH Level
###########################
Configured Offset =  4.7
###########################
Hydroponics Found id=149D ip=192.168.1.34
sending REST URL =  http://192.168.1.34/readHydroponicsSensors?password=admin
pHRaw= 436
pH Value=  7.16
sending REST URL =  http://192.168.1.34/readHydroponicsSensors?password=admin
pHRaw= 436
pH Value=  7.16
sending REST URL =  http://192.168.1.34/readHydroponicsSensors?password=admin
pHRaw= 436
pH Value=  7.16
sending REST URL =  http://192.168.1.34/readHydroponicsSensors?password=admin
pHRaw= 436
pH Value=  7.16
sending REST URL =  http://192.168.1.34/readHydroponicsSensors?password=admin
pHRaw= 436
pH Value=  7.16
####
Average Raw pH Value=  436.0
Average pH Value=  7.16
####
###########################

Testing TimeLapse and Picture Management

testPictureManagement.py

If you have a Pi Camera hooked up to your Raspberry Pi or have the optional IR sensor for your Hydroponics Unit, then you can run this program to verify you have everything working (especially ffmpeg which will not run on older Raspberry Pis such as the A+ and original Raspberry Pi Zero and Zero W).   You can edit this file to test various functions of the picture management system.  You need to run SmartGarden3 for a day before running these tests.

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testPictureManagement.py > tx
startime= 2022-02-26 05:00:00
endtime= 2022-02-27 05:00:00
devices= ['149D-IR', '1335-IR', 'GardenCamPi']
device= 149D-IR
config.= True
before query
query= SELECT timestamp, cameraID, picturename  FROM  SkyCamPictures WHERE cameraID = '149D-IR' AND timestamp >= '2022-02-26 05:00:00' AND timestamp < '2022-02-27 05:00:00' ORDER BY timestamp
cp static/SkyCam/149D-IR/2022-02-26/149D-IR_1_2022-02-26-05-09-44.jpg static/BuildTimeLapse/pic_0000.jpg
cp static/SkyCam/149D-IR/2022-02-26/149D-IR_1_2022-02-26-05-19-44.jpg static/BuildTimeLapse/pic_0001.jpg
cp static/SkyCam/149D-IR/2022-02-26/149D-IR_1_2022-02-26-05-29-44.jpg static/BuildTimeLapse/pic_0002.jpg
cp static/SkyCam/149D-IR/2022-02-26/149D-IR_1_2022-02-26-05-39-45.jpg static/BuildTimeLapse/pic_0003.jpg
.
.
.
(many lines)
.
.
.
cp static/SkyCam/GardenCamPi/2022-02-27/GardenCamPi_1_2022-02-27-04-56-22.jpg static/BuildTimeLapse/pic_1436.jpg
cp static/SkyCam/GardenCamPi/2022-02-27/GardenCamPi_1_2022-02-27-04-57-22.jpg static/BuildTimeLapse/pic_1437.jpg
cp static/SkyCam/GardenCamPi/2022-02-27/GardenCamPi_1_2022-02-27-04-58-22.jpg static/BuildTimeLapse/pic_1438.jpg
cp static/SkyCam/GardenCamPi/2022-02-27/GardenCamPi_1_2022-02-27-04-59-22.jpg static/BuildTimeLapse/pic_1439.jpg
/home/pi/SDL_Pi_SmartGarden3
/usr/bin/ffmpeg -r 20 -i /home/pi/SDL_Pi_SmartGarden3/static/BuildTimeLapse/pic_%04d.jpg -c:v libx264 /home/pi/SDL_Pi_SmartGarden3/static/TimeLapses/GardenCamPi/GardenCamPi_2022-02-27.mp4 
['/usr/bin/ffmpeg', '-r', '20', '-i', '/home/pi/SDL_Pi_SmartGarden3/static/BuildTimeLapse/pic_%04d.jpg', '-c:v', 'libx264', '/home/pi/SDL_Pi_SmartGarden3/static/TimeLapses/GardenCamPi/GardenCamPi_2022-02-27.mp4']

Calibrate your Hydroponics Water Level Sensor

testHydroponicsLevel.py

This program helps calibrate your moisture level sensor. Fill your Hydroponics unit with water (to the Max line). Then run the program:

sudo python3 testHydroponicsLevel.py

And follow the directions on the screen. Write down the “Empty Tank Value” and “Full Tank Value” (something like 865 and 520), go into SG3Configure and go into the Debug and Calibration Tab and enter these values into the fields. Then hit “Save and Reload SGS” which will restart your SmartGarden3 system with the new values. You will see something like this:

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testHydroponicsLevel.py
SGS.JSON File exists
###########################
Calibrate Hydroponics Level
###########################
Hydroponics Found id=149D ip=192.168.1.8

1) Remove Moisture Sensor from Hydroponics Tank and Dry
Hit Return to Continue


Now reading Hydroponics Level Sensor 5 times (may take 3 minutes )

sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
####
Empty Tank Value=  865.0
####
2) Fill Hydroponics Tank to Full
Hit Return to Continue

3) Insert Moisture Sensor into the Wiring Housing in Tank
Hit Return to Continue


Now reading Hydroponics Level Sensor 5 times (may take 3 minutes)

sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
sending REST URL =  http://192.168.1.8/readHydroponicsSensors?password=admin
####
Full Tank Value=  520.0
####

Run SG3Configure again and insert above values on 'Debug/Calibration' Tab
###########################
   Complete

Checking for Active SG3 Extenders

testSG3Extender.py

pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $ sudo python3 testSG3Extender.py
SGS.JSON File exists
Wireless Device ID 149D Active
Wireless Device ID 1335 Active
pi@SwitchDocLabs:~/SDL_Pi_SmartGarden3 $