// Library #include #include #include // Watchdog ------------------- #include #include #include // ---------------------------- #define WDTSet 8000 // Solo i seguenti valori in ms: 16 32 64 125 250 500 1000 2000 4000 8000 #define DEBUG true int chkhttp = 10000; // Valore in ms controllo chkhttp int vtchk = 5; // Valore in s loop check controller unsigned long int TWTD; // Timer Watchdog unsigned long int TCHK; // Timer loop check controller // Temporizzazioni unsigned long int VTIME; // Impostazione scheda ethernet byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x97, 0xFA }; // mac address 16 //byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x97, 0xFD }; // mac address 17 byte ip[] = { 192, 168, 2, 16 }; // ip arduino byte gateway[] = { 192, 168, 2, 1 }; // Router byte subnet[] = { 255, 255, 255, 0 }; // Subnet mask EthernetServer server(8016); // Server port byte ws_ip[] = { 192, 168, 2, 8 }; // IP Web server byte cpu_10[] = { 192, 168, 2, 10 }; // IP Controller 10 byte cpu_11[] = { 192, 168, 2, 11 }; // IP Controller 11 byte cpu_12[] = { 192, 168, 2, 12 }; // IP Controller 12 byte cpu_13[] = { 192, 168, 2, 13 }; // IP Controller 13 byte cpu_14[] = { 192, 168, 2, 14 }; // IP Controller 14 byte cpu_15[] = { 192, 168, 2, 15 }; // IP Controller 15 byte cpu_16[] = { 192, 168, 2, 16 }; // IP Controller 16 byte cpu_17[] = { 192, 168, 2, 17 }; // IP Controller 16 String ip_web_server="192.168.2.8"; // Web server String web_server="http://192.168.2.240"; // Web server String web_page; // Pagine http String send_data; // Pagine http String send_data_cdz; // Pagine http String send_data_servo; // Pagine http String send_loop; // Pagine http String readString; String str_light; // Stringa led String chk_page; // Check Page string void setup() { // Inizializzazione Watchdog WDT_off(); WDT_Init(); Ethernet.begin(mac, ip, gateway, subnet); server.begin(); if ( DEBUG == true ) { Serial.begin(9600); Serial.println("Reset controllore 16"); } EthernetClient client; if (client.connect( ws_ip, 80)) { send_data=""; send_data += "GET /security.php?TYP=SYS&STS=START_Microcontrollore_Test..."; client.println(send_data); client.stop(); } TWTD = WDTSet; } void loop() { // -------------------------------------------------------------- // Read millis() controller // -------------------------------------------------------------- VTIME=millis(); // -------------------------------------------------------------- // Reset or overflow millis() // -------------------------------------------------------------- if ( VTIME == 1000 ) { TWTD = millis() + chkhttp; } if ( DEBUG == 1 ) { Serial.println(millis()); } http_control(); // --------------------------------------------------------------------------------- // Controllo ricezione dati http altrimenti restart CPU // --------------------------------------------------------------------------------- if ( VTIME >= TWTD ) { delay(10000); } // --------------------------------------------------------------------------------- // Loop chk Ethernet Shield controllori // --------------------------------------------------------------------------------- if ( VTIME >= TCHK ) { //Chk_controller( cpu_10,8010 ); //Chk_controller( cpu_11,8011 ); //Chk_controller( cpu_12,8012 ); //Chk_controller( cpu_13,8013 ); //Chk_controller( cpu_14,8014 ); //Chk_controller( cpu_15,8015 ); //Chk_controller( cpu_16,8016 ); Chk_controller( cpu_17,8017 ); TCHK = VTIME + ( vtchk * 1000 ); } // --------------------------------------------------------- ResetWatchdog(); // Resetto il watchdog file del loop // --------------------------------------------------------- } // -------------------------------------------------------------- // HTTP client // -------------------------------------------------------------- void http_control() { EthernetClient client = server.available(); // EthernetClient client; if (client) { boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); readString.concat(c); if (c == '\n' && currentLineIsBlank) { if(readString.indexOf("status=1") > 0) { web_page = ""; web_page += "Descrizione : \t\tRegolazione CDZ - Power control \n"; web_page += "IP Controller : \t"; web_page += ip[0]; web_page += "."; web_page += ip[1]; web_page += "."; web_page += ip[2]; web_page += "."; web_page += ip[3]; web_page += "\n"; web_page += "Gateway : \t\t"; web_page += gateway[0]; web_page += "."; web_page += gateway[1]; web_page += "."; web_page += gateway[2]; web_page += "."; web_page += gateway[3]; web_page += "\n"; web_page += "Subnet : \t\t"; web_page += subnet[0]; web_page += "."; web_page += subnet[1]; web_page += "."; web_page += subnet[2]; web_page += "."; web_page += subnet[3]; web_page += "\n"; web_page += "Millis : \t\t"; web_page += millis(); web_page += "\n"; client.print(web_page); } if(readString.indexOf("wait=1") > 0) { web_page = ""; web_page += "Descrizione : \t\tRegolazione CDZ - Power control \n\n\n\n\n"; web_page += "Forzatura attesa 6 sec. per riavvio ..... \t"; client.print(web_page); delay(10000); } if(readString.indexOf("chk=1") > 0) { TWTD = VTIME + chkhttp; web_page = ""; web_page += "IP Controller : \t"; web_page += ip[0]; web_page += "."; web_page += ip[1]; web_page += "."; web_page += ip[2]; web_page += "."; web_page += ip[3]; web_page += "\n"; client.print(web_page); } readString=""; client.stop(); } } } } } void WDT_Init(void) { cli(); // Disable interrupts wdt_reset(); // Reset watchdog WDTCSR = (1<