This is only a preview of the November 2023 issue of Silicon Chip. You can view 47 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. Articles in this series:
Items relevant to "Pico Audio Analyser":
Articles in this series:
Items relevant to "K-Type Thermostat":
Items relevant to "Modem/Router Watchdog":
Items relevant to "1kW+ Class-D Amplifier, Pt2":
Items relevant to "Recreating Sputnik-1, Part 1":
Purchase a printed copy of this issue for $12.50. |
Keeping the Internet Up
By Nicholas Vinen
This simple device for the home or office will automatically restart your
modem or router if it stops working. It can’t stop your internet connection
from dropping out, but it will save you the hassle of pulling the power to see if
it’s the router at fault (which is often the case, unfortunately).
I
t is a sad fact that many of the routers
used for NBN connections these days
are not terribly reliable. They might
work OK for a few days or weeks,
then will suddenly quit for no apparent reason.
Power cycling them will usually
restore your internet connection,
which can be annoying if you are not
home, but other family members are.
Or if it’s in a remote unoccupied office
that you have lost your connection to.
Ask me how I know!
This device is based on the WebMite, with Geoff Graham’s MMBasic
software running on a low-cost Raspberry Pi Pico W with built-in WiFi
(August 2023 issue; siliconchip.au/
Article/15897). The MMBasic code
periodically tries to make a connection
to a remote server that you can expect
to be operating most of the time (eg,
Google, Apple, Microsoft etc).
It will try several of those, and if
it can’t connect to any, it will briefly
interrupt the DC or AC power to your
Modem Watchdog Kit
SC6827 ($35 + postage): contains
all the required (non-optional)
items listed (12V relay). You just
need a small enclosure to house it.
68
Silicon Chip
router to restart it. It will then wait
a little while and resume operation;
hopefully, after that, it will be able
to connect and continue monitoring
the connection until it stops working again.
It’s built on a small circuit board
using only a dozen or so components.
To keep it safe and simple, it is connected between the router’s power
supply and the router, and it is powered from that same power supply. It
will work with modems/routers powered with 9-24V DC or 6-15V AC and
it only draws about 50mA extra from
that supply.
Circuit details
The Watchdog circuit is shown in
Fig.1. As most of the hard work is done
by software running on the WebMite
(Pico W), there isn’t much to it.
AC or DC from the router’s supply
comes in via CON1 or CON2 and is
fed to header CON3 via the normally-
closed contacts of relay RLY1. So
most of the time, power is fed straight
through to the router. RLY1 is activated
for a few seconds when the router
needs to be rebooted, briefly cutting
its power. When RLY1 is released, the
router starts back up and reconnects.
Australia's electronics magazine
RLY1 is controlled by the Pico
W (MOD1) via NPN transistor Q1.
When the Pico W’s GP22 digital output is floating or low, Q1 is off and so
is RLY1. When the Pico brings that
pin high, Q1’s base-emitter junction
is forward-biased, and it sinks current from the negative end of the coil,
energising it.
The 470W resistor limits the base
current to the required level; (3.3V –
0.7V) ÷ 470W = 5.5mA, so when multiplied by the transistor’s gain, it can
sink around 100mA, more than enough
for most typical 12V relays. Diode D2
prevents the coil’s negative end from
flying above 12.7V when it switches
off, which could damage transistor Q1.
The positive end of the relay coil
connects to the main DC supply rail
via resistor R2. This can be a 0W link
when that rail is close to 12V DC, or
a 1W resistor with a value chosen to
drop the voltage seen by the coil to
12V if the supply rail is higher. A 5V
coil relay can be used with a suitable
series resistor for a lower supply rail;
more on choosing its value later.
We also included a 4.7kW/1kW
divider across the supply rail that
feeds the Pico’s GP28 pin, which can
be used for voltage measurements. We
siliconchip.com.au
USB supply feeding back into REG1.
The Pico has an onboard 3.3V regulator, so we don’t need to provide it
with exactly 5V.
Software
Fig.1: the main part of the Watchdog
is the Pico W module (MOD1), relay
RLY1 and NPN transistor Q1. They
conspire to reboot the modem or
router powered via CON3 when it
stops working. Power for both the
modem/router and the circuit comes
in via CON1 or CON2. It is rectified,
filtered and regulated to power
MOD1.
did this in case it was helpful for the
Pico to monitor the plugpack’s output, which would allow something
like a ‘brownout protection’ feature to
be added. We’ve tested this function
but haven’t enabled it by default, as it
doesn’t seem that useful.
Power output header CON3 can
be wired to a suitable plug cut off a
defunct plugpack or cable, or made
from a new plug soldered to a length
of twin lead. The CON1 input is an
onboard 2.1mm or 2.5mm inner diameter barrel socket that many plugpacks
will plug into, while header CON2 can
instead be wired to an offboard socket
if that’s easier, or your power supply’s
plug does not fit CON1.
Power supply
To derive power for the Pico W,
first, we apply the input from CON1
or CON2 to bridge rectifier BR1, which
has a 220µF filter capacitor across its
outputs. This will convert AC to DC, or
if the input is already DC, it will ensure
that a positive voltage is applied across
that capacitor regardless of how the
supply output plug is wired.
For a 6-15V AC input, we can expect
around 7-20V DC (6-15V AC × 1.414
– 0.7V × 2) across the 220µF filter
siliconchip.com.au
capacitor. We’ll get around 1.4V less
than the incoming supply voltage for
a DC supply, ie, 7.6-22.6V DC for the
stated input range of 9-24V DC.
5V linear regulator REG1 is powered from the voltage across the 220µF
capacitor with a 10W series dropper
resistor and 100nF input bypass/output filter capacitors. The 7805 has a
specified maximum input voltage of
35V, so it will easily handle the maximum expected voltage at its input. Its
dropout voltage is around 2V at 1A,
so it will be in regulation down to 7V.
The WebMite is in sleep mode a lot
of the time; when it is operating, it
draws around 50mA on average. With
a 24V DC input, we can expect REG1
to dissipate 880mW ([22.6V – 5V] ×
50mA). That’s within the capabilities
of a TO-220 package without a heatsink, although the PCB is designed to
allow you to attach a small heatsink
if you need to.
In most cases, the input voltage will
be lower, no more than 15V, so most
users will not need to add a heatsink.
The Pico W is powered from the
output of REG1 via diode D1, which
allows you to connect the Pico W to
the USB port of a computer without
the possibility of the computer’s 5V
Australia's electronics magazine
The software is written in MM-
Basic, using Geoff Graham’s WebMite
firmware to simplify the code. That is
especially useful if you want to modify or customise it, as there is lots of
documentation available for the WebMite, and it’s easy to alter its code over
a USB or WiFi connection.
The program is simple. It updates
its onboard clock every two minutes
using the internet NTP protocol. If
your router is not working, that will
fail. In that case, it then tries to connect
to major web servers (google.com and
microsoft.com), although it doesn’t
request any data; it is just checking to
see if it can connect.
If all three attempts fail, it brings
the GP22 pin high for five seconds to
cut power to the router, then waits five
minutes and reboots, to reinstate the
WIFI connection, before it starts monitoring the internet connection again.
The watchdog timer is also enabled
so that, should something go wrong
and the Pico W freezes for too long
(at least six minutes), it will automatically reboot.
Programming the Pico W
You can do this before building the
unit. It can be programmed before or
after; it doesn’t make much difference,
but it’s a little bit easier dealing with
the Pico W before it has been soldered
to our board.
Use a micro Type-B USB cable to
connect it to your computer and a virtual flash drive should be detected.
You can either load MMBasic onto it,
making it a WebMite, then install the
BASIC code and set it up yourself, or
load our “RouterWatchdogV1.uf2”
The Modem Watchdog shown at
actual size with the PicoW unplugged.
November 2023 69
Replace ssid and password with
your WiFi network credentials. After
typing that command and pressing
Enter, the Pico W will reboot and
attempt to connect to your WiFi network. You can verify this has worked
by reconnecting to the USB serial port,
pressing CTRL+C again and typing:
PRINT MM.INFO(IP ADDRESS)
This should give you an address
like 192.168.1.100, indicating that it
is connected to your network, which
means the device is now working. You
can unplug it and proceed with construction.
Component selection
The assembled board, ready to be
mounted in a small plastic case.
file, which already has the BASIC
code loaded and most of the settings
configured.
You can download that file from
our website at siliconchip.com.au/
Shop/6/260
See the panel on loading the BASIC
code and setting the options if you’d
prefer to do that yourself.
There are a few settings we can’t
provide, like the WiFi network credentials, so once the firmware is loaded,
you’ll need to open a serial connection
to the WebMite to finish the setup. You
can use a free program like PuTTY or
Tera Term to connect to the WebMite’s
virtual serial port at 115,200 baud.
Press CTRL+C, and after a while, you
should see the “>” prompt (be patient,
as it won’t respond to key presses in
sleep). Enter the following command:
OPTION WIFI “ssid”, “password”
100nF
CON2
REG1
VERIFY POLARITY CONSISTENCY
COIL
100nF
~ –
+ ~
COIL
40
30
+
~ –
+ ~
MOD1
1
38
37
39
36
2
35
3
5
4
34
31
33
7
8
32
6
9
11
28
29
10
12
26
27
13
25
14
16
23
24
15
18
17
21
22
40
38
Silicon Chip
Q1
CON3
ALTERNATIVES
CON1
D2
Fig.2: the missing parts are for
optional features. See the “Component
selection” section of the article to
calculate the value for R2 and select
an appropriate relay.
70
19
20
1
2
37
39
36
R2
The Watchdog PCB layout is shown
in Fig.2. Some components may
depend on your router’s power supply
voltage or are for features that aren’t
required for the basic function, so
those components are shown translucent, with their values in parentheses.
Start by mounting the axial components, such as resistors and diodes;
the diodes must be orientated with
the cathode stripes facing as shown.
Fit the bridge rectifier next, ensuring
its + symbol is in the location shown,
then the transistor with its flat face
towards the top of the board.
Now fit the two smaller capacitors,
followed by the DC socket; try to make
the latter parallel/perpendicular to the
PCB edge before soldering it.
Then you can install the two polarised headers, the electrolytic capacitor
D1
10W
B R1
RLY1
3
5
CON1
4
33
220mF
35
470W
34
31
+
32
28
30
Q1
29
CON2
26
CON3
27
23
25
24
21
22
(1kW)
Construction
MICRO
USB–B
PORT
RASPBERRY
PI Pico W
SWDIO
(4.7kW)
7
8
GN D
6
9
10
13
12
11
14
15
16
18
17
19
20
RP2040
MCU
WIFI SWCLK
MODULE
The only components you may need
to change are the relay (RLY1) and its
coil’s series resistor (R2). Start by using
a DVM to check the output voltage of
the plugpack powering your modem
or router. Determine whether it is AC
or DC and its magnitude.
If it’s 12-15V DC or 9-12V AC, you
should be able to build the unit as per
Figs.1 & 2 and the parts list, with R2
replaced with a wire link.
If it’s above 12V DC but below 24V
DC, or above 10V AC, use a 1W resistor
for R2. For a DC supply with a voltage
of Vin, its ideal value is (Vin − 13.4V) ÷
0.044A. That’s based on the 44mA coil
current for the JW1FSN-DC12V relay
specified. For example, if the supply
is 18V DC, you would use 104.5W
([18V − 13.4V] ÷ 0.044A), which we
can round to 100W.
For an AC supply above 12V (Vacin),
multiply the voltage reading by 1.414,
then plug the result into the formula
above. For example, for 12V AC, 12V
AC × 1.414 = 17V DC, which gives us
a value of 81.8W, close to the preferred
value of 82W.
If your supply is close to 24V DC,
you could go back to using a wire link
for R2 and substitute a 24V DC coil
relay for RLY2.
For supplies below 12V DC or 9V
AC, use a 5V DC coil relay for RLY1
with a series resistor. The formula for
that resistor value is (Vin − 6.4V) ÷
0.106A; if it’s an AC supply, again multiply the voltage by 1.414 first.
For example, for a 9V DC supply,
use a 5V relay with a series resistor
value of 24.5W ([9V − 6.4V] ÷ 0.106A),
which we can round to 22W or 24W.
Similarly, for 6V AC, use 19.7W ([6V
× 1.414 − 6.4V] ÷ 0.106A), so select
either 18W or 22W.
Fig.3: the only wiring strictly required is for the output cable that goes to the
modem/router, as shown here. An external power input connector can be wired
into CON2 if the onboard connector doesn’t suit your modem/router’s power
supply. The polarity only matters because it must be consistent between the
input socket and output plug if using a DC supply.
Australia's electronics magazine
siliconchip.com.au
and the regulator. The electro has its
longer (positive) lead towards the top
of the board and the stripe on the can,
indicating the negative side, towards
the bottom. The regulator shouldn’t
need a heatsink but its tab is near the
edge of the board, so you can fit one
if you want to.
There are a few different ways to
mount the Pico W. You can mount it
horizontally or vertically; either way,
you have three ways to solder it: solder the two boards directly to each
other, use a header to join them, or use
a header and socket, allowing you to
easily unplug the Pico W.
In our prototype, we mounted
it horizontally into a socket so we
could unplug the Pico W during
development if necessary. However,
it’s much easier to solder it directly
using a header (straight or right angle),
depending on what will fit in your box
best. Therefore, the kit will include
headers but no socket.
Before soldering it, check if it will
block access to two of the PCB mounting holes. If so, you’ll have to attach
spacers to them first, and you might
want to use Nylon screws to ensure
they can’t short against the Pico W.
We’ll leave the choice to constructors, but regardless of your method,
check that you’re connecting it the
right way around. Only half the pins
of the Pico are soldered to the board,
with pin 21 on the connector end of
our board and pin 40 at the regulator
end. If in doubt, check Fig.2. If mounting it horizontally, it will hang off the
edge of our board.
Finally, fit the relay. It will only go
in one way. Ensure it is pushed down
fully before soldering its pins. Then
attach tapped spacers to the corners
of the board using machine screws.
Wiring
For the power supply cable to the
router, you will need a length of twin
lead with a suitable socket on the end,
as shown in Fig.3. We will supply a
USB-to-barrel-socket cable in the kit,
with the reasonably common 2.1mm
inner diameter plug type. It will suit
many routers but probably not all.
The idea is to cut off the USB plug
and crimp and/or solder it to a polarised header plug, then plug that into
the output header, CON3. If the supplied cable is no good, you’ll need to
find or make one with the correct plug
for your router.
siliconchip.com.au
Parts List – Modem/Router Watchdog
1 double-sided PCB coded 10111231, 51 × 42mm
1 Raspberry Pi Pico W microcontroller module (MOD1)
1 12V DC coil 5A+ SPDT relay (RLY1) ●
[Jaycar SY4050, Altronics S4197 or JW1FSN-DC12V]
1 PCB-mounting barrel socket, 2.1mm or 2.5mm inner diameter (CON1)
2 2-way vertical polarised headers with matching plugs (CON2, CON3)
1 20-way straight or right-angle header (for mounting the Pico W)
1 20-way female header socket (optional; to socket the Pico W)
1 barrel plug and cable from a disused plugpack or USB to barrel plug cable
8 M3 × 6mm panhead machine screws
4 10mm long M3-tapped spacers
Semiconductors
1 7805 5V 1A linear regulator, TO-220 (REG1)
1 BC547 100mA 45V NPN transistor (Q1)
1 W02M/W04M/2W02/2W04 bridge rectifier (BR1)
2 1N4004 400V 1A diodes (D1, D2)
Capacitors
1 220μF 50V electrolytic
2 100nF 50V ceramic or MKT
Resistors (all 5% unless noted)
1 470W ¼W
1 10W 1W
1 1W 5% resistor (value depends on supply voltage and relay used; see text)
● a 5V or 24V relay might be required if the router power supply is unusually
low or high
MMBasic Code Listing
WATCHDOG 65000
PRINT “Watchdog initialising”
SETPIN GP22, DOUT
PIN(GP22) = 0
SETPIN GP28, AIN
ON ERROR IGNORE
CPU SLEEP 60
DO
WATCHDOG 65000
CPU SLEEP 60
WATCHDOG 200000
PRINT “Checking NTP”
WEB NTP -10
IF MM.ERRNO THEN
PRINT “Checking Google”
WEB OPEN TCP CLIENT “google.com”, 80
IF MM.ERRNO THEN
PRINT “Checking Microsoft”
WEB OPEN TCP CLIENT “microsoft.com”, 80
IF MM.ERRNO THEN
PRINT “Rebooting router”
PIN(22) = 1
WATCHDOG 10000
CPU SLEEP 5
PIN(22) = 0
WATCHDOG 200000
CPU SLEEP 180
CPU RESTART
ELSE
PRINT “OK”
WEB CLOSE TCP CLIENT
ENDIF
ELSE
PRINT “OK”
WEB CLOSE TCP CLIENT
ENDIF
ELSE
PRINT “OK”
ENDIF
WATCHDOG 65000
CPU SLEEP 60
Australia's electronics magazine
LOOP
November 2023 71
Silicon Chip
Binders
REAL
VALUE AT
$21.50*
PLUS
P&P
Are your copies of
Silicon Chip getting
damaged or dog-eared
just lying around in a
cupboard or on a shelf?
Can you quickly find a
particular issue that you
need to refer to?
Keep your copies
safe, secure and
always available with
these handy binders
These binders will protect your
copies of S ilicon C hip . They
feature heavy-board covers, hold
12 issues & will look great on your
bookshelf.
H 80mm internal width
H Silicon Chip logo printed in goldcoloured lettering on spine &
cover
Silicon Chip Publications
PO Box 194
Matraville NSW 2036
Order online from www.
siliconchip.com.au/Shop/4
or call (02) 9939 3295
and quote your credit card
number.
*see website for delivery prices.
72
Silicon Chip
It doesn’t matter which way you
wire it to header CON3, except that it
needs to be consistent with the input
connection to CON1 or CON2. To
check this, ensure the output is not
connected to anything and plug the
power supply into CON1 or CON2.
Use a DMM to check for continuity
between the outer barrel of the power
supply’s plug and the outer barrel of
the plug that will go to the router.
If not, swap the connections at
CON3, then check again. We don’t want
to reverse the polarity of the power
applied to the router (although that
won’t matter if it’s low-voltage AC).
It’s a good idea to double-check
this by plugging the power supply
into a mains GPO and using a digital
voltmeter to check the polarity of the
Watchdog’s output plug. Make a note
of whether the inside of the socket is
positive or negative relative to the outside, then unplug the supply from the
unit and verify that its output polarity is the same as what you measured
coming out of the Watchdog.
You can also check the sticker on
the back of your router to verify it’s
expecting the same polarity.
Housing it
The board is unfortunately too large
to easily fit into the smallest Jiffy box
(UB5), although it will fit comfortably
into the next larger one (UB3). You
could put it in just about any enclosure, or even use it as a bare board, as
long as you’re careful that it can’t short
against anything! If the onboard barrel
socket doesn’t suit your router power
supply, you will probably have to
put it in an enclosure so you can wire
up an appropriate chassis-mounting
socket via CON2.
Testing
Connect the output power plug to
your router, along with all the other
cables the router needs to operate.
Power the whole thing up and check
that the router lights come on and your
internet connection is working after a
few minutes. Leave it for 15 minutes to
verify that the Watchdog relay does not
trigger, causing your router to reboot.
If it does, it probably can’t connect
to your WiFi network, so connect the
Pico W back to your computer and
correct the WiFi credentials.
Assuming it’s working, disconnect
the internet cable from your router
(from the NBN box or whatever is
upstream). Wait a few minutes; you
should hear the Watchdog relay click,
and the router will reboot. Plug the
internet cable back in, as it is all working as expected.
If that doesn’t happen, you might
not have loaded the firmware correctly. If you can’t figure out what has
gone wrong, you might need to load the
Pico W firmware again from scratch.
That involves holding the white button down on the Pico W while plugging it into your computer via a USB
cable so that the virtual flash drive
SC
appears again.
Loading the firmware manually
Start by loading the WebMite firmware onto the Pico W. You can refer to the
August 2023 article on the WebMite (siliconchip.au/Article/15897). However,
the procedure is basically the same as mentioned in the article; you just load
the WebMite .uf2 file rather than the one specific to this project. It is also available to download from our website (siliconchip.au/Shop/6/230).
The next step is to connect to the WebMite using the USB virtual serial port
(as described in the article text), then load the BASIC code and set up the
options. The BASIC file is called “ModemWatchdog.bas” and is part of the
download package linked in the article text.
Open the BASIC file in a text editor like Windows Notepad. Connect to the
WebMite using Tera Term or PuTTY, run the “AUTOSAVE” command, and then
in Notepad, press CTRL+A (to select the whole program) and CTRL+C (to copy
it). If using PuTTY, right-click in the windows to paste the program, then press
CTRL+Z. If using Tera Term, go to that window, press CTRL+V (or ALT+V) to
paste the program, then press CTRL+Z.
You should be back at the MMBasic prompt with the code loaded. You
can check it has been loaded by running the LIST command. Now set up the
options as below. Note that you’ll probably need to reconnect to the WebMite
between some of them:
OPTION WIFI “ssid”, “password”
OPTION TELNET CONSOLE ON
OPTION AUTORUN ON
Australia's electronics magazine
siliconchip.com.au
|