This is only a preview of the August 2023 issue of Silicon Chip. You can view 39 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "The WebMite":
Items relevant to "Watering System Controller":
Items relevant to "Arduino-based LC & ESR Meter":
Items relevant to "Calibrated Measurement Mic":
Articles in this series:
Purchase a printed copy of this issue for $11.50. |
WebMite-based
Watering System
Controller
By Geoff Graham
This advanced Watering System Controller does it all. It can change the
watering schedule depending on the seasons, check the weather forecast
before watering and even alert you to a burst pipe or blocked sprinkler.
Best of all, it is very easy to set up and use.
Image: www.pexels.com/photo/sprinkler-on-a-grassy-field-3351909/
W
atering system controllers, often
known as reticulation or irrigation controllers, are notoriously difficult to program. They generally have a
small LCD screen and an array of tiny
buttons or switches to configure the
watering schedule.
Our Watering System Controller has
no LCD or buttons; it is entirely set up
and controlled via a web browser on
your smartphone, tablet or computer.
The web pages are easy to understand
and provide everything you need to
set it up.
The key component is the WebMite,
a Raspberry Pi Pico W microcontroller
running the MMBasic programming
language, starting on page 30 in this
issue. Here it delivers the web pages,
gets the time, date and weather from
the internet and follows the watering
schedule you have configured.
The only other significant components in this design are a small power
supply and the solid-state relays
(SSRs) that drive the solenoid watering valves.
The program running on the WebMite is written in BASIC, so you can
read it and edit it if you have special
requirements.
This project was partly developed
to demonstrate what you can do with
the WebMite. Even if you do not want
to build a Watering System Controller,
this project can be helpful by providing the code and techniques you can
use in other projects.
The program will even run on a bare
Raspberry Pi Pico W. That means you
can explore the program and try it
yourself without building anything;
you just need the Pico W module.
Watering system layout
Fig.1 shows a typical reticulation
layout. The water supply is connected
via a master valve to a series of valves
that control individual sprinklers (or
sets of sprinklers). The Controller
The finished controller
in a weatherproof
enclosure mounted
on an exterior wall.
We decided to mount
the status LED on
the lid along with a
waterproof power
switch.
36
Silicon Chip
Australia's electronics magazine
opens the master valve, then steps
through each sprinkler valve in turn,
opening them for the specified time.
The master valve is important as it
provides a backup if one of the sprinkler valves is stuck open (it happens).
The master valve will still cut off
the water supply, limiting the damage caused by the permanently-open
valve.
Some systems have a pump as the
water supply; in that case, the Watering System Controller would switch
that on and off instead of a master
valve.
Either way, the Controller will
switch it on half a second before the
first sprinkler valve is opened and
switch it off half a second after the last
has been closed. That is to ensure that
the water pipes leading to the sprinkler
valves are kept full of water, avoiding
the situation where a sprinkler valve
closes after the master valve, letting
water out of the pipes.
Otherwise, when the master valve
next opens, the water rushing through
the empty pipes could act as a hammer and damage the joints in the pipe
and the valve.
The flow sensor is an optional but
worthwhile addition. It is usually fitted at the outlet of the pump or master valve and tells the Controller the
amount of water flowing through the
system. The Controller records this
and, over time, builds up an average
flow rate for each valve.
The Controller can then easily detect
an abnormal flow rate when it opens
a valve, either over or under the average. This is invaluable as an excessive
siliconchip.com.au
Fig.1: a typical watering system
layout. The water supply is
connected via a master valve (or
pump if using rain water) to a series
of valves that control the sprinklers.
The optional flow sensor allows
the Controller to detect a burst pipe
(above-average flow) or blocked
valve (below-average flow).
flow indicates that a pipe has burst
and it might be digging a hole in your
garden. A lower-than-normal flow rate
means a sprinkler or valve is blocked;
if left unfixed, that could cause your
plants to die.
When an excessively high flow is
found, the Controller immediately
shuts off that valve to stop any damage. In the case of underflow, it will
continue with the watering time in
the hope that some water is getting
through, but it will also inform you
of the problem.
The rain sensor is also optional.
The Watering System Controller can
check the weather forecast for you and
skip watering if rain is predicted, but
connecting a rain sensor provides a
backup specific to your garden. The
Controller will check the sensor before
it starts a watering run, and if it indicates that it is currently raining, the
schedule will be skipped for that day.
Controller capabilities
To set up the Controller, you use a
web browser to access its web page,
siliconchip.com.au
shown in Screen 1. It lists all the possible watering schedules, with a button to configure each. It also has a RUN
NOW button that can be used to start
the watering schedule at any time.
These schedules are set to start at a
certain date in the year and terminate
at another. For example, you can set
up a schedule for the summer months
tailored to the demands of hot weather,
another for autumn when less watering is required, another for winter and
so on. You can set up the watering
requirements for the whole year and,
Features & Specifications
»
»
»
»
»
»
»
»
»
»
»
»
»
»
»
Configured using a web interface from a smartphone, tablet or computer
Controls a master valve plus up to eight sprinkler valves
Up to eight independent watering schedules
Schedules can be customised for different requirements during summer etc
The active schedule can be skipped if rain is forecast or detected
Sprinkler times can be increased on hot days
Flow sensor support for detecting burst pipes, blocked valves or sprinklers
A rain sensor can be connected to avoid watering during rain
Schedules can run on certain days of the week or at intervals in days
Schedules can start at a fixed time or a period before/after sunrise/sunset
Time and date are set from the internet with automatic daylight saving
compensation
No battery-backed clock is required
Schedules continue if the WiFi or internet is down
Schedules automatically restart after a power failure
Powered by 24V AC at 1A
Australia's electronics magazine
August 2023 37
unless you change your mind, it will
be repeated year after year.
Typical Watering System Controllers require you to change the watering characteristics at the start of each
season, and that can quickly become
tedious, something that our design
eliminates.
That page includes buttons to configure each schedule. After clicking
one, you will be presented with a web
page similar to that shown in Screen
2, which provides all the schedule
details.
The first field on the configuration
page allows you to enter a meaningful
title to be displayed on the main page.
You can also enable or disable the
schedule with a checkbox. The next
four fields let you set the start and
stop dates in the year for the schedule. Schedules can overlap and, if you
want the same watering scheme for the
whole year, you can set the start to 1/1
and the end to 31/12.
The following section allows you to
set the days of the week for watering
or specify a watering interval in days.
This is a case of one or the other but
not both.
Following this, you set the time for
the watering to start. Screen 2 shows
Screen 1: the
main web page
you see when you
connect to the
Controller. It lists
all the watering
schedules and
their start and
stop dates. The
CONFIGURE
button lets
you change
the associated
schedule,
while the RUN
NOW button
immediately
starts that
program.
Screen 2: this
allows you
to modify
a schedule,
including the
start and stop
dates, the time
to start watering,
the watering time
for each valve
and the actions to
take based on the
weather forecast.
38
Silicon Chip
Australia's electronics magazine
this set to 6 hours 0 minutes after midnight (ie, 6am). However, using the
dropdown list, you can also specify a
number of hours and minutes before
sunrise, after sunrise, before sunset
or after sunset. That gives you a lot
of flexibility in setting the start time.
In the next section, you can configure each solenoid valve’s watering time in minutes. The Controller
will step through each valve in the
sequence, opening it for the specified
time. It can drive up to eight valves
(plus the master valve), but you do
not need to install that many if you
need fewer. The program will skip
any valves with a zero or blank watering time.
If you have entered some watering
times in these fields, the RUN NOW
button will appear on the main page,
even if the schedule is disabled and
the other fields have not been filled in.
That means you can create a watering
sequence that can only be started on
demand from the web page.
The final section allows you to
change the watering schedule for that
day depending on the weather forecast. You can skip watering entirely if
rain is forecast, and you can increase
the watering times if the forecast for
the next 24 hours predicts a maximum
temperature over a certain threshold.
The former can avoid wasting water,
while the latter can prevent plant
death on unusually hot days.
At the bottom of the page is a button to save the changes that you have
made. The BASIC program saves the
configuration and settings to a file
called “settings.dat” in the internal file
system of the WebMite. On power-up
or a reboot, the program reads that file
so that all the details are in memory.
General settings
The GENERAL SETTINGS button at
the bottom of the main page (in Screen
1) takes you to the web page shown in
Screen 3. On this page, you can tell
the program your location, connected
sensors and details for sending emails.
The location data is used for many
features of the Controller, including its
time zone, daylight saving compensation, the times for sunrise and sunset
and the weather forecast. You need
to enter the name of your city and the
country code, which is AU for Australia and NZ for New Zealand (a full
list of the Alpha-2 codes can be found
at https://w.wiki/Gb$). After that, you
siliconchip.com.au
Screen 3: this
screen lets
you change
the settings for
the Controller
as a whole.
You can tell it
your location,
the connected
sensors and how
to send emails.
The location
is particularly
important as it is
used to determine
the time zone,
daylight saving
compensation,
times for sunrise
and sunset and
the weather
forecast.
can click on the TEST button, and you
should see a response similar to that
shown in Screen 4.
For large cities, you can also enter a
suburb (eg, “North Sydney”); if that is
found, it will provide you with a more
specific weather forecast.
The database has over 200,000
cities and towns, so you should be
able to find your location. If you cannot, try for the nearest larger city or
town within the same time zone. The
weather predictions might still be
accurate enough, depending on how
close it is to you.
These functions use data from Open
Weather Map (http://openweathermap.
com). It uses that service to look up the
latitude and longitude when validating your location. The program can
then use that information to query
Open Weather Map for your time zone
(including DST) and the sunrise and
sunset times.
If a schedule depends on the weather
forecast, the program will query Open
Weather Map for the 24-hour forecast
before running the watering schedule. With that data, the program can
determine if the schedule should be
skipped or modified.
If you do not enter a location, the
Controller will still operate but will
use the AEST (GMT + 10 hours) time
zone or whatever is set in the BASIC
program. You can still set a watering
schedule and start times, but compensation for daylight saving will not be
included, and you will not be able
to set times based on sunset/sunrise
or modify the schedule based on the
weather.
Screen 4: you can
test the location
you entered and
if it is found,
you will see a
message like this.
When you test the
email function,
you will see a
similar message
confirming that it
worked OK.
Sensors
There is a section below the location
data where you can configure the flow
and/or rain sensors (if fitted).
The flow sensor will alert you if the
water flow for a particular valve is significantly over or under its average
flow rate. Either case will cause the
status LED to flash and add a warning message on the main web page of
the Controller. However, these can be
missed, so an email alert (see below)
should also be configured to ensure
you are notified of the fault.
If the fault is not corrected, the Controller will, over time, add this abnormal flow into its average flow rate for
the valve and eventually stop treating
it as a failure. So, if you get an email
indicating a fault, make sure that you
siliconchip.com.au
attend to it. When you fix the fault,
click the button to reset the average
so that the BASIC program knows to
build a new average for fault detection
(it will do that for all valves).
You can connect a rain sensor and, if
configured, the Controller will not run
a watering schedule if it is currently
raining. That is in addition to checking
the weather forecast. Most rain sensors
Australia's electronics magazine
have normally-closed contacts that
open in the case of rain, which is what
the Controller is designed for. You just
need to connect it to the screw terminal on the Controller and tick the box
to enable this function.
Sending emails
This is an invaluable feature as
you would not normally check the
August 2023 39
Controller’s status LED or web page
daily. Because sprinklers are usually run before sunrise, critical faults
can remain unnoticed for months, by
which time they could have done a lot
of damage to your garden.
To send emails, you need to open
a free account with SendGrid (http://
sendgrid.com). Opening the account
is a little tedious because they need to
verify your identity to prevent spammers from abusing their service. However, with the account created, you
can get a free API key (a 69-character
string) that you can enter in the API
key field.
When you get the key from SendGrid, you must also provide them
with a matching “from email address”,
which should be entered in the next
field (From Email Address). Finally,
you need to provide an email address
to receive emails. This can be the same
as the From Address or different.
To test your settings, click on the
TEST button. After a few seconds,
you should see a confirmation message telling you that a test email has
been successfully sent. You can then
check your email inbox to confirm you
have received it.
Circuit details
The circuit diagram for the Watering System Controller, Fig.2, is dominated by the Raspberry Pi Pico W (ie,
the WebMite). The only other significant components are the power supply and the solenoid drivers.
All valves use a single common
return connection. The Controller
is designed for the typical solenoid
valves used in domestic reticulation
systems that are controlled by 24V
AC. These solenoids usually draw a
surge current of 350mA when energised, then drop to a holding current
of about 220mA.
Photo 1: The fully populated Watering System Controller PCB (shown smaller
than actual size). Along the bottom edge are the screw terminals for the power
input, the master valve plus eight sprinkler valves and the inputs for the
optional flow and rain sensors. The board has plenty of space below the screw
terminals to route the wires.
40
Silicon Chip
Australia's electronics magazine
An IXYS CPC1965 solid-state relay
drives each valve. These switch on the
zero crossing of the AC waveform, so
there are no problems with inductive
kickback from the coils in the solenoid valves. These are controlled by
an inbuilt LED that provides isolation
between the input and output.
The drive current for the LED is
about 5mA (limited by the 470W resistor), well within the drive capability of
the microcontroller’s digital outputs.
Only two solenoid valves can be
energised at once: the master and the
currently open sprinkler valve. These
are protected by separate PPTC (polymeric positive temperature coefficient)
‘fuses’, which increase in resistance if
there is an excessive current through
them, limiting the maximum current.
When the fault is removed, they revert
to regular operation. They protect
against short circuits in a solenoid or
the solenoid wiring.
The power supply is a switching
buck (step-down) regulator providing 5V DC to the WebMite and the
flow sensor (if fitted). This comprises
switching regulator REG1, inductor L1, diode D1, a feedback voltage
divider that sets the output to 5V and a
couple of bypass/filter capacitors. The
power requirement of the Controller is
modest at 60-100mA.
However, the relatively high input
voltage of around 34V DC from the rectified 24V AC would result in 3-4W of
heat being generated by a linear regulator. In a sealed enclosure, that could
lessen the life of the electrolytic capacitors. With the switching power supply, dissipation is less than 1W.
The life of the electrolytic capacitors is a major consideration, as the
Watering System Controller should
ideally last for 10-20 years or more. For
this reason, we have specified high-
voltage, high-temperature capacitors
with higher capacitances than strictly
necessary. Those factors together
should extend the life of the capacitors considerably.
5V power to the WebMite is supplied via schottky diode D2. This is
to isolate the Controller’s power supply from the USB 5V provided by your
computer if you have plugged that into
the WebMite, letting you use the USB
port to debug and test the software on
the WebMite even while the Watering
System is powered.
The flow and rain sensor inputs are
pulled up to 3.3V (from the Pico) by
siliconchip.com.au
Fig.2: the Watering System Controller circuit is dominated by the Raspberry Pi
Pico W (ie, the WebMite). The power supply at upper left is a switching design
to reduce heat generation. The solenoid drivers on the right switch on the zerocrossing of the AC waveform to avoid inductive spikes from the solenoid valves.
3.3kW resistors and clamped to stay
within the supply rails by pairs of
schottky diodes. The diodes are for
protection from miswiring, nearby
lightning strikes etc. In both cases, the
input is pulled to ground by the sensor, which is detected and processed
by the WebMite’s BASIC program.
There are two LEDs and two tactile
switches mounted on the PCB. The
red LED indicates the controller status; when it is solidly lit, the Controller is operating without fault. If it is
siliconchip.com.au
flashing or off, that indicates a fault
like an abnormal flow detected by the
flow sensor, an inability to connect to
the internet etc.
The green LED illuminates when the
Controller is running a watering cycle;
the abort button below it can terminate
this cycle. The reset switch will force
the WebMite to reboot, which is useful if you are upgrading the firmware.
Circuit board design
The fully-populated Watering
Australia's electronics magazine
System Controller PCB is shown
in Photo 1. This is intended to be
mounted in a RITEC RP1285BF 186
× 146 × 75mm waterproof sealed
enclosure. Altronics stocks this (Cat
H0310F) and there are others of a similar size, some with a clear lid.
Note the screw terminals along the
bottom edge of the PCB. The first on
the left is the 24V AC power input.
While a capacity of 1A is specified, a
source capable of providing 750mA or
more should work OK.
August 2023 41
Further along the bottom are the
outputs for driving the eight sprinkler
valves plus one master valve.
Also on the bottom edge are the
inputs for the optional flow and rain
sensors. The flow sensor should be a
Hall effect type that can be powered
by 5V DC. The parts list gives a typical example, although there are many
other suppliers. The rain sensor does
not need power and should be a type
with normally-closed contacts; again,
the parts list gives a typical example.
The board is designed so there is
plenty of space between the screw
terminals and the bottom of the case,
allowing you to route the wires easily.
On the top of the PCB, there is space
for a small toroidal transformer that
can be installed by a qualified electrician if the Controller is to be permanently wired to a power circuit.
Before you decide on the placement
of the Controller, check that the WebMite can reach your WiFi network at
that location. As described later, you
can do this by loading the firmware
onto the WebMite and powering it
with a 5V USB power bank or portable computer. If you can call up its
web page from that location, you are
good to go.
24V AC power source
24V AC is the standard power supply for domestic watering system controllers and if you are replacing an
existing controller, it might already
be available.
We mounted the prototype Watering
System Controller next to the house
fusebox, which had a mains GPO
socket inside, then used
a 24V AC plug pack
to power the Controller. This is the best
and most economical solution; suitable plug packs are inexpensive and
easy to find. Typical examples are Jaycar MP3032 and Altronics M9379A.
If you want to power the Controller
from the mains, you will need a qualified electrician to run the cables and
connect them to a power circuit. This
is expensive, so we do not recommend
it, but if you must, the PCB has space
for a small toroidal transformer at the
top, such as Jaycar Cat MT2112 or Vigortronix VTX-146-030-212.
The Controller does not have facilities for terminating and fusing the
transformer primary as that would be
done by the electrician.
Construction
The Controller is built on a 132
× 152mm double-sided PCB coded
Fig.3: this shows where to
place the components on
the PCB. Note that many
parts are optional and
could be left off if you
don’t need them. Take care
with the orientation of
the IC, diodes, SSRs and
electrolytic capacitors.
42
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
15110231, with the components
mounted as shown in Fig.3.
Before you start, you need to decide
what options you will include or
exclude. The first is the number of
valves to control. Most reticulation
schemes only need two, three or four
sprinkler valves, but the Controller
can control up to eight to accommodate large layouts. Most constructors
will choose one of the options mentioned in the parts list: four, six or
eight valves.
The two sensor inputs are also
optional. You can omit the associated components if you do not plan
to install a rain or flow sensor. Still,
you might want to fit them in case you
decide to use them later.
The two LEDs and tactile switches
are also optional. They are helpful if
you are fault-finding or setting up the
Controller, but they will be of little
use once the box is sealed. You could
mount them on the front panel using
waterproof LEDs and switches with
flying leads, where they would be
much more useful.
We mounted a waterproof power
switch and status LED on the front
panel of our prototype. If you see the
LED flashing, you can visit the Controller’s web page to determine the cause.
All the components are throughhole types, so construction should be
easy and there are no particular tricks.
Follow Fig.3 and the silkscreened text
on the PCB and start with the low profile components, working towards the
taller components.
The WebMite (Pico W) can be soldered directly to the PCB, but we
strongly recommend using sockets on
the PCB and pin headers on the WebMite to make it a plug-in device. That
way, you can easily remove it for testing and fault-finding.
Loading the firmware
Before you plug the WebMite into
the board, load the firmware via the
USB port on a computer (Windows,
Mac or Linux). Starting with a factory-
fresh Raspberry Pi Pico W, you first
need to load the WebMite firmware
(MMBasic). The process is described
in detail in the WebMite User Manual,
but we will summarise it here:
1. While holding down the white
button on the top of the Pico, plug it
into your computer. The Pico should
appear as a pseudo USB drive on your
computer.
siliconchip.com.au
Parts List – Watering System Controller
1 double-sided PCB coded 15110231, 132 × 152mm
1 Raspberry Pi Pico W microcontroller module (MOD1)
1 RITEC RP1285BF 186 × 146 × 75mm sealed enclosure
[Altronics H0310F, DigiKey 164-RP1285BF-ND, Mouser 546-RP1285BF]
1 330μH 0.5A bobbin-style inductor (L1) [Altronics L6227]
1 IXYS CPC1966Y or CPC1965Y solid-state relay (SSRLYM)
[Mouser 849-CPC1966Y or 849-CPC1965Y]
2 500mA hold current, 1A trip PPTC resettable fuses (PTC1-2)
[Altronics R4550A or Bourns MF-RX050/72-AP]
2 PCB-mounting momentary tactile switches (S1, S2) [Altronics S1120]
2 two-way 5/5.08mm 45° PCB-mounting terminal blocks (CON1, CON2)
[Altronics P2044A]
2 20-pin headers, 2.54mm pitch (for MOD1)
2 20-pin header sockets, 2.54mm pitch (for MOD1)
2 3AG PCB-mounting fuse clips (F1) [Altronics S5980]
1 3AG slow-blow 500mA fuse (F1)
4 No.4 × 6mm panhead self-tapping screws
Semiconductors
1 LM2574(Y)N-ADJ buck regulator, DIP-8 (REG1)
1 W04 400V 1.2A bridge rectifier (BR1) [Altronics Z0073 or Z0073A]
2 1N5819 40V 1A schottky diodes (D1, D2)
1 3mm red LED (LED1)
1 3mm green LED (LED2)
Capacitors
2 220μF 63V 105ºC radial electrolytic caps
Resistors (all ¼W 5% axial)
1 10kW
1 3.3kW
3 470W
Extra parts for a four-, six- or eight-valve controller
4, 6 or 8 IXYS CPC1966Y or CPC1965Y solid-state relays (SSRLY1-SSRLY8)
[Mouser 849-CPC1966Y or 849-CPC1965Y]
4, 6 or 8 470W ¼W 5% axial resistors
2, 3 or 4 two-way 5/5.08mm 45° PCB-mounting terminal blocks
(CON3-CON6) [Altronics P2044A]
Extra parts for the flow sensor
2 1N5819 40V 1A schottky diodes (D3, D4)
1 10kW ¼W 5% axial resistor
1 3.3kW ¼W 5% axial resistor
1 three-way 5/5.08mm 45° PCB-mounting terminal block (CON7)
[Altronics P2045A]
1 5V-powered flow sensor, TTL output
[Valves Direct siliconchip.au/link/abmg]
Extra parts for the rain sensor
2 1N5819 40V 1A schottky diodes (D5, D6)
1 10kW ¼W 5% axial resistor
1 3.3kW ¼W 5% axial resistor
1 two-way 5/5.08mm 45° PCB-mounting terminal block (CON8)
[Altronics P2044A]
1 rain sensor with NC contacts [Valves Direct siliconchip.au/link/abmh]
2. Locate the WebMite firmware
(with a name like WebMiteV5.07.07.
uf2) and drag and drop that into the
USB drive.
3. When it finishes copying, the
WebMite will reboot and reconnect
to your PC as a serial port over USB.
The green LED on the top of the Pico
W should slowly flash.
4. Determine the name of the serial
Australia's electronics magazine
port used by the WebMite (ie, COM12),
then use Tera Term (http://tera-term.
en.lo4d.com) to connect to that port.
5. Press return/Enter and you
should see the MMBasic command
prompt (the > character).
Next, you must set the WebMite
options for accessing the WiFi network. These are entered at the command prompt and each will cause the
August 2023 43
Modifying the BASIC program
While the Controller is configured via its web pages, you can also change
some minor settings by editing the BASIC program. To do this, use Telnet to
connect to the WebMite’s console (eg, using Tera Term), then press CTRL-C
to interrupt the running program.
Enter EDIT at the command prompt to run the editor. Scrolling down, you
will see part of the program labelled “User changeable constants”, as shown
in code below. These are the parameters that you can easily change.
The status LED will flash continuously if you have not entered a location on
the general setup page. To avoid this, you can turn off the warning by setting
DisableLocationWarning to 1 instead of 0.
You might want to change the default time zone from AEST (+10 hours).
To do this, change the line CONST DefaultTimeZone = 10.0 to your time zone.
For example, Adelaide is 9.5. Note that the program will not be able to correct
for daylight saving in this case.
The program will signal a fault from the flow sensor if the value is 50%
above the long-term average. This can be changed by changing the entry
Const UpperFtolerance = 50 to another value. For example, if you wanted the
Controller to be much more sensitive to excessive flow, you could change the
value to 20 (20%).
Similarly, for the lower tolerance (reduction in flow), change the entry Lower
Ftolerance on the line below.
We have registered an account with Open Weather Map and used the associated API key in the Watering System Controller program. Their free account
provides us with everything we need. The only significant restriction is that
users of the key are limited to 60 queries per minute or a million in a month.
That means that all users of this program will be using the same API key,
but that should be fine as it is unlikely for 60 users to all make a call in the
same minute. However, you can get your own access key if you want to be
independent.
If you open an account with Open Weather Map, they will provide you with an
API key. The key is a 32-character-long string of letters and numbers that acts
like a password. To replace the key in the code, edit the program line starting
with “Const OWMKey =”.
When the program gets the weather forecast from Open Weather Map, the
chance of rain is returned as a percentage, with 0 representing no chance of
rain and 100 indicating certainty. If a schedule is configured to skip watering on a forecast of rain, the program will do this if the chance of rain is at
least 90%.
You can change this threshold to anything you want by changing the line
“Const RainThreshild = 90”. For example, if you only want to skip watering if it
is certain to rain, you can set the value to 100 (ie, 100% chance).
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' User changeable constants
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
‘ set this to 1 to disable the location warning
Const DisableLocationWarning = 0
‘ this is the default time zone if the location is not set
Const DefaultTimeZone = 10.0
‘ the
Const
‘ the
Const
% increase in flow rate to trigger a fault
UpperFtolerance = 50
% decrease in flow rate to trigger a fault
LowerFtolerance = 50
‘ % forecast % chance of rain required to skip a schedule
Const RainThreshild = 90
‘ API key for accessing Open Weather Map
‘ This key is shared between all users of this program and is
‘ limited to 60 queries/minute. This should not be a problem but
‘ you can easily get your own key and be inderpendent. To do this
‘ goto https://openweathermap.org/ and open a free account, then
‘ generate a key and replace the key below with your own key.
Const OWMKey = "73cd207244614965fc5ca3646bdd10ab"
44
Silicon Chip
Australia's electronics magazine
WebMite to reboot, so you will need to
reconnect the Tera Term session after
each (the double quotes are required
for the SSID and password values):
OPTION WIFI “SSID”, “password”
OPTION TCP SERVER PORT 80
OPTION TELNET CONSOLE ON
The following command will show
the IP address that your router has
allocated to the WebMite:
PRINT MM.INFO(IP ADDRESS)
Now you need to copy some files
to the WebMite’s internal file system.
The best way to do this is by using
TFTP on your computer. Follow these
instructions for Windows: siliconchip.
au/link/abmf
The files are in the download for
the Watering System Controller and
are named “retic.bas”, “config.html”,
“index.html” and “setup.html”. Use
the following TFTP commands to
transfer the files (ipaddr is the IP
address of the WebMite):
TFTP
TFTP
TFTP
TFTP
-i
-i
-i
-i
ipaddr
ipaddr
ipaddr
ipaddr
PUT
PUT
PUT
PUT
retic.bas
config.html
index.html
setup.html
You can check that the files have
copied correctly by using the command FILES at the MMBasic prompt.
That will list the files in the internal
file system.
Now you can run the BASIC program using the following command
and the Watering System Controller
should start up:
RUN “retic.bas”
When the program starts, it will
print a series of status messages on the
console. The program does this whenever it takes some action; it is useful
for debugging and understanding what
is happening.
You can now fire up your web
browser and enter in the address field
the IP address of the WebMite that you
determined earlier. When you press
Enter, you should then see a web page
similar to Screen 1 (without the configuration data entered).
Note that it’s possible to skip all
the steps above apart from setting the
WiFi options and running the program by instead loading the all-in-one
“WaterCtrl.uf2” file that’s included in
the download package.
Now you can install the WebMite
on the Controller PCB, place the
siliconchip.com.au
Controller in its final location and
attach the case lid. You can then set
up the Controller as described earlier
by accessing it via WiFi, configuring
each watering schedule, completing
the basic setup section to enter your
location etc.
Fault-finding
If the Controller does not work as
expected, first check the status LED. If
it is off or flashing, that means a fault
has been detected; if it is permanently
illuminated, that means that everything is working correctly (as far as
the program is concerned). While the
Controller is starting up, the LED will
turn off or flash for a while, but if it
is still flashing after a minute or two,
something is wrong.
If the LED indicates an error, log into
the Controller web page and check for
a message in red at the bottom. This
could be an incorrect configuration,
inability to access the internet, excessive water flow etc. When you correct
this error, the message should vanish
and the status LED will stop flashing.
If you cannot log into the web page
or the Controller appears dead, unplug
the WebMite and plug it directly into
the USB port on your computer. Then
use Tera Term to access the serial-overUSB console to diagnose the problem.
You might have to press CTRL-C to terminate the running program so you can
access the MMBasic console.
Try restarting the BASIC program
with the command RUN “retic.bas”.
As the program starts, you should see
a series of messages in your terminal
emulator describing the progress. The
first will be concerned with connecting
to your WiFi, then connecting to the
internet, followed by more messages
detailing the progress in getting your
location and time zone from Open
Weather Map.
The success or failure of these
should give you some pointers as to
where to look. Typical problems that
can trip you up include:
● Not programming the Pico W with
the correct WebMite firmware.
● Incorrect SSID or password in the
OPTION WIFI command.
● Your router is not configured for
WPA-PSK security and DHCP.
● Your router is blocking the WebMite from reaching the internet.
● You have not set the options correctly. Use OPTION LIST to check
them.
siliconchip.com.au
Photo 2: the Controller mounted in a waterproof sealed enclosure. This shows it
with an onboard 24V mains transformer, but note that it must be installed by a
qualified electrician who will terminate the primary and connect it to a suitable
power circuit.
● You have not copied the program
files to the WebMite. Use the FILES
command to check that all four files
have been copied correctly and are
not zero bytes.
If the WebMite seems fine while
plugged into your computer but not in
the enclosure, it could be something as
simple as a wire inside the controller
box draped near the WebMite’s WiFi
aerial, reducing its sensitivity.
If the fault appears to be with the
control board, you will have to revert
to traditional fault-finding procedures
like checking that the power supply
is working correctly and 5V is on the
Australia's electronics magazine
VSYS pin of the WebMite. Also check
the component values and examine
your soldering in detail.
Hopefully, your Watering System
Controller will work the first time, and
you can relax knowing that your plants
will have all the water they need.
For future software updates, check
the Silicon Chip website or the author’s
website at http://geoffg.net/retic.html
Consider joining the Back Shed
Forum (www.thebackshed.com/
forum/Microcontrollers), where many
enthusiastic WebMite and MMBasic
users are happy to help newcomers
with advice and hints.
SC
August 2023 45
|