Connections:
netBoot with a case:
Version 1:
Version 2:
Scheme:
Source code:
#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; }
Yes, it´s an idea... but, I could want to reset two or more devices on the same outlet power strip...