Sunday, January 7, 2018

A simple wireless modem restarter (reseter)

Disclaimer. The author doesn’t bear any responsibility for any consequences related to the device described in this article, including a lost profit. Decisions made by a reader are implemented at his own risk. 

Our company has a remote server connected to the WWW via a wireless modem. The wireless modem is connected to a router. Sometimes the modem cancels the connection without any reasons. Router reset doesn’t give any result, and only the manual turning off of the modem helps to restart it.
As we need to get access to the server even there’s nobody near it, we have to restart the modem automatically. By the way, I heard that miners had the same problems with an internet connection.There’re some solutions on the internet one can find. For example:
  • USB-relay. But you’d have to make a program to control it;
  • IP WatchDog and similar devices. But they are too expensive for this simple job;
  • DIY devices. But they use microcontrollers that you have to program too.
So, I’ve invented my own device to restart the modem by turning its power off.  I don’t pretend that it’s an original idea, but I haven’t found similar schemes yet.My aim was to make a device which:
  • User don’t have to program;
  • Can be built by anyone;
  • Costs almost nothing.
But there’s a disadvantage one should pay for simplicity. You should have a working computer to control the device.So, here’s the scheme. There’s no USB/COM converter on it, but it supposes to be. There are only 5V, TX and GND pins needed to operate.
The principle of operation.
When something is transmitting the COM-port (I used a USB/TTL COM-port converter) it causes some pulses on the TX pin. These pulses induce the start of the long pulse of the 555 chip scheme, which controls the relay that disconnects modem power supply for some seconds. The power for this scheme takes from the USB connector.
The components shown in the scheme are that I had. You can use your own components. For example, IRFZ44N is more than enough for this device, but I had a lot of them. So, you can use other MOSFETs or even bipolar or Darlington transistors. But if you use bipolar or Darlington ones you should replace the relay with one with 4.5V coil and increase the resistance of R2 up to 1-2 kOhms.
You can even use a more powerful relay. But if the relay has coil resistance below 100 Ohm, you should use separate power supply unit to not overload a USB port.
I used a CP210X-based USB/TTL COM-port converter. And it gives negative pulses of TX (3.3-0-3.3V). If your converter gives positive pulses (0-5-0)V, you should use the following input and 555 scheme:

 Yes, that’s not a quite correct scheme of using 555 and especially a transistor, but emulation showed that it works and discharge of the C1 doesn’t cause a breakdown of Q2.
This device was built on a small prototype PCB for inserting directly to the computer USB port.

 The relay was moved to the modem rack and connected to the device with a wire. 5V wire in the holder was cut and connected to the relay.

So, ones you insert this device in the USB-port, a virtual COM-port should appear in your device manager. You should get the number of this port (COM5 for example) and make a .bat or .cmd file with the following content:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion
:Begin
ping google.com
If !ErrorLevel! == 0 (
Echo Internet Online
) Else (
Echo Internet Offline
Echo rebooting modem...
copy win.ini >com5
)
Timeout /t 180 /nobreak  >nul
Goto Begin

And run that file. This is an infinitive cycle that checks ping for google.com (or use your local website with a short timeout), and if there’s no ping it sends ‘win.ini’ file to COM5. Sending something to COM5 causes pulses on the TX pin of the converter and the relay turns on and disconnect the modem power supply.
File ‘win.ini’ was chosen as it’s a tiny file and it’s available from any folder. So, you can place your .bat or .cmd file in any folder you want.
If you don’t want to run this file infinitely, you can delete :Begin, Timeout<> and Goto<> commands from the file and run it by the schedule of the Task Scheduler.
I even heard that .bat or .cmd files are able to run in the hidden mode, but I didn’t try it as I didn’t need it. So, you can find out how to do that by yourself.

Anyway, you can control other stuff with this device by making your own .bat file with your own conditions. You can insert several devices and get control on several channels. So, that’s the idea only, you can apply it to any of your own DIY devices.