Project tutorial
netBOOT

netBOOT © GPL3+

Automatic Cable Modem Rebooter.

  • 2,243 views
  • 0 comments
  • 9 respects

Components and supplies

About this project

Description

I think this may sound familiar to many... Are you away from home when you suddenly need to access remotely your cameras or any other service hosted in your home, BUT your network/internet at home has stopped responding ? You are exactly in the right project.

To solve that, this device will keep pinging some pre-configured websites (or IP addresses) like google.com, google dns, microsoft, facebook... etc.. and then, when none of them respond to a ping after three tries, a relay cuts off power to the cable modem (or to your router as well) for 10 seconds, then a reboot and new sync with the provider will be done.

This is what you will need to build this:

ARDUINO UNO (or ATMEGA328p Standalone) W5100 ETHERNET MODULE RELAY MODULE

Code is available at www.zolalab.com.br

Video: https://youtu.be/4svJ33d-qDQ

Details

netBOOT - version 2 (with display)
netBOOT - version 1


Code

netBoot code version 1Arduino
http://www.zolalab.com.br/eletronica_projetos/netboot.php
// by: Eduardo Zola - 2015 (www.zolalab.com.br) egzola@gmail.com

#include <SPI.h>

#include <Ethernet.h>

#include <ICMPPing.h>

byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

EthernetClient client;

#define MAX_IPs 5

IPAddress pingAddrs[MAX_IPs];

int CNT = 0;

int ERRORS_COUNT = 0;

SOCKET pingSocket = 0;

char buffer [256];

ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

void setup()

{

  pinMode(9, OUTPUT); // relay Pin
  digitalWrite(9, HIGH);

  Serial.begin(9600);

  Serial.println("Iniciando...");

  delay(2000);

  pingAddrs[0] = IPAddress(74, 125, 26, 147); // google.com

  pingAddrs[1] = IPAddress(8, 8, 8, 8); // dns google

  pingAddrs[2] = IPAddress(200, 221, 2, 45); // uol

  pingAddrs[3] = IPAddress(23, 216, 170, 96); // microsoft

  pingAddrs[4] = IPAddress(31, 13, 73, 1); // facebook

  delay(3000);

  while (Ethernet.begin(mac) == 0) Serial.println("Failed to configure Ethernet using DHCP");

  Serial.print("My IP address: ");

  for (byte thisByte = 0; thisByte < 4; thisByte++)

  {

    Serial.print(Ethernet.localIP()[thisByte], DEC);

    Serial.print(".");

  }

  Serial.println();

}

void loop()

{

  if (ERRORS_COUNT >= 3)

  {

    ERRORS_COUNT = 0;

    Serial.println("BOOT");

    boot();

  }

  if (CNT >= MAX_IPs) CNT = 0;

  ICMPEchoReply echoReply = ping(pingAddrs[CNT], 4);

  if (echoReply.status == SUCCESS)

  {

    ERRORS_COUNT = 0;

    sprintf(buffer,

            "Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d",

            echoReply.data.seq,

            echoReply.addr[0],

            echoReply.addr[1],

            echoReply.addr[2],

            echoReply.addr[3],

            REQ_DATASIZE,

            millis() - echoReply.data.time,

            echoReply.ttl);

  }

  else

  {

    sprintf(buffer, "Echo request failed; %d", echoReply.status);

    ERRORS_COUNT ++;

  }

  Serial.println(buffer);

  delay(1000);

  CNT ++;

}

void boot()

{

  digitalWrite(9, LOW); // desliga o modem, por tanto, o relay deve ser usado em NO, ao inves de NC... ou seja, o relay desligado permite que o router fique ligado. Ao acionar o relay, a energia do router eh cortada.

  delay(5000); // aguarda 5 segundos com o modem desligado

  digitalWrite(9, HIGH);

  delay(60 * 1000 * 5); // aguarda 5 minutos para o modem inicializar e reconectar, evitando que a rotina o desligue novamente.

}
netBoot code version 2 (with display)Arduino
#include <SPI.h>
#include <UTFT.h>
#include <Ethernet.h>
#include <ICMPPing.h>

byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

EthernetClient client;


#define MAX_IPs 5
IPAddress pingAddrs[MAX_IPs];
int CNT = 0;
int ERRORS_COUNT = 0;

SOCKET pingSocket = 0;
 
char buffer [256];

ICMPPing ping(pingSocket, (uint16_t)random(0, 255));


extern uint8_t SmallFont[];
UTFT myGLCD(UNO_26,A2,A1,A3,A4);   //USE  UNO_26 FOR ST7787/7781 / UNO_24 FOR SPFD4508A

int Y = 0;

void setup() 
{
   // Setup the LCD
   pinMode(A0,OUTPUT);    // for the UNO_SHIELD_1IN1
   digitalWrite(A0,HIGH);  // the RD pin must be set high
   myGLCD.InitLCD();
   myGLCD.clrScr();
  
   pinMode(9,OUTPUT);
   digitalWrite(9,HIGH);

   pinMode(8,OUTPUT);
   digitalWrite(8,LOW);

     
   Serial.begin(9600);

   Serial.println("Initing...");

   Y = 20;
   
   myGLCD.setColor(0, 0, 180);
   myGLCD.fillRect(0, 0, 319, 14);
   myGLCD.setBackColor(0, 0, 180);
   myGLCD.setColor(255, 255, 255);
   myGLCD.setFont(SmallFont);
   myGLCD.print("netBOOT - Zola Lab", CENTER, 2);
   myGLCD.setBackColor(0, 0, 0);
   myGLCD.setColor(255, 255, 255);
   myGLCD.print("Initing...", LEFT, Y);
   
   Y += 20;
  
   delay(2000); // mantem 2 segundos com a ethernet desligada (reseta a ethernet)
   digitalWrite(8,HIGH);
   delay(2000); // mantem 2 segundos com a ethernet ligada, antes de executar ethernet.begin


  

   pingAddrs[0] = IPAddress(74,125,26,147); // google.com
   pingAddrs[1] = IPAddress(8,8,8,8); // dns google
   pingAddrs[2] = IPAddress(200,221,2,45); // uol
   pingAddrs[3] = IPAddress(23,216,170,96); // microsoft
   pingAddrs[4] = IPAddress(31,13,73,1); // facebook

   Y += 20;
   
   delay(3000);
   while(Ethernet.begin(mac)==0) {Serial.println("Failed to configure Ethernet using DHCP");myGLCD.print("Failed to configure Ethernet using DHCP", LEFT, Y);};

   Clear();
   printIP();
}

void loop() 
{
  if(ERRORS_COUNT >= 3)
  {
      ERRORS_COUNT = 0;

      boot(); 
  }
  
  if(CNT >= MAX_IPs) CNT = 0;

  ICMPEchoReply echoReply = ping(pingAddrs[CNT], 4);
  
  if(echoReply.status == SUCCESS)
  {
     ERRORS_COUNT = 0;
     
     sprintf(buffer,
            "IP: %d.%d.%d.%d    TIME: %ldms",
//            echoReply.data.seq,
            echoReply.addr[0],
            echoReply.addr[1],
            echoReply.addr[2],
            echoReply.addr[3],
//            REQ_DATASIZE,
            millis() - echoReply.data.time
//            echoReply.ttl
            );
  }
  else
  {
    sprintf(buffer, "Echo request failed; %d", echoReply.status);
    ERRORS_COUNT ++;
  }
  Serial.println(buffer);
  myGLCD.print(buffer, LEFT, Y);  

  Y += 20;
  
  if(Y >= 240)  Clear();
    
  delay(1000);  
  CNT ++;  
}


void boot()
{
   Clear();
   Serial.println("BOOT");      
   myGLCD.print("BOOT", LEFT, Y);   
   Y+=20;
      
   digitalWrite(9,LOW);  // desliga o modem, por tanto, o relay deve ser usado em NO, ao inves de NC...  ou seja, o relay desligado permite que o router fique ligado. Ao acionar o relay, a energia do router eh cortada.
   delay(5000);  // aguarda 5 segundos com o modem desligado
   digitalWrite(9,HIGH);
   
   for(int j=0;j<150;j++) {myGLCD.print(".", j*2, Y);delay(2500);};
//   delay(60*1000*5); // aguarda 5 minutos para o modem inicializar e reconectar, evitando que a rotina o desligue novamente.

   Y+=20;
   while(Ethernet.begin(mac)==0) {Serial.println("Failed to configure Ethernet using DHCP");myGLCD.print("Failed to configure Ethernet using DHCP", LEFT, Y);};

   Y+=20;
   printIP();
}

void Clear()
{
     Y = 20;
     myGLCD.setColor(0, 0, 0);
     myGLCD.setBackColor(0, 0, 0);
     myGLCD.fillRect(0, 20, 319, 240);
     myGLCD.setColor(255, 255, 255);
}


void printIP()
{
   Serial.print("My IP address: ");
   myGLCD.print("My IP address: ", LEFT, Y);
   
   String IP = "";
   for (byte thisByte = 0; thisByte < 4; thisByte++) 
   {
      int ip;
      ip = Ethernet.localIP()[thisByte];
      IP = IP + String(ip) + ".";
   }
   IP = IP.substring(0,IP.length()-1);
   IP = IP + "   ";
   Serial.println(IP);
   myGLCD.print(IP, RIGHT, Y);
   Y+=20;   
}

Schematics

netBoot alternative assembly
wire connections
Netboot schema
Part: 1
1
Part: 2
2
Part: 3
3
Part: 4
4

Comments

Similar projects you might like

Unlock your door with a knock

Project tutorial by Ashraf Nabil

  • 22,829 views
  • 12 comments
  • 60 respects

Universal Remote Control using Arduino, 1Sheeld and Android

Project tutorial by Ashraf Nabil

  • 9,021 views
  • 5 comments
  • 14 respects

ThingSpeak Controlling Arduino with 1Sheeld

by eric

  • 2,362 views
  • 2 comments
  • 4 respects

Using Android Smart Phone to Remote Controller

Project tutorial by Team Makewith

  • 1,987 views
  • 1 comment
  • 6 respects

Control TV Using A Touch Remote

Project tutorial by the lonely programmer

  • 473 views
  • 2 comments
  • 2 respects

Arduino Dynamic Web Control

Project tutorial by phpoc_man

  • 34,757 views
  • 15 comments
  • 117 respects
Add projectSign up / Login