Introduction: Smart WiFi Router Reboot Switch Using Onion Omega 2 & 1

About: Hardware design engineer

The Internet is a very important part of our daily life and it sucks when we lose wifi connection. A lot of time when we lose wifi connection, we have to manually power reset the router. In this project, we will make a smart WiFi Reset switch. So whenever you lose the internet it will reboot your wifi router. In this project, we will be using the following hardware.

1. Onion Omega

2. Onion Omega I2C Shield

3. One Channel Relay Shield

Step 1: How It Works

This is a surprisingly simple project. Onion Omega has built-in WiFi which will be connected to your local router. It will constantly ping a web address and if it doesn't get any response it will trigger a false condition in our script. The script will run on our Onion Omega and will be constantly monitoring so that if the internet is accessible the Onion Omega will have a true condition and when the internet is down it will have a false condition. Once onion omega has a false condition it will toggle the power and it will reboot the router.

Step 2: Hardware Connection and Setup

The onion omega is plugged into the Onion omega I2C adapter.
This Onion Omega adapter has a USB port which will provide power to the Onion Omega and the relay board. It also has an I2C connector, which makes it really easy to connect it with all kinds of I2C devices. 1 Channel Relay board -- this board from controleverything.com has a PCA9536 chip and one SPDT relay on it. It also has an I2C connector so it's easy to connect with the Onion Omega I2C adapter. We will also need a 2.4mm barrel connector and a power cable. To make the connection plug the Onion Omega into the I2C shield and connect the relay board to the I2C shield. The barrel connector has 3 pins. The tip of the barrel connector will be connected to the Normally Open of the relay board and Sleeve will be connected to the power cable ( as shown in the picture). The other wire of the power cable will be connected to the relay common. So the relay board is simply working as a switch.

Step 3: Python Script for WiFi Router Auto Reboot

This script has 2 parts. The first part is to check if the internet is working or not and the second part is to reboot the router.
In this first part, we will check if the internet is working or not. If it's not working we will reboot the router by resetting the power. The code can also be found here: Onion omega Smart router reboot switch.

The code can also be found over here. Onion omega Smart router reboot switch

# Smart_WiFi_Reset

#use onion omega and relay controller to reset your router

# relay baord https://www.controleverything.com/content/Relay-Controller?sku=PCA9536_I2CR_R11

# onion omega i2c shield https://www.controleverything.com/content/I2C-Master?sku=OOI2C

from OmegaExpansion import onionI2C

import time

import socket

i2c = onionI2C.OnionI2C()

i2c.writeByte(0x41, 0x03, 0x00)

time.sleep(0.5)

i2c.writeByte(0x41,0x01,0x01)

while True :

REMOTE_SERVER = "www.onion.io"

def is_connected():

try:

host = socket.gethostbyname(REMOTE_SERVER)

s = socket.create_connection((host, 80), 2)

return True

except:

pass

return False

if is_connected() :

print "Connected to the internet...."

i2c.writeByte(0x41, 0x01, 0x01)

time.sleep(1)

else :

print " No internet ...."

i2c.writeByte(0x41, 0x01, 0x00)

time.sleep(1)

i2c.writeByte(0x41, 0x01, 0x01)

time.sleep(60)

time.sleep(100)

Step 4: Testing and Debug

After programming the Onion Omega it will turn on the power supply and will wait for our WiFi to connect. Once it's connected to WiFi it will constantly monitor the internet connection and when there is no internet it will reboot the router by resetting the power. You can also login into your Onion Omega and it will display on the terminal if the internet is working or not.
For testing purpose, I will disable the WiFi connection on my Onion Omega and it started to show no internet. Then I enabled the WiFi and it started to show that it was connected to the internet. You can also change the toggle time. So let's say if your router takes a lot of time to boot then you can increase in the code.(change this line time.sleep(100)). It depends on how quick your router responds. If your router takes a long time to reboot then increase the toggle time. You can also use this code to check if your website is working or not.