mega2560+w5100+16relay box не могу управлять более 10 реле

dim5555
Offline
Зарегистрирован: 12.01.2019

Добрый вечер. Нужна помощь форума. Имеется Mega2560+w5100+16 relay box (активация низким уровнем).

С 1 по 10 реле отрабатывают как положено, при активации OFF после 10 (допустим 15) отработают 2 и 5 реле, при этом на странице соответственно изменится индикация на 2 и 5 реле (соответственно если 16 - 2 и 6 реле). 

D скетче указано*Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.* , я понимаю, что он подходит до 10 портов включительно. 

#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>


////////////////////////////////////////////////////////////////////////
//CONFIGURATION
////////////////////////////////////////////////////////////////////////

//IP manual settings
byte ip[] = { 
  192, 168, 1, 110 };   //Manual setup only


// if need to change the MAC address (Very Rare)
byte mac[] = { 
  0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

//Ethernet Port
EthernetServer server = EthernetServer(80); //default html port 80

//The number of outputs going to be switched.
int outputQuantity = 16;  //should not exceed 10???

//Invert the output of the leds
boolean outputInverted = true; //true or false
// This is done in case the relay board triggers the relay on negative, rather then on positive supply

//Html page refresh
int refreshPage = 15; //default is 10sec. 
//Beware that if you make it refresh too fast, the page could become inacessable.

//Display or hide the "Switch on all Pins" buttons at the bottom of page
int switchOnAllPinsButton = false; //true or false

//Button Array
//Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.

// Select the pinout address
int outputAddress[16] = { 22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37}; //Allocate 10??? spaces and name the output pin address.
//PS pin addresses 10, 11, 12 and 13 on the Duemilanove are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 10, 50, 51 and 52 and 53 on the Mega are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 4, are used for the SD card, therefore cannot be used.
//PS. pin address 2 is used for interrupt-driven notification, therefore could not be used.

// Write the text description of the output channel
String buttonText[16] = {
  "РЕЛЕ 1","РЕЛЕ 2","РЕЛЕ 3","РЕЛЕ 4","РЕЛЕ 5","РЕЛЕ 6","РЕЛЕ 7","РЕЛЕ 8","РЕЛЕ 9","РЕЛЕ 10","РЕЛЕ 11","РЕЛЕ 12","РЕЛЕ 13","РЕЛЕ 14","РЕЛЕ 15","РЕЛЕ 16"};

// Set the output to retain the last status after power recycle.
int retainOutputStatus[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//1-retain the last status. 0-will be off after power cut.

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
//VARIABLES DECLARATION
////////////////////////////////////////////////////////////////////////
int outp = 0;
boolean printLastCommandOnce = false;
boolean printButtonMenuOnce = false;
boolean initialPrint = true;
String allOn = "";
String allOff = "";
boolean reading = false;
boolean outputStatus[16]; //Create a boolean array for the maximum ammount.
unsigned long timeConnectedAt;
boolean writeToEeprom = false;
EthernetClient client;



////////////////////////////////////////////////////////////////////////
//RUN ONCE
////////////////////////////////////////////////////////////////////////
//Beginning of Program
void setup(){
  Serial.begin(9600);

  initEepromValues();
  readEepromValues();

  //Set pins as Outputs 
  boolean currentState = false;
  for (int var = 0; var < outputQuantity; var++){

    pinMode(outputAddress[var], OUTPUT);       

    //Switch all outputs to either on or off on Startup
    if(outputInverted == true) {
      //digitalWrite(outputAddress[var], HIGH);
      if(outputStatus[var] == 0){currentState = true;}else{currentState = false;} //check outputStatus if off, switch output accordingly
      digitalWrite(outputAddress[var], currentState);
      
    }
    else{
      
      //digitalWrite(outputAddress[var], LOW);
      if(outputStatus[var] == 0){currentState = false;}else{currentState = true;}//check outputStatus if off, switch output accordingly
      digitalWrite(outputAddress[var], currentState);
    }

  }

  //Setting up the IP address. Comment out the one you dont need.
  //Ethernet.begin(mac); //for DHCP address. (Address will be printed to serial.)
  Ethernet.begin(mac, ip); //for manual setup. (Address is the one configured above.)


  server.begin();
  Serial.print("Server started at ");
  Serial.println(Ethernet.localIP());
}


////////////////////////////////////////////////////////////////////////
//LOOP
////////////////////////////////////////////////////////////////////////
//Run once
void loop(){


  // listen for incoming clients, and process requests.
  checkForClient();
}

////////////////////////////////////////////////////////////////////////
//checkForClient Function
////////////////////////////////////////////////////////////////////////
//
void checkForClient(){

  EthernetClient client = server.available();

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {

        //if header was not set send it
        
         //read user input
        char c = client.read();
        
          if(c == '*'){

          printHtmlHeader(client); //call for html header and css
          printLoginTitle(client);
          printHtmlFooter(client);
          //sentHeader = true;
          break;
        }
        
        if(!sentHeader){
          
            printHtmlHeader(client); //call for html header and css
           // printHtmlButtonTitle(client); //print the button title
            
          //This is for the arduino to construct the page on the fly. 
          sentHeader = true;
        }

        //read user input
    //    char c = client.read();

        //if there was reading but is blank there was no reading
        if(reading && c == ' '){
          reading = false;
        }

        //if there is a ? there was user input
        if(c == '?') {
          reading = true; //found the ?, begin reading the info
        }

       // if there was user input switch the relevant output
        if(reading){
          
          //if user input is H set output to 1
          if(c == 'H') {
            outp = 1;
          }
          
          //if user input is L set output to 0
          if(c == 'L') {
            outp = 0;
          }
          
          Serial.print(c);   //print the value of c to serial communication
          //Serial.print(outp);
          //Serial.print('\n');

          switch (c) {

             case '0':
               //add code here to trigger on 0
               triggerPin(outputAddress[0], client, outp);
               break;            
             case '1':
               //add code here to trigger on 1
               triggerPin(outputAddress[1], client, outp);
               break;             
             case '2':
               //add code here to trigger on 2
               triggerPin(outputAddress[2], client, outp);
               break;
             case '3':
               //add code here to trigger on 3
               triggerPin(outputAddress[3], client, outp);
               break;
             case '4':
               //add code here to trigger on 4
               triggerPin(outputAddress[4], client, outp);
               break;
             case '5':
               //add code here to trigger on 5
               triggerPin(outputAddress[5], client, outp);
               //printHtml(client);
               break;
             case '6':
               //add code here to trigger on 6
               triggerPin(outputAddress[6], client, outp);
               break;
             case '7':
               //add code here to trigger on 7
               triggerPin(outputAddress[7], client, outp);
               break;
             case '8':
               //add code here to trigger on 8
               triggerPin(outputAddress[8], client, outp);
               break;
             case '9':
               //add code here to trigger on 9
               triggerPin(outputAddress[9], client, outp);
               break;
             case '10':
               //add code here to trigger on 10
               triggerPin(outputAddress[10], client, outp);
               break;            
             case '11':
               //add code here to trigger on 11
               triggerPin(outputAddress[11], client, outp);
               break;             
             case '12':
               //add code here to trigger on 1
               triggerPin(outputAddress[12], client, outp);
               break;
             case '13':
               //add code here to trigger on 13
               triggerPin(outputAddress[13], client, outp);
               break;
             case '14':
               //add code here to trigger on 14
               triggerPin(outputAddress[14], client, outp);
               break;
             case '15':
               //add code here to trigger on 15
               triggerPin(outputAddress[15], client, outp);
               //printHtml(client);
               break;

          } //end of switch case

        }//end of switch switch the relevant output 

        //if user input was blank
        if (c == '\n' && currentLineIsBlank){
          printLastCommandOnce = true;
          printButtonMenuOnce = true;
          triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
          break;
        }
        


        
      }
    }
    
    printHtmlFooter(client); //Prints the html footer
 
  } 
else
   {  //if there is no client
  
      //And time of last page was served is more then a minute.
      if (millis() > (timeConnectedAt + 60000)){           

             if (writeToEeprom == true){ 
                 writeEepromValues();  //write to EEprom the current output statuses
                 Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");
                 writeToEeprom = false;
             }
             
      }
   }


}


////////////////////////////////////////////////////////////////////////
//triggerPin Function
////////////////////////////////////////////////////////////////////////
//
void triggerPin(int pin, EthernetClient client, int outp){
  //Switching on or off outputs, reads the outputs and prints the buttons   

  //Setting Outputs
  if (pin != 777){ 

    if(outp == 1) {
      if (outputInverted ==false){ 
        digitalWrite(pin, HIGH);
      } 
      else{
        digitalWrite(pin, LOW);
      }
    }
    if(outp == 0){
      if (outputInverted ==false){ 
        digitalWrite(pin, LOW);
      } 
      else{
        digitalWrite(pin, HIGH);
      }
    }


  }
  //Refresh the reading of outputs
  readOutputStatuses();


  //Prints the buttons
  if (printButtonMenuOnce == true){
    printHtmlButtons(client);
    printButtonMenuOnce = false;
  }

}

////////////////////////////////////////////////////////////////////////
//printHtmlButtons Function
////////////////////////////////////////////////////////////////////////
//print the html buttons to switch on/off channels
void printHtmlButtons(EthernetClient client){

  //Start to create the html table
  client.println("");
  //client.println("<p>");
  client.println("<FORM>");
  client.println("<table border=\"0\" align=\"left\">");


  


  //Start printing button by button
  for (int var = 0; var < outputQuantity; var++)  {      

    //set command for all on/off
    allOn += "H";
    allOn += outputAddress[var];
    allOff += "L";
    allOff += outputAddress[var];


    //Print begining of row
    client.print("<tr>\n");    
//текст кнопок
    //Prints the button Text
    client.print("<td><h2>");
    client.print(buttonText[var]);
    client.print("</h2></td>\n");

    //Prints the ON Buttons
    client.print("<td>");
    //client.print(buttonText[var]);
    client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
    //client.print(buttonText[var]);
    client.print("\" onClick=\"parent.location='/?H");
    client.print(var);
    client.print("'\"></td>\n");

    //Prints the OFF Buttons 
    client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
    //client.print(var);
    client.print("\" onClick=\"parent.location='/?L");
    client.print(var);
    client.print("'\"></td>\n");


    //Print first part of the Circles or the LEDs

    //Invert the LED display if output is inverted.

    if (outputStatus[var] == true ){                                                            //If Output is ON
      if (outputInverted == false){                                                             //and if output is not inverted 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED
      }
      else{                                                                                    //else output is inverted then
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
    }
    else                                                                                      //If Output is Off
    {
      if (outputInverted == false){                                                           //and if output is not inverted
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
      else{                                                                                   //else output is inverted then 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED                    
      }
    }  




    //Print end of row
    client.print("</tr>\n");  
  }

  //Display or hide the Print all on Pins Button
  if (switchOnAllPinsButton == true ){

    //Prints the ON All Pins Button
    client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOn);
    client.print("'\"></td>\n");

    //Prints the OFF All Pins Button            
    client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOff);
    client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
  }

  //Closing the table and form
  client.println("</table>");
  client.println("</FORM>");
  //client.println("</p>"); 

}

////////////////////////////////////////////////////////////////////////
//readOutputStatuses Function
////////////////////////////////////////////////////////////////////////
//Reading the Output Statuses
void readOutputStatuses(){
  for (int var = 0; var < outputQuantity; var++)  { 
    outputStatus[var] = digitalRead(outputAddress[var]);
    //Serial.print(outputStatus[var]);
  }

}

////////////////////////////////////////////////////////////////////////
//readEepromValues Function
////////////////////////////////////////////////////////////////////////
//Read EEprom values and save to outputStatus
void readEepromValues(){
    for (int adr = 0; adr < outputQuantity; adr++)  { 
    outputStatus[adr] = EEPROM.read(adr); 
    }
}

////////////////////////////////////////////////////////////////////////
//writeEepromValues Function
////////////////////////////////////////////////////////////////////////
//Write EEprom values
void writeEepromValues(){
    for (int adr = 0; adr < outputQuantity; adr++)  { 
    EEPROM.write(adr, outputStatus[adr]);
    }

} 

////////////////////////////////////////////////////////////////////////
//initEepromValues Function
////////////////////////////////////////////////////////////////////////
//Initialiaze EEprom values
//if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0
void initEepromValues(){
      for (int adr = 0; adr < outputQuantity; adr++){        
         if (EEPROM.read(adr) > 1){
                EEPROM.write(adr, 0);
         } 
 
      }
  
}


////////////////////////////////////////////////////////////////////////
//htmlHeader Function
////////////////////////////////////////////////////////////////////////
//Prints html header
 void printHtmlHeader(EthernetClient client){
          Serial.print("Serving html Headers at ms -");
          timeConnectedAt = millis(); //Record the time when last page was served.
          Serial.print(timeConnectedAt); // Print time for debbugging purposes
          writeToEeprom = true; // page loaded so set to action the write to eeprom
          
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html;charset=UTF-8");//"Content-Type: text/html;charset=UTF-8"
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<head>");

          // add page title 
          client.println("<title>Удаленное управление</title>");
          client.println("<meta name=\"description\" content=\"Удаленное управление\"/>");
/*
//перзагрузка страницы,рефреш
          // add a meta refresh tag, so the browser pulls again every x seconds:
          client.print("<meta http-equiv=\"refresh\" content=\"");
          client.print(refreshPage);
          client.println("; url=/\">");
*/
          // add other browser configuration
          client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
          client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");
          client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");          

          //inserting the styles data, usually found in CSS files.
          client.println("<style type=\"text/css\">");
          client.println("");

          //This will set how the page will look graphically
          client.println("html { height:100%; }");  

          client.println("  body {");
          client.println("    height: 100%;");
          client.println("    margin: 0;");
          client.println("    font-family: helvetica, sans-serif;");
          client.println("    -webkit-text-size-adjust: none;");
          client.println("   }");
          client.println("");
          client.println("body {");
          client.println("    -webkit-background-size: 100% 21px;");
          client.println("    background-color: #c5ccd3;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, right top,");
          client.println("    color-stop(.75, transparent),");
          client.println("    color-stop(.75, rgba(255,255,255,.1)) );");
          client.println("    -webkit-background-size: 7px;");
          client.println("   }");
          client.println("");
          client.println(".view {");
          client.println("    min-height: 100%;");
          client.println("    overflow: auto;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper {");
          client.println("    height: 44px;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");
          client.println("    border-top: solid 1px rgba(255,255,255,0.6);");
          client.println("    border-bottom: solid 1px rgba(0,0,0,0.6);");
          client.println("    color: #fff;");
          client.println("    background-color: #8195af;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(rgba(255,255,255,.4)),");
          client.println("    to(rgba(255,255,255,.05)) ),");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(transparent),");
          client.println("    to(rgba(0,0,64,.1)) );");
          client.println("    background-repeat: no-repeat;");
          client.println("    background-position: top left, bottom left;");
          client.println("    -webkit-background-size: 100% 21px, 100% 22px;");
          client.println("    -webkit-box-sizing: border-box;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper h1 {");
          client.println("    text-align: center;");
          client.println("    font-size: 20px;");
          client.println("    line-height: 44px;");
          client.println("    margin: 0;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper {");
          client.println("    margin: 9px;");
          client.println("    }");
          client.println("");
          client.println(".group-wrapper h2 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 17px;");
          client.println("    line-height: 0.8;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h3 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 12px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h4 {");  //Text for description
          client.println("    color: #212121;");
          client.println("    font-size: 14px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #aaa 1px 1px 3px;");
          client.println("    margin: 5px 5px 5px;");
          client.println("   }");
          client.println(""); 
          client.println(".group-wrapper table {");
          client.println("    background-color: #fff;");
          client.println("    -webkit-border-radius: 10px;");

          client.println("    -moz-border-radius: 10px;");
          client.println("    -khtml-border-radius: 10px;");
          client.println("    border-radius: 10px;");


          client.println("    font-size: 20px;");
          client.println("    line-height: 20px;");
          client.println("    margin: 9px 0 20px;");
          client.println("    border: solid 1px #a9abae;");
          client.println("    padding: 11px 3px 12px 3px;");
          client.println("    margin-left:auto;");
          client.println("    margin-right:auto;");

          client.println("    -moz-transform :scale(1);"); //Code for Mozilla Firefox
          client.println("    -moz-transform-origin: 0 0;");



          client.println("   }");
          client.println("");


          //how the green (ON) LED will look
          client.println(".green-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #0f0;");
          //client.println("    background-color: rgba(60, 132, 198, 0.8);");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");

          client.println("    background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");
          client.println("    border: 2px solid #ccc;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

          client.println("    }");
          client.println("");

          //how the black (off)LED will look
          client.println(".black-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #040;");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */"); 
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    }");
          client.println("");

          //this will add the glare to both of the LEDs
          client.println("   .glare {");
          client.println("      position: relative;");
          client.println("      top: 1;");
          client.println("      left: 5px;");
          client.println("      -webkit-border-radius: 10px;");
          client.println("      -moz-border-radius: 10px;");
          client.println("      -khtml-border-radius: 10px;");
          client.println("      border-radius: 10px;");
          client.println("      height: 1px;");
          client.println("      width: 13px;");
          client.println("      padding: 5px 0;");
          client.println("      background-color: rgba(200, 200, 200, 0.25);");
          client.println("      background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");
          client.println("    }");
          client.println("");


          //and finally this is the end of the style data and header
          client.println("</style>");
          client.println("</head>");

          //now printing the page itself
          client.println("<body>");
          client.println("<div class=\"view\">");
          client.println("    <div class=\"header-wrapper\">");
          client.println("      <h1>Умный дом</h1>");
          client.println("    </div>");

//////

 } //end of htmlHeader

////////////////////////////////////////////////////////////////////////
//htmlFooter Function
////////////////////////////////////////////////////////////////////////
//Prints html footer
void printHtmlFooter(EthernetClient client){
    //Set Variables Before Exiting 
    printLastCommandOnce = false;
    printButtonMenuOnce = false;
    allOn = "";
    allOff = "";
    /*client.println("\n</div>\n</body>\n</html>");
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
    */
    
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
   
 } //end of htmlFooter


////////////////////////////////////////////////////////////////////////
//printHtmlButtonTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title
void printHtmlButtonTitle(EthernetClient client){
          client.println("<div  class=\"group-wrapper\">");
          client.println();
}



////////////////////////////////////////////////////////////////////////
//printLoginTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title

void printLoginTitle(EthernetClient client){
         client.println("<div  class=\"group-wrapper\">");
          client.println("    <h2>Please enter the user data to login.</h2>");
          client.println();
}

если я правильно понимаю нужный мне алгоритм в строке

//Set pins as Outputs 
  boolean currentState = false;
  for (int var = 0; var < outputQuantity; var++){
 
Пробовал вести отсчет var = -6, результата нет.
Подскажите как расширить диапазон 0-9 до 0-15?
asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Ну и правильно, что не работает

char c = client.read();
...
switch (c) {

case '10': 

Надо посылающую часть переделывать что бы для десятог реле посылала 'A', 11го 'B' итд. А в скетче заменить '10' на 'A', '11' на 'B' и далее

dim5555
Offline
Зарегистрирован: 12.01.2019

asam пишет:

Ну и правильно, что не работает

char c = client.read();
...
switch (c) {

case '10': 

Надо посылающую часть переделывать что бы для десятог реле посылала 'A', 11го 'B' итд. А в скетче заменить '10' на 'A', '11' на 'B' и далее

можно поподробнее про переделку посылающей части?

нужно каждый порт прописать - типа порт 10 = a,

порт 11 = b  и так далее, может есть какие нибудь примеры?

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Как я могу привести пример если понятия не имею что там у вас на другом конце? Вы уж там сами разбирайтесь. Направление я указал.

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

dim5555, при таком определении номера канала, как у Вас, этот номер должен кодироваться единственным символом. Символов '10', '11' и т.д. не бывает - это двухсимвольные последовательности, из которых Си, согласно стандарту, берет только первый символ. Т.е. у Вас определено 7 веток '1'.

asam Вам правильно советует: самый простой путь - заменить все двухсимвольные последовательности. которые Вы сами вставили в код, на одиночные символы. Какие символы использовать - Вам решать. 

Взаимно согласованные изменения, естественно, нужны как в приемной, так и в передающей частях.

dim5555
Offline
Зарегистрирован: 12.01.2019

вроде все изменил, но теперь появилась ошибка *exit status 1

'readString' was not declared in this scope*
 
уже голова болит ,всю ночь просидел возле компа..
посмотрите пожалуйста
#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>


////////////////////////////////////////////////////////////////////////
//CONFIGURATION
////////////////////////////////////////////////////////////////////////

//IP manual settings
byte ip[] = { 
  192, 168, 1, 110 };   //Manual setup only


// if need to change the MAC address (Very Rare)
byte mac[] = { 
  0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

//Ethernet Port
EthernetServer server = EthernetServer(80); //default html port 80

//The number of outputs going to be switched.
int outputQuantity = 16;  //should not exceed 10???

//Invert the output of the leds
boolean outputInverted = true; //true or false
// This is done in case the relay board triggers the relay on negative, rather then on positive supply

//Html page refresh
int refreshPage = 15; //default is 10sec. 
//Beware that if you make it refresh too fast, the page could become inacessable.

//Display or hide the "Switch on all Pins" buttons at the bottom of page
int switchOnAllPinsButton = false; //true or false

//Button Array
//Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.

// Select the pinout address
byte outputAddress[8] = {
  22,23,24,25,26,27,28,29}; //Allocate 10 spaces and name the output pin address.
byte outputAddress2[8]= {
  30,31,32,33,34,35,36,37};
//PS pin addresses 10, 11, 12 and 13 on the Duemilanove are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 10, 50, 51 and 52 and 53 on the Mega are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 4, are used for the SD card, therefore cannot be used.
//PS. pin address 2 is used for interrupt-driven notification, therefore could not be used.

// Write the text description of the output channel
String buttonText[16] = {
  "РЕЛЕ 1","РЕЛЕ 2","РЕЛЕ 3","РЕЛЕ 4","РЕЛЕ 5","РЕЛЕ 6","РЕЛЕ 7","РЕЛЕ 8","РЕЛЕ 9","РЕЛЕ 10","РЕЛЕ 11","РЕЛЕ 12","РЕЛЕ 13","РЕЛЕ 14","РЕЛЕ 15","РЕЛЕ 16"};

// Set the output to retain the last status after power recycle.
int retainOutputStatus[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//1-retain the last status. 0-will be off after power cut.

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
//VARIABLES DECLARATION
////////////////////////////////////////////////////////////////////////

int outp = 0;
boolean printLastCommandOnce = false;
boolean printButtonMenuOnce = false;
boolean initialPrint = true;
String allOn = "";
String allOff = "";
boolean reading = false;
boolean outputStatus[8]; //Create a boolean array for the maximum ammount.
boolean outputStatus2[8]; // relays 9-16
unsigned long timeConnectedAt;
boolean writeToEeprom = false;
EthernetClient client;


////////////////////////////////////////////////////////////////////////
//RUN ONCE
////////////////////////////////////////////////////////////////////////
//Beginning of Program
void setup(){
  Serial.begin(9600);

  //initEepromValues();
  //readEepromValues();

  //Set pins as Outputs 
  boolean currentState = false;
  for (int var = 0; var < 9; var++){
    digitalWrite(outputAddress[var], HIGH);
    pinMode(outputAddress[var], OUTPUT); 

  }
  for (int var2 = 0; var2 < 9; var2++){

    pinMode(outputAddress2[var2], OUTPUT); 
    digitalWrite(outputAddress2[var2], HIGH);
  }



  Ethernet.begin(mac, ip); //for manual setup. (Address is the one configured above.)


  server.begin();
  Serial.print("Server started at ");
  Serial.println(Ethernet.localIP());
  
}


////////////////////////////////////////////////////////////////////////
//LOOP
////////////////////////////////////////////////////////////////////////
//Run once
void loop(){


  // listen for incoming clients, and process requests.
  checkForClient();
}


////////////////////////////////////////////////////////////////////////
//checkForClient Function
////////////////////////////////////////////////////////////////////////
//
void checkForClient(){

  EthernetClient client = server.available();

 // if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;
    
    while (client.connected()) {
      if (client.available()) {
        //if header was not set send it

        //read user input
       char c = client.read();
        Serial.println(c);
        readString.concat(c);
        if(c == '*'){

          printHtmlHeader(client); //call for html header and css
          printLoginTitle(client);
          printHtmlFooter(client);
          //sentHeader = true;
          break;
        }

        if(!sentHeader){

         printHtmlHeader(client); //call for html header and css
         

          //This is for the arduino to construct the page on the fly. 
          sentHeader = true;
        }

        //read user input
    //    char c = client.read();

        //if there was reading but is blank there was no reading
        if(reading && c == ' '){
          reading = false;
        }

        //if there is a ? there was user input
        if(c == '?') {
          reading = true; //found the ?, begin reading the info
        }

        // if there was user input switch the relevant output
        if(reading){

          //if user input is H set output to 1
          if(c == 'H') {
            outp = 1;
          }

          //if user input is L set output to 0
          if(c == 'L') {
            outp = 0;
          }


          Serial.print(c);   //print the value of c to serial communication
          //Serial.print(outp);
          //Serial.print('\n');

          switch (c) {

          case '0':
            //add code here to trigger on 0
            triggerPin(outputAddress[0], client, outp);
            break;            
          case '1':
            //add code here to trigger on 1
            triggerPin(outputAddress[1], client, outp);
            break;             
          case '2':
            //add code here to trigger on 2
            triggerPin(outputAddress[2], client, outp);
            break;
          case '3':
            //add code here to trigger on 3
            triggerPin(outputAddress[3], client, outp);
            break;
          case '4':
            //add code here to trigger on 4
            triggerPin(outputAddress[4], client, outp);
            break;
          case '5':
            //add code here to trigger on 5
            triggerPin(outputAddress[5], client, outp);
            //  printHtml(client);
            break;
          case '6':
            //add code here to trigger on 6
            triggerPin(outputAddress[6], client, outp);
            break;
          case '7':
            //add code here to trigger on 7
            triggerPin(outputAddress[7], client, outp);
            break;
          case '8':
            //add code here to trigger on 8
            triggerPin(outputAddress[8], client, outp);
            break;
          case '9':
            // add code here to trigger on 9
            triggerPin(outputAddress[9], client, outp);
            break;
          case 'A':
            triggerPin(outputAddress[10], client, outp);
            break;
          case 'B':
            triggerPin(outputAddress[11], client, outp);
            break;
          case 'C':
            triggerPin(outputAddress[12], client, outp);
            break;
          case 'D':
            triggerPin(outputAddress[13], client, outp);
            break;
          case 'F':
            triggerPin(outputAddress[15], client, outp);
            break;
          case 'Logout':
            login=false;
            readString="";
            break;

          } //end of switch case

        }//end of switch switch the relevant output 

        //if user input was blank
        if (c == '\n' && currentLineIsBlank){
          printLastCommandOnce = true;
          printButtonMenuOnce = true;
          triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
          break;
        }
        


        
      }
    }
    
    printHtmlFooter(client); //Prints the html footer
 
  } 
 else
   {  //if there is no client
  
      //And time of last page was served is more then a minute.
      if (millis() > (timeConnectedAt + 60000)){           

             if (writeToEeprom == true){ 
                 writeEepromValues();  //write to EEprom the current output statuses
                 Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");
                 writeToEeprom = false;
             }
             
      }
   }


}


////////////////////////////////////////////////////////////////////////
//triggerPin Function
////////////////////////////////////////////////////////////////////////
//
void triggerPin(int pin, EthernetClient client, int outp){
  //Switching on or off outputs, reads the outputs and prints the buttons   

  //Setting Outputs
  if (pin != 777){ 

    if(outp == 1) {
      if (outputInverted ==false){ 
        digitalWrite(pin, HIGH);
      } 
      else{
        digitalWrite(pin, LOW);
      }
    }
    if(outp == 0){
      if (outputInverted ==false){ 
        digitalWrite(pin, LOW);
      } 
      else{
        digitalWrite(pin, HIGH);
      }
    }
  }
  //Refresh the reading of outputs
  readOutputStatuses();


  //Prints the buttons
  if (printButtonMenuOnce == true){
    printHtmlButtons(client);
    printButtonMenuOnce = false;
  }

}

////////////////////////////////////////////////////////////////////////
//printHtmlButtons Function
////////////////////////////////////////////////////////////////////////
//print the html buttons to switch on/off channels
void printHtmlButtons(EthernetClient client){

  //Start to create the html table
  client.println("");
  //client.println("<p>");
  client.println("<FORM>");
  client.println("<table border=\"0\" align=\"left\">");


  


  //Start printing button by button
  for (int var = 0; var < outputQuantity; var++)  {      

    //set command for all on/off
    allOn += "H";
    allOn += outputAddress[var];
    allOff += "L";
    allOff += outputAddress[var];


    //Print begining of row
    client.print("<tr>\n");    
//текст кнопок
    //Prints the button Text
    client.print("<td><h2>");
    client.print(buttonText[var]);
    client.print("</h2></td>\n");

    //Prints the ON Buttons
    client.print("<td>");
    //client.print(buttonText[var]);
    client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
    //client.print(buttonText[var]);
    client.print("\" onClick=\"parent.location='/?H");
    client.print(var);
    client.print("'\"></td>\n");

    //Prints the OFF Buttons 
    client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
    //client.print(var);
    client.print("\" onClick=\"parent.location='/?L");
    client.print(var);
    client.print("'\"></td>\n");


    //Print first part of the Circles or the LEDs

    //Invert the LED display if output is inverted.

    if (outputStatus[var] == true ){                                                            //If Output is ON
      if (outputInverted == false){                                                             //and if output is not inverted 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED
      }
      else{                                                                                    //else output is inverted then
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
    }
    else                                                                                      //If Output is Off
    {
      if (outputInverted == false){                                                           //and if output is not inverted
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
      else{                                                                                   //else output is inverted then 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED                    
      }
    }  




    //Print end of row
    client.print("</tr>\n");  
  }

  //Display or hide the Print all on Pins Button
  if (switchOnAllPinsButton == true ){

    //Prints the ON All Pins Button
    client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOn);
    client.print("'\"></td>\n");

    //Prints the OFF All Pins Button            
    client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOff);
    client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
  }

  //Closing the table and form
  client.println("</table>");
  client.println("</FORM>");
  //client.println("</p>"); 

}

////////////////////////////////////////////////////////////////////////
//readOutputStatuses Function
////////////////////////////////////////////////////////////////////////
//Reading the Output Statuses
void readOutputStatuses(){
  for (int var = 0; var < outputQuantity; var++)  { 
    outputStatus[var] = digitalRead(outputAddress[var]);
    outputStatus2[var] = digitalRead(outputAddress2[var]);
    //Serial.print(outputStatus[var]);
 

   }

}

////////////////////////////////////////////////////////////////////////
//readEepromValues Function
////////////////////////////////////////////////////////////////////////
//Read EEprom values and save to outputStatus
void readEepromValues(){
  for (int adr = 0; adr < outputQuantity; adr++)  { 
    outputStatus[adr] = EEPROM.read(adr); 
  }
}

////////////////////////////////////////////////////////////////////////
//writeEepromValues Function
////////////////////////////////////////////////////////////////////////
//Write EEprom values
void writeEepromValues(){
  for (int adr = 0; adr < outputQuantity; adr++)  { 
    EEPROM.write(adr, outputStatus[adr]);
  }

} 

////////////////////////////////////////////////////////////////////////
//initEepromValues Function
////////////////////////////////////////////////////////////////////////
//Initialiaze EEprom values
//if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0
void initEepromValues(){
      for (int adr = 0; adr < outputQuantity; adr++){        
         if (EEPROM.read(adr) > 1){
                EEPROM.write(adr, 0);
    } 

  }

}


////////////////////////////////////////////////////////////////////////
//htmlHeader Function
////////////////////////////////////////////////////////////////////////
//Prints html header
 void printHtmlHeader(EthernetClient client){
          Serial.print("Serving html Headers at ms -");
          timeConnectedAt = millis(); //Record the time when last page was served.
          Serial.print(timeConnectedAt); // Print time for debbugging purposes
          writeToEeprom = true; // page loaded so set to action the write to eeprom
          
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html;charset=UTF-8");//"Content-Type: text/html;charset=UTF-8"
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<head>");

          // add page title 
          client.println("<title>Удаленное управление</title>");
          client.println("<meta name=\"description\" content=\"Удаленное управление\"/>");
/*
//перзагрузка страницы,рефреш
          // add a meta refresh tag, so the browser pulls again every x seconds:
          client.print("<meta http-equiv=\"refresh\" content=\"");
          client.print(refreshPage);
          client.println("; url=/\">");
*/
          // add other browser configuration
          client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
          client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");
          client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");          

          //inserting the styles data, usually found in CSS files.
          client.println("<style type=\"text/css\">");
          client.println("");

          //This will set how the page will look graphically
          client.println("html { height:100%; }");  

          client.println("  body {");
          client.println("    height: 100%;");
          client.println("    margin: 0;");
          client.println("    font-family: helvetica, sans-serif;");
          client.println("    -webkit-text-size-adjust: none;");
          client.println("   }");
          client.println("");
          client.println("body {");
          client.println("    -webkit-background-size: 100% 21px;");
          client.println("    background-color: #c5ccd3;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, right top,");
          client.println("    color-stop(.75, transparent),");
          client.println("    color-stop(.75, rgba(255,255,255,.1)) );");
          client.println("    -webkit-background-size: 7px;");
          client.println("   }");
          client.println("");
          client.println(".view {");
          client.println("    min-height: 100%;");
          client.println("    overflow: auto;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper {");
          client.println("    height: 44px;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");
          client.println("    border-top: solid 1px rgba(255,255,255,0.6);");
          client.println("    border-bottom: solid 1px rgba(0,0,0,0.6);");
          client.println("    color: #fff;");
          client.println("    background-color: #8195af;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(rgba(255,255,255,.4)),");
          client.println("    to(rgba(255,255,255,.05)) ),");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(transparent),");
          client.println("    to(rgba(0,0,64,.1)) );");
          client.println("    background-repeat: no-repeat;");
          client.println("    background-position: top left, bottom left;");
          client.println("    -webkit-background-size: 100% 21px, 100% 22px;");
          client.println("    -webkit-box-sizing: border-box;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper h1 {");
          client.println("    text-align: center;");
          client.println("    font-size: 20px;");
          client.println("    line-height: 44px;");
          client.println("    margin: 0;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper {");
          client.println("    margin: 9px;");
          client.println("    }");
          client.println("");
          client.println(".group-wrapper h2 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 17px;");
          client.println("    line-height: 0.8;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h3 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 12px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h4 {");  //Text for description
          client.println("    color: #212121;");
          client.println("    font-size: 14px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #aaa 1px 1px 3px;");
          client.println("    margin: 5px 5px 5px;");
          client.println("   }");
          client.println(""); 
          client.println(".group-wrapper table {");
          client.println("    background-color: #fff;");
          client.println("    -webkit-border-radius: 10px;");

          client.println("    -moz-border-radius: 10px;");
          client.println("    -khtml-border-radius: 10px;");
          client.println("    border-radius: 10px;");


          client.println("    font-size: 20px;");
          client.println("    line-height: 20px;");
          client.println("    margin: 9px 0 20px;");
          client.println("    border: solid 1px #a9abae;");
          client.println("    padding: 11px 3px 12px 3px;");
          client.println("    margin-left:auto;");
          client.println("    margin-right:auto;");

          client.println("    -moz-transform :scale(1);"); //Code for Mozilla Firefox
          client.println("    -moz-transform-origin: 0 0;");



          client.println("   }");
          client.println("");


          //how the green (ON) LED will look
          client.println(".green-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #0f0;");
          //client.println("    background-color: rgba(60, 132, 198, 0.8);");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");

          client.println("    background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");
          client.println("    border: 2px solid #ccc;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

          client.println("    }");
          client.println("");

          //how the black (off)LED will look
          client.println(".black-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #040;");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */"); 
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    }");
          client.println("");

          //this will add the glare to both of the LEDs
          client.println("   .glare {");
          client.println("      position: relative;");
          client.println("      top: 1;");
          client.println("      left: 5px;");
          client.println("      -webkit-border-radius: 10px;");
          client.println("      -moz-border-radius: 10px;");
          client.println("      -khtml-border-radius: 10px;");
          client.println("      border-radius: 10px;");
          client.println("      height: 1px;");
          client.println("      width: 13px;");
          client.println("      padding: 5px 0;");
          client.println("      background-color: rgba(200, 200, 200, 0.25);");
          client.println("      background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");
          client.println("    }");
          client.println("");


          //and finally this is the end of the style data and header
          client.println("</style>");
          client.println("</head>");

          //now printing the page itself
          client.println("<body>");
          client.println("<div class=\"view\">");
          client.println("    <div class=\"header-wrapper\">");
          client.println("      <h1>Умный дом</h1>");
          client.println("    </div>");

//////

 } //end of htmlHeader

////////////////////////////////////////////////////////////////////////
//htmlFooter Function
////////////////////////////////////////////////////////////////////////
//Prints html footer
void printHtmlFooter(EthernetClient client){
    //Set Variables Before Exiting 
    printLastCommandOnce = false;
    printButtonMenuOnce = false;
    allOn = "";
    allOff = "";
    /*client.println("\n</div>\n</body>\n</html>");
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
    */
    
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
   
 } //end of htmlFooter


////////////////////////////////////////////////////////////////////////
//printHtmlButtonTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title
void printHtmlButtonTitle(EthernetClient client){
  client.println("<div  class=\"group-wrapper\">");
  client.println();
}


////////////////////////////////////////////////////////////////////////
//printLoginTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title

void printLoginTitle(EthernetClient client){
         client.println("<div  class=\"group-wrapper\">");
          client.println("    <h2>Please enter the user data to login.</h2>");
          client.println();
}

 

 

b707
Offline
Зарегистрирован: 26.05.2017

dim5555 пишет:

вроде все изменил, но теперь появилась ошибка *exit status 1

'readString' was not declared in this scope*

 

Dim, на будущее - указывайте весь текст ошибки. Думаете так интересно просматривать ваши сотни строк кода. чтобы найти, где у вас readString ? - в ошибке указан номер строки

Если правильно нашел, это строка 144. Насколько я вижу, в новом коде она вообще лишняя. попробуйте ее просто закомментировать

dim5555
Offline
Зарегистрирован: 12.01.2019

поправил код,

куча ошибок..

Arduino: 1.8.5 (Windows 7), Плата:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
 
C:\Users\admin\AppData\Local\Temp\arduino_modified_sketch_377729\sketch_jan12a.ino: In function 'void checkForClient()':
 
sketch_jan12a:147: error: 'printHtmlHeader' was not declared in this scope
 
           printHtmlHeader(client); //call for html header and css
 
                                 ^
 
sketch_jan12a:148: error: 'printHtmlFooter' was not declared in this scope
 
           printHtmlFooter(client);
 
                                 ^
 
sketch_jan12a:155: error: 'printHtmlHeader' was not declared in this scope
 
          printHtmlHeader(client); //call for html header and css
 
                                ^
 
sketch_jan12a:197: error: 'triggerPin' was not declared in this scope
 
             triggerPin(outputAddress[0], client, outp);
 
                                                      ^
 
sketch_jan12a:250: error: 'readString' was not declared in this scope
 
             readString="";
 
             ^
 
sketch_jan12a:261: error: 'triggerPin' was not declared in this scope
 
           triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
 
                                       ^
 
sketch_jan12a:271: error: 'printHtmlFooter' was not declared in this scope
 
     printHtmlFooter(client); //Prints the html footer
 
                           ^
 
C:\Users\admin\AppData\Local\Temp\arduino_modified_sketch_377729\sketch_jan12a.ino: At global scope:
 
sketch_jan12a:274: error: expected unqualified-id before 'else'
 
  else
 
  ^
 
exit status 1
'printHtmlHeader' was not declared in this scope
 
 
Этот отчёт будет иметь больше информации с
включенной опцией Файл -> Настройки ->
"Показать подробный вывод во время компиляции"
 
 
#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>


////////////////////////////////////////////////////////////////////////
//CONFIGURATION
////////////////////////////////////////////////////////////////////////

//IP manual settings
byte ip[] = { 
  192, 168, 1, 110 };   //Manual setup only


// if need to change the MAC address (Very Rare)
byte mac[] = { 
  0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

//Ethernet Port
EthernetServer server = EthernetServer(80); //default html port 80

//The number of outputs going to be switched.
int outputQuantity = 16;  //should not exceed 10???

//Invert the output of the leds
boolean outputInverted = true; //true or false
// This is done in case the relay board triggers the relay on negative, rather then on positive supply

//Html page refresh
int refreshPage = 15; //default is 10sec. 
//Beware that if you make it refresh too fast, the page could become inacessable.

//Display or hide the "Switch on all Pins" buttons at the bottom of page
int switchOnAllPinsButton = false; //true or false

//Button Array
//Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.

// Select the pinout address
byte outputAddress[8] = {
  22,23,24,25,26,27,28,29}; //Allocate 10 spaces and name the output pin address.
byte outputAddress2[8]= {
  30,31,32,33,34,35,36,37};
//PS pin addresses 10, 11, 12 and 13 on the Duemilanove are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 10, 50, 51 and 52 and 53 on the Mega are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 4, are used for the SD card, therefore cannot be used.
//PS. pin address 2 is used for interrupt-driven notification, therefore could not be used.

// Write the text description of the output channel
String buttonText[16] = {
  "РЕЛЕ 1","РЕЛЕ 2","РЕЛЕ 3","РЕЛЕ 4","РЕЛЕ 5","РЕЛЕ 6","РЕЛЕ 7","РЕЛЕ 8","РЕЛЕ 9","РЕЛЕ 10","РЕЛЕ 11","РЕЛЕ 12","РЕЛЕ 13","РЕЛЕ 14","РЕЛЕ 15","РЕЛЕ 16"};

// Set the output to retain the last status after power recycle.
int retainOutputStatus[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//1-retain the last status. 0-will be off after power cut.

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
//VARIABLES DECLARATION
////////////////////////////////////////////////////////////////////////

int outp = 0;
boolean printLastCommandOnce = false;
boolean printButtonMenuOnce = false;
boolean initialPrint = true;
String allOn = "";
String allOff = "";
boolean reading = false;
boolean outputStatus[8]; //Create a boolean array for the maximum ammount.
boolean outputStatus2[8]; // relays 9-16
unsigned long timeConnectedAt;
boolean writeToEeprom = false;
EthernetClient client;


////////////////////////////////////////////////////////////////////////
//RUN ONCE
////////////////////////////////////////////////////////////////////////
//Beginning of Program
void setup(){
  Serial.begin(9600);

  //initEepromValues();
  //readEepromValues();

  //Set pins as Outputs 
  boolean currentState = false;
  for (int var = 0; var < 9; var++){
    digitalWrite(outputAddress[var], HIGH);
    pinMode(outputAddress[var], OUTPUT); 

  }
  for (int var2 = 0; var2 < 9; var2++){

    pinMode(outputAddress2[var2], OUTPUT); 
    digitalWrite(outputAddress2[var2], HIGH);
  }



  Ethernet.begin(mac, ip); //for manual setup. (Address is the one configured above.)


  server.begin();
  Serial.print("Server started at ");
  Serial.println(Ethernet.localIP());
  
}


////////////////////////////////////////////////////////////////////////
//LOOP
////////////////////////////////////////////////////////////////////////
//Run once
void loop(){


  // listen for incoming clients, and process requests.
  checkForClient();
}


////////////////////////////////////////////////////////////////////////
//checkForClient Function
////////////////////////////////////////////////////////////////////////
//
void checkForClient(){

  EthernetClient client = server.available();

 // if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;
    
    while (client.connected()) {
      if (client.available()) {
        //if header was not set send it

        //read user input
       char c = client.read();
        Serial.println(c);
        //readString.concat(c);
        if(c == '*'){

          printHtmlHeader(client); //call for html header and css
          printHtmlFooter(client);
          //sentHeader = true;
          break;
        }

        if(!sentHeader){

         printHtmlHeader(client); //call for html header and css
         

          //This is for the arduino to construct the page on the fly. 
          sentHeader = true;
        }

        //read user input
    //    char c = client.read();

        //if there was reading but is blank there was no reading
        if(reading && c == ' '){
          reading = false;
        }

        //if there is a ? there was user input
        if(c == '?') {
          reading = true; //found the ?, begin reading the info
        }

        // if there was user input switch the relevant output
        if(reading){

          //if user input is H set output to 1
          if(c == 'H') {
            outp = 1;
          }

          //if user input is L set output to 0
          if(c == 'L') {
            outp = 0;
          }


          Serial.print(c);   //print the value of c to serial communication
          //Serial.print(outp);
          //Serial.print('\n');

          switch (c) {

          case '0':
            //add code here to trigger on 0
            triggerPin(outputAddress[0], client, outp);
            break;            
          case '1':
            //add code here to trigger on 1
            triggerPin(outputAddress[1], client, outp);
            break;             
          case '2':
            //add code here to trigger on 2
            triggerPin(outputAddress[2], client, outp);
            break;
          case '3':
            //add code here to trigger on 3
            triggerPin(outputAddress[3], client, outp);
            break;
          case '4':
            //add code here to trigger on 4
            triggerPin(outputAddress[4], client, outp);
            break;
          case '5':
            //add code here to trigger on 5
            triggerPin(outputAddress[5], client, outp);
            //  printHtml(client);
            break;
          case '6':
            //add code here to trigger on 6
            triggerPin(outputAddress[6], client, outp);
            break;
          case '7':
            //add code here to trigger on 7
            triggerPin(outputAddress[7], client, outp);
            break;
          case '8':
            //add code here to trigger on 8
            triggerPin(outputAddress[8], client, outp);
            break;
          case '9':
            // add code here to trigger on 9
            triggerPin(outputAddress[9], client, outp);
            break;
          case 'A':
            triggerPin(outputAddress[10], client, outp);
            break;
          case 'B':
            triggerPin(outputAddress[11], client, outp);
            break;
          case 'C':
            triggerPin(outputAddress[12], client, outp);
            break;
          case 'D':
            triggerPin(outputAddress[13], client, outp);
            break;
          case 'F':
            triggerPin(outputAddress[15], client, outp);
            readString="";
            break;

          } //end of switch case

        }//end of switch switch the relevant output 

        //if user input was blank
        if (c == '\n' && currentLineIsBlank){
          printLastCommandOnce = true;
          printButtonMenuOnce = true;
          triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
          break;
        }
        


        
      }
    }
    
    printHtmlFooter(client); //Prints the html footer
 
  } 
 else
   {  //if there is no client
  
      //And time of last page was served is more then a minute.
      if (millis() > (timeConnectedAt + 60000)){           

             if (writeToEeprom == true){ 
                 writeEepromValues();  //write to EEprom the current output statuses
                 Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");
                 writeToEeprom = false;
             }
             
      }
   }


}


////////////////////////////////////////////////////////////////////////
//triggerPin Function
////////////////////////////////////////////////////////////////////////
//
void triggerPin(int pin, EthernetClient client, int outp){
  //Switching on or off outputs, reads the outputs and prints the buttons   

  //Setting Outputs
  if (pin != 777){ 

    if(outp == 1) {
      if (outputInverted ==false){ 
        digitalWrite(pin, HIGH);
      } 
      else{
        digitalWrite(pin, LOW);
      }
    }
    if(outp == 0){
      if (outputInverted ==false){ 
        digitalWrite(pin, LOW);
      } 
      else{
        digitalWrite(pin, HIGH);
      }
    }
  }
  //Refresh the reading of outputs
  readOutputStatuses();


  //Prints the buttons
  if (printButtonMenuOnce == true){
    printHtmlButtons(client);
    printButtonMenuOnce = false;
  }

}

////////////////////////////////////////////////////////////////////////
//printHtmlButtons Function
////////////////////////////////////////////////////////////////////////
//print the html buttons to switch on/off channels
void printHtmlButtons(EthernetClient client){

  //Start to create the html table
  client.println("");
  //client.println("<p>");
  client.println("<FORM>");
  client.println("<table border=\"0\" align=\"left\">");


  


  //Start printing button by button
  for (int var = 0; var < outputQuantity; var++)  {      

    //set command for all on/off
    allOn += "H";
    allOn += outputAddress[var];
    allOff += "L";
    allOff += outputAddress[var];


    //Print begining of row
    client.print("<tr>\n");    
//текст кнопок
    //Prints the button Text
    client.print("<td><h2>");
    client.print(buttonText[var]);
    client.print("</h2></td>\n");

    //Prints the ON Buttons
    client.print("<td>");
    //client.print(buttonText[var]);
    client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
    //client.print(buttonText[var]);
    client.print("\" onClick=\"parent.location='/?H");
    client.print(var);
    client.print("'\"></td>\n");

    //Prints the OFF Buttons 
    client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
    //client.print(var);
    client.print("\" onClick=\"parent.location='/?L");
    client.print(var);
    client.print("'\"></td>\n");


    //Print first part of the Circles or the LEDs

    //Invert the LED display if output is inverted.

    if (outputStatus[var] == true ){                                                            //If Output is ON
      if (outputInverted == false){                                                             //and if output is not inverted 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED
      }
      else{                                                                                    //else output is inverted then
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
    }
    else                                                                                      //If Output is Off
    {
      if (outputInverted == false){                                                           //and if output is not inverted
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
      else{                                                                                   //else output is inverted then 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED                    
      }
    }  




    //Print end of row
    client.print("</tr>\n");  
  }

  //Display or hide the Print all on Pins Button
  if (switchOnAllPinsButton == true ){

    //Prints the ON All Pins Button
    client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOn);
    client.print("'\"></td>\n");

    //Prints the OFF All Pins Button            
    client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOff);
    client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
  }

  //Closing the table and form
  client.println("</table>");
  client.println("</FORM>");
  //client.println("</p>"); 

}

////////////////////////////////////////////////////////////////////////
//readOutputStatuses Function
////////////////////////////////////////////////////////////////////////
//Reading the Output Statuses
void readOutputStatuses(){
  for (int var = 0; var < outputQuantity; var++)  { 
    outputStatus[var] = digitalRead(outputAddress[var]);
    outputStatus2[var] = digitalRead(outputAddress2[var]);
    //Serial.print(outputStatus[var]);
 

   }

}

////////////////////////////////////////////////////////////////////////
//readEepromValues Function
////////////////////////////////////////////////////////////////////////
//Read EEprom values and save to outputStatus
void readEepromValues(){
  for (int adr = 0; adr < outputQuantity; adr++)  { 
    outputStatus[adr] = EEPROM.read(adr); 
  }
}

////////////////////////////////////////////////////////////////////////
//writeEepromValues Function
////////////////////////////////////////////////////////////////////////
//Write EEprom values
void writeEepromValues(){
  for (int adr = 0; adr < outputQuantity; adr++)  { 
    EEPROM.write(adr, outputStatus[adr]);
  }

} 

////////////////////////////////////////////////////////////////////////
//initEepromValues Function
////////////////////////////////////////////////////////////////////////
//Initialiaze EEprom values
//if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0
void initEepromValues(){
      for (int adr = 0; adr < outputQuantity; adr++){        
         if (EEPROM.read(adr) > 1){
                EEPROM.write(adr, 0);
    } 

  }

}


////////////////////////////////////////////////////////////////////////
//htmlHeader Function
////////////////////////////////////////////////////////////////////////
//Prints html header
 void printHtmlHeader(EthernetClient client){
          Serial.print("Serving html Headers at ms -");
          timeConnectedAt = millis(); //Record the time when last page was served.
          Serial.print(timeConnectedAt); // Print time for debbugging purposes
          writeToEeprom = true; // page loaded so set to action the write to eeprom
          
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html;charset=UTF-8");//"Content-Type: text/html;charset=UTF-8"
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<head>");

          // add page title 
          client.println("<title>Удаленное управление</title>");
          client.println("<meta name=\"description\" content=\"Удаленное управление\"/>");
/*
//перзагрузка страницы,рефреш
          // add a meta refresh tag, so the browser pulls again every x seconds:
          client.print("<meta http-equiv=\"refresh\" content=\"");
          client.print(refreshPage);
          client.println("; url=/\">");
*/
          // add other browser configuration
          client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
          client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");
          client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");          

          //inserting the styles data, usually found in CSS files.
          client.println("<style type=\"text/css\">");
          client.println("");

          //This will set how the page will look graphically
          client.println("html { height:100%; }");  

          client.println("  body {");
          client.println("    height: 100%;");
          client.println("    margin: 0;");
          client.println("    font-family: helvetica, sans-serif;");
          client.println("    -webkit-text-size-adjust: none;");
          client.println("   }");
          client.println("");
          client.println("body {");
          client.println("    -webkit-background-size: 100% 21px;");
          client.println("    background-color: #c5ccd3;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, right top,");
          client.println("    color-stop(.75, transparent),");
          client.println("    color-stop(.75, rgba(255,255,255,.1)) );");
          client.println("    -webkit-background-size: 7px;");
          client.println("   }");
          client.println("");
          client.println(".view {");
          client.println("    min-height: 100%;");
          client.println("    overflow: auto;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper {");
          client.println("    height: 44px;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");
          client.println("    border-top: solid 1px rgba(255,255,255,0.6);");
          client.println("    border-bottom: solid 1px rgba(0,0,0,0.6);");
          client.println("    color: #fff;");
          client.println("    background-color: #8195af;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(rgba(255,255,255,.4)),");
          client.println("    to(rgba(255,255,255,.05)) ),");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(transparent),");
          client.println("    to(rgba(0,0,64,.1)) );");
          client.println("    background-repeat: no-repeat;");
          client.println("    background-position: top left, bottom left;");
          client.println("    -webkit-background-size: 100% 21px, 100% 22px;");
          client.println("    -webkit-box-sizing: border-box;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper h1 {");
          client.println("    text-align: center;");
          client.println("    font-size: 20px;");
          client.println("    line-height: 44px;");
          client.println("    margin: 0;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper {");
          client.println("    margin: 9px;");
          client.println("    }");
          client.println("");
          client.println(".group-wrapper h2 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 17px;");
          client.println("    line-height: 0.8;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h3 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 12px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h4 {");  //Text for description
          client.println("    color: #212121;");
          client.println("    font-size: 14px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #aaa 1px 1px 3px;");
          client.println("    margin: 5px 5px 5px;");
          client.println("   }");
          client.println(""); 
          client.println(".group-wrapper table {");
          client.println("    background-color: #fff;");
          client.println("    -webkit-border-radius: 10px;");

          client.println("    -moz-border-radius: 10px;");
          client.println("    -khtml-border-radius: 10px;");
          client.println("    border-radius: 10px;");


          client.println("    font-size: 20px;");
          client.println("    line-height: 20px;");
          client.println("    margin: 9px 0 20px;");
          client.println("    border: solid 1px #a9abae;");
          client.println("    padding: 11px 3px 12px 3px;");
          client.println("    margin-left:auto;");
          client.println("    margin-right:auto;");

          client.println("    -moz-transform :scale(1);"); //Code for Mozilla Firefox
          client.println("    -moz-transform-origin: 0 0;");



          client.println("   }");
          client.println("");


          //how the green (ON) LED will look
          client.println(".green-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #0f0;");
          //client.println("    background-color: rgba(60, 132, 198, 0.8);");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");

          client.println("    background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");
          client.println("    border: 2px solid #ccc;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

          client.println("    }");
          client.println("");

          //how the black (off)LED will look
          client.println(".black-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #040;");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */"); 
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    }");
          client.println("");

          //this will add the glare to both of the LEDs
          client.println("   .glare {");
          client.println("      position: relative;");
          client.println("      top: 1;");
          client.println("      left: 5px;");
          client.println("      -webkit-border-radius: 10px;");
          client.println("      -moz-border-radius: 10px;");
          client.println("      -khtml-border-radius: 10px;");
          client.println("      border-radius: 10px;");
          client.println("      height: 1px;");
          client.println("      width: 13px;");
          client.println("      padding: 5px 0;");
          client.println("      background-color: rgba(200, 200, 200, 0.25);");
          client.println("      background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");
          client.println("    }");
          client.println("");


          //and finally this is the end of the style data and header
          client.println("</style>");
          client.println("</head>");

          //now printing the page itself
          client.println("<body>");
          client.println("<div class=\"view\">");
          client.println("    <div class=\"header-wrapper\">");
          client.println("      <h1>Умный дом</h1>");
          client.println("    </div>");

//////

 } //end of htmlHeader

////////////////////////////////////////////////////////////////////////
//htmlFooter Function
////////////////////////////////////////////////////////////////////////
//Prints html footer
void printHtmlFooter(EthernetClient client){
    //Set Variables Before Exiting 
    printLastCommandOnce = false;
    printButtonMenuOnce = false;
    allOn = "";
    allOff = "";
    /*client.println("\n</div>\n</body>\n</html>");
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
    */
    
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
   
 } //end of htmlFooter


////////////////////////////////////////////////////////////////////////
//printHtmlButtonTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title
void printHtmlButtonTitle(EthernetClient client){
  client.println("<div  class=\"group-wrapper\">");
  client.println();
}


////////////////////////////////////////////////////////////////////////
//printLoginTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title

void printLoginTitle(EthernetClient client){
         client.println("<div  class=\"group-wrapper\">");
          client.println("    <h2>Please enter the user data to login.</h2>");
          client.println();
}

 

 

kalapanga
Offline
Зарегистрирован: 23.10.2016

Функции должны быть объявлены до их использования.

dim5555
Offline
Зарегистрирован: 12.01.2019

спасибо , видно просто не хватает знаний...

вот эта версия на 20 реле компилируется нормально, отображаются все 20 реле, c 1 по 10 работают как положено - далее если допустим включить реле 14 отработают реле 2 и 4.

Ребята , поправьте пожалуйста скетч, уже сутки не сплю...

#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>


////////////////////////////////////////////////////////////////////////
//CONFIGURATION
////////////////////////////////////////////////////////////////////////

//IP manual settings
byte ip[] = { 
  192, 168, 1, 110 };   //Manual setup only


// if need to change the MAC address (Very Rare)
byte mac[] = { 
  0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

//Ethernet Port
EthernetServer server = EthernetServer(80); //default html port 80

//The number of outputs going to be switched.
int outputQuantity = 20;  //should not exceed 10???

//Invert the output of the leds
boolean outputInverted = true; //true or false
// This is done in case the relay board triggers the relay on negative, rather then on positive supply

//Html page refresh
int refreshPage = 15; //default is 10sec. 
//Beware that if you make it refresh too fast, the page could become inacessable.

//Display or hide the "Switch on all Pins" buttons at the bottom of page
int switchOnAllPinsButton = false; //true or false

//Button Array
//Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.

// Select the pinout address
int outputAddress[10] = { 22,23,24,25,26,27,28,29,30,31}; //Allocate 10
int outputAddress2[10]= { 32,33,34,35,36,37,38,39,40,41}; //Allocate 10
//PS pin addresses 10, 11, 12 and 13 on the Duemilanove are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 10, 50, 51 and 52 and 53 on the Mega are used for the ethernet shield, therefore cannot be used.
//PS pin addresses 4, are used for the SD card, therefore cannot be used.
//PS. pin address 2 is used for interrupt-driven notification, therefore could not be used.

// Write the text description of the output channel
String buttonText[20] = {
  "Relay 1","Relay 2","Relay 3","Relay 4","Relay 5","Relay 6","Relay 7","Relay 8","Relay 9","Relay 10","Relay 11","Relay 12","Relay 13","Relay 14","Relay 15","Relay 16","Relay 17","Relay 18","Relay 19","Relay 20"};

// Set the output to retain the last status after power recycle.
int retainOutputStatus[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//1-retain the last status. 0-will be off after power cut.

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
//VARIABLES DECLARATION
////////////////////////////////////////////////////////////////////////
int outp = 0;
boolean printLastCommandOnce = false;
boolean printButtonMenuOnce = false;
boolean initialPrint = true;
String allOn = "";
String allOff = "";
boolean reading = false;
boolean outputStatus[20]; //Create a boolean array for the maximum ammount.
unsigned long timeConnectedAt;
boolean writeToEeprom = false;
EthernetClient client;



////////////////////////////////////////////////////////////////////////
//RUN ONCE
////////////////////////////////////////////////////////////////////////
//Beginning of Program
void setup(){
  Serial.begin(9600);

  initEepromValues();
  readEepromValues();

  //Set pins as Outputs 
  boolean currentState = false;
  for (int var = 0; var < 11; var++){
    digitalWrite(outputAddress[var], HIGH);
    pinMode(outputAddress[var], OUTPUT); 

  }
  for (int var2 = 0; var2 < 11; var2++){

    pinMode(outputAddress2[var2], OUTPUT); 
    digitalWrite(outputAddress2[var2], HIGH);
  }

  //Setting up the IP address. Comment out the one you dont need.
  //Ethernet.begin(mac); //for DHCP address. (Address will be printed to serial.)
  Ethernet.begin(mac, ip); //for manual setup. (Address is the one configured above.)


  server.begin();
  Serial.print("Server started at ");
  Serial.println(Ethernet.localIP());
}


////////////////////////////////////////////////////////////////////////
//LOOP
////////////////////////////////////////////////////////////////////////
//Run once
void loop(){


  // listen for incoming clients, and process requests.
  checkForClient();
}

////////////////////////////////////////////////////////////////////////
//checkForClient Function
////////////////////////////////////////////////////////////////////////
//
void checkForClient(){

  EthernetClient client = server.available();

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {

        //if header was not set send it
        
         //read user input
        char c = client.read();
        
          if(c == '*'){

          printHtmlHeader(client); //call for html header and css
          printLoginTitle(client);
          printHtmlFooter(client);
          //sentHeader = true;
          break;
        }
        
        if(!sentHeader){
          
            printHtmlHeader(client); //call for html header and css
           // printHtmlButtonTitle(client); //print the button title
            
          //This is for the arduino to construct the page on the fly. 
          sentHeader = true;
        }

        //read user input
    //    char c = client.read();

        //if there was reading but is blank there was no reading
        if(reading && c == ' '){
          reading = false;
        }

        //if there is a ? there was user input
        if(c == '?') {
          reading = true; //found the ?, begin reading the info
        }

       // if there was user input switch the relevant output
        if(reading){
          
          //if user input is H set output to 1
          if(c == 'H') {
            outp = 1;
          }
          
          //if user input is L set output to 0
          if(c == 'L') {
            outp = 0;
          }
          
          Serial.print(c);   //print the value of c to serial communication
          //Serial.print(outp);
          //Serial.print('\n');

          switch (c) {

             case '0':
            //add code here to trigger on 0
            triggerPin(outputAddress[0], client, outp);
            break;            
          case '1':
            //add code here to trigger on 1
            triggerPin(outputAddress[1], client, outp);
            break;             
          case '2':
            //add code here to trigger on 2
            triggerPin(outputAddress[2], client, outp);
            break;
          case '3':
            //add code here to trigger on 3
            triggerPin(outputAddress[3], client, outp);
            break;
          case '4':
            //add code here to trigger on 4
            triggerPin(outputAddress[4], client, outp);
            break;
          case '5':
            //add code here to trigger on 5
            triggerPin(outputAddress[5], client, outp);
            //  printHtml(client);
            break;
          case '6':
            //add code here to trigger on 6
            triggerPin(outputAddress[6], client, outp);
            break;
          case '7':
            //add code here to trigger on 7
            triggerPin(outputAddress[7], client, outp);
            break;
          case '8':
            //add code here to trigger on 8
            triggerPin(outputAddress[8], client, outp);
            break;
          case '9':
            // add code here to trigger on 9
            triggerPin(outputAddress[9], client, outp);
            break;
          case 'A':
            triggerPin(outputAddress[10], client, outp);
            break;
          case 'B':
            triggerPin(outputAddress[11], client, outp);
            break;
          case 'C':
            triggerPin(outputAddress[12], client, outp);
            break;
          case 'D':
            triggerPin(outputAddress[13], client, outp);
            break;
          case 'E':
            triggerPin(outputAddress[14], client, outp);
            break;
          case 'F':
            triggerPin(outputAddress[15], client, outp);
            break;
            case 'G':
            triggerPin(outputAddress[16], client, outp);
            break;
          case 'H':
            triggerPin(outputAddress[17], client, outp);
            break;
          case 'I':
            triggerPin(outputAddress[18], client, outp);
            break;
          case 'J':
            triggerPin(outputAddress[19], client, outp);
            break;

          } //end of switch case

        }//end of switch switch the relevant output 

        //if user input was blank
        if (c == '\n' && currentLineIsBlank){
          printLastCommandOnce = true;
          printButtonMenuOnce = true;
          triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
          break;
        }
        


        
      }
    }
    
    printHtmlFooter(client); //Prints the html footer
 
  } 
else
   {  //if there is no client
  
      //And time of last page was served is more then a minute.
      if (millis() > (timeConnectedAt + 60000)){           

             if (writeToEeprom == true){ 
                 writeEepromValues();  //write to EEprom the current output statuses
                 Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");
                 writeToEeprom = false;
             }
             
      }
   }


}


////////////////////////////////////////////////////////////////////////
//triggerPin Function
////////////////////////////////////////////////////////////////////////
//
void triggerPin(int pin, EthernetClient client, int outp){
  //Switching on or off outputs, reads the outputs and prints the buttons   

  //Setting Outputs
  if (pin != 777){ 

    if(outp == 1) {
      if (outputInverted ==false){ 
        digitalWrite(pin, HIGH);
      } 
      else{
        digitalWrite(pin, LOW);
      }
    }
    if(outp == 0){
      if (outputInverted ==false){ 
        digitalWrite(pin, LOW);
      } 
      else{
        digitalWrite(pin, HIGH);
      }
    }


  }
  //Refresh the reading of outputs
  readOutputStatuses();


  //Prints the buttons
  if (printButtonMenuOnce == true){
    printHtmlButtons(client);
    printButtonMenuOnce = false;
  }

}

////////////////////////////////////////////////////////////////////////
//printHtmlButtons Function
////////////////////////////////////////////////////////////////////////
//print the html buttons to switch on/off channels
void printHtmlButtons(EthernetClient client){

  //Start to create the html table
  client.println("");
  //client.println("<p>");
  client.println("<FORM>");
  client.println("<table border=\"0\" align=\"left\">");


  


  //Start printing button by button
  for (int var = 0; var < outputQuantity; var++)  {      

    //set command for all on/off
    allOn += "H";
    allOn += outputAddress[var];
    allOff += "L";
    allOff += outputAddress[var];


    //Print begining of row
    client.print("<tr>\n");    
//текст кнопок
    //Prints the button Text
    client.print("<td><h2>");
    client.print(buttonText[var]);
    client.print("</h2></td>\n");

    //Prints the ON Buttons
    client.print("<td>");
    //client.print(buttonText[var]);
    client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
    //client.print(buttonText[var]);
    client.print("\" onClick=\"parent.location='/?H");
    client.print(var);
    client.print("'\"></td>\n");

    //Prints the OFF Buttons 
    client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
    //client.print(var);
    client.print("\" onClick=\"parent.location='/?L");
    client.print(var);
    client.print("'\"></td>\n");


    //Print first part of the Circles or the LEDs

    //Invert the LED display if output is inverted.

    if (outputStatus[var] == true ){                                                            //If Output is ON
      if (outputInverted == false){                                                             //and if output is not inverted 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED
      }
      else{                                                                                    //else output is inverted then
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
    }
    else                                                                                      //If Output is Off
    {
      if (outputInverted == false){                                                           //and if output is not inverted
        client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
      }
      else{                                                                                   //else output is inverted then 
        client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED                    
      }
    }  




    //Print end of row
    client.print("</tr>\n");  
  }

  //Display or hide the Print all on Pins Button
  if (switchOnAllPinsButton == true ){

    //Prints the ON All Pins Button
    client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOn);
    client.print("'\"></td>\n");

    //Prints the OFF All Pins Button            
    client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");
    client.print("\" onClick=\"parent.location='/?");
    client.print(allOff);
    client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
  }

  //Closing the table and form
  client.println("</table>");
  client.println("</FORM>");
  //client.println("</p>"); 

}

////////////////////////////////////////////////////////////////////////
//readOutputStatuses Function
////////////////////////////////////////////////////////////////////////
//Reading the Output Statuses
void readOutputStatuses(){
  for (int var = 0; var < outputQuantity; var++)  { 
    outputStatus[var] = digitalRead(outputAddress[var]);
    //Serial.print(outputStatus[var]);
  }

}

////////////////////////////////////////////////////////////////////////
//readEepromValues Function
////////////////////////////////////////////////////////////////////////
//Read EEprom values and save to outputStatus
void readEepromValues(){
    for (int adr = 0; adr < outputQuantity; adr++)  { 
    outputStatus[adr] = EEPROM.read(adr); 
    }
}

////////////////////////////////////////////////////////////////////////
//writeEepromValues Function
////////////////////////////////////////////////////////////////////////
//Write EEprom values
void writeEepromValues(){
    for (int adr = 0; adr < outputQuantity; adr++)  { 
    EEPROM.write(adr, outputStatus[adr]);
    }

} 

////////////////////////////////////////////////////////////////////////
//initEepromValues Function
////////////////////////////////////////////////////////////////////////
//Initialiaze EEprom values
//if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0
void initEepromValues(){
      for (int adr = 0; adr < outputQuantity; adr++){        
         if (EEPROM.read(adr) > 1){
                EEPROM.write(adr, 0);
         } 
 
      }
  
}


////////////////////////////////////////////////////////////////////////
//htmlHeader Function
////////////////////////////////////////////////////////////////////////
//Prints html header
 void printHtmlHeader(EthernetClient client){
          Serial.print("Serving html Headers at ms -");
          timeConnectedAt = millis(); //Record the time when last page was served.
          Serial.print(timeConnectedAt); // Print time for debbugging purposes
          writeToEeprom = true; // page loaded so set to action the write to eeprom
          
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html;charset=UTF-8");//"Content-Type: text/html;charset=UTF-8"
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<head>");

          // add page title 
          client.println("<title>MajorDomo</title>");
          client.println("<meta name=\"description\" content=\"Удаленное управление\"/>");
/*
//перзагрузка страницы,рефреш
          // add a meta refresh tag, so the browser pulls again every x seconds:
          client.print("<meta http-equiv=\"refresh\" content=\"");
          client.print(refreshPage);
          client.println("; url=/\">");
*/
          // add other browser configuration
          client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
          client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");
          client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");          

          //inserting the styles data, usually found in CSS files.
          client.println("<style type=\"text/css\">");
          client.println("");

          //This will set how the page will look graphically
          client.println("html { height:100%; }");  

          client.println("  body {");
          client.println("    height: 100%;");
          client.println("    margin: 0;");
          client.println("    font-family: helvetica, sans-serif;");
          client.println("    -webkit-text-size-adjust: none;");
          client.println("   }");
          client.println("");
          client.println("body {");
          client.println("    -webkit-background-size: 100% 21px;");
          client.println("    background-color: #c5ccd3;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, right top,");
          client.println("    color-stop(.75, transparent),");
          client.println("    color-stop(.75, rgba(255,255,255,.1)) );");
          client.println("    -webkit-background-size: 7px;");
          client.println("   }");
          client.println("");
          client.println(".view {");
          client.println("    min-height: 100%;");
          client.println("    overflow: auto;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper {");
          client.println("    height: 44px;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");
          client.println("    border-top: solid 1px rgba(255,255,255,0.6);");
          client.println("    border-bottom: solid 1px rgba(0,0,0,0.6);");
          client.println("    color: #fff;");
          client.println("    background-color: #8195af;");
          client.println("    background-image:");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(rgba(255,255,255,.4)),");
          client.println("    to(rgba(255,255,255,.05)) ),");
          client.println("    -webkit-gradient(linear, left top, left bottom,");
          client.println("    from(transparent),");
          client.println("    to(rgba(0,0,64,.1)) );");
          client.println("    background-repeat: no-repeat;");
          client.println("    background-position: top left, bottom left;");
          client.println("    -webkit-background-size: 100% 21px, 100% 22px;");
          client.println("    -webkit-box-sizing: border-box;");
          client.println("   }");
          client.println("");
          client.println(".header-wrapper h1 {");
          client.println("    text-align: center;");
          client.println("    font-size: 20px;");
          client.println("    line-height: 44px;");
          client.println("    margin: 0;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper {");
          client.println("    margin: 9px;");
          client.println("    }");
          client.println("");
          client.println(".group-wrapper h2 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 17px;");
          client.println("    line-height: 0.8;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h3 {");
          client.println("    color: #4c566c;");
          client.println("    font-size: 12px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #fff 0 1px 0;");
          client.println("    margin: 20px 10px 12px;");
          client.println("   }");
          client.println("");
          client.println(".group-wrapper h4 {");  //Text for description
          client.println("    color: #212121;");
          client.println("    font-size: 14px;");
          client.println("    line-height: 1;");
          client.println("    font-weight: bold;");
          client.println("    text-shadow: #aaa 1px 1px 3px;");
          client.println("    margin: 5px 5px 5px;");
          client.println("   }");
          client.println(""); 
          client.println(".group-wrapper table {");
          client.println("    background-color: #fff;");
          client.println("    -webkit-border-radius: 10px;");

          client.println("    -moz-border-radius: 10px;");
          client.println("    -khtml-border-radius: 10px;");
          client.println("    border-radius: 10px;");


          client.println("    font-size: 20px;");
          client.println("    line-height: 20px;");
          client.println("    margin: 9px 0 20px;");
          client.println("    border: solid 1px #a9abae;");
          client.println("    padding: 11px 3px 12px 3px;");
          client.println("    margin-left:auto;");
          client.println("    margin-right:auto;");

          client.println("    -moz-transform :scale(1);"); //Code for Mozilla Firefox
          client.println("    -moz-transform-origin: 0 0;");



          client.println("   }");
          client.println("");


          //how the green (ON) LED will look
          client.println(".green-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #0f0;");
          //client.println("    background-color: rgba(60, 132, 198, 0.8);");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");

          client.println("    background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");
          client.println("    border: 2px solid #ccc;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

          client.println("    }");
          client.println("");

          //how the black (off)LED will look
          client.println(".black-circle {");
          client.println("    display: block;");
          client.println("    height: 23px;");
          client.println("    width: 23px;");
          client.println("    background-color: #040;");
          client.println("    -moz-border-radius: 11px;");
          client.println("    -webkit-border-radius: 11px;");
          client.println("    -khtml-border-radius: 11px;");
          client.println("    border-radius: 11px;");
          client.println("    margin-left: 1px;");
          client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
          client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */"); 
          client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
          client.println("    }");
          client.println("");

          //this will add the glare to both of the LEDs
          client.println("   .glare {");
          client.println("      position: relative;");
          client.println("      top: 1;");
          client.println("      left: 5px;");
          client.println("      -webkit-border-radius: 10px;");
          client.println("      -moz-border-radius: 10px;");
          client.println("      -khtml-border-radius: 10px;");
          client.println("      border-radius: 10px;");
          client.println("      height: 1px;");
          client.println("      width: 13px;");
          client.println("      padding: 5px 0;");
          client.println("      background-color: rgba(200, 200, 200, 0.25);");
          client.println("      background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");
          client.println("    }");
          client.println("");


          //and finally this is the end of the style data and header
          client.println("</style>");
          client.println("</head>");

          //now printing the page itself
          client.println("<body>");
          client.println("<div class=\"view\">");
          client.println("    <div class=\"header-wrapper\">");
          client.println("      <h1>Умный дом</h1>");
          client.println("    </div>");

//////

 } //end of htmlHeader

////////////////////////////////////////////////////////////////////////
//htmlFooter Function
////////////////////////////////////////////////////////////////////////
//Prints html footer
void printHtmlFooter(EthernetClient client){
    //Set Variables Before Exiting 
    printLastCommandOnce = false;
    printButtonMenuOnce = false;
    allOn = "";
    allOff = "";
    /*client.println("\n</div>\n</body>\n</html>");
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
    */
    
    delay(1); // give the web browser time to receive the data

    client.stop(); // close the connection:
    
    Serial.println(" - Done, Closing Connection.");
    
    delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
   
 } //end of htmlFooter


////////////////////////////////////////////////////////////////////////
//printHtmlButtonTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title
void printHtmlButtonTitle(EthernetClient client){
          client.println("<div  class=\"group-wrapper\">");
          client.println();
}



////////////////////////////////////////////////////////////////////////
//printLoginTitle Function
////////////////////////////////////////////////////////////////////////
//Prints html button title

void printLoginTitle(EthernetClient client){
         client.println("<div  class=\"group-wrapper\">");
          client.println("    <h2>Please enter the user data to login.</h2>");
          client.println();
}

 

sadman41
Offline
Зарегистрирован: 19.10.2016

Не надо включать реле 14, надо включать D.

dim5555
Offline
Зарегистрирован: 12.01.2019

не могу понять как это сделать.

до этого с ардуиной не работал.

могу рассмотреть вариант Вашей помощи на материальной основе

sadman41
Offline
Зарегистрирован: 19.10.2016

К глобальным переменным прибавляете такую:

char relayIds[outputQuantity] = {'0', '1', ..., '9', 'A', 'B'...}; // Недостающие символы дорисуйте сами

А client.print(var); замените на client.print(relayIds[var]);

Впрочем, всё равно это будет работать плохо, так как неправильно обрабатывается outputAddress[] и outputAddress2[]

А скетч я этот помню... он на интструктейблесе лежал. Что-то там версии 4.0.1 Я в него температуру с DS-ок запихивал по просьбе товарищей. Там еще несколько некорректных конструкций внутри имеется.

sadman41
Offline
Зарегистрирован: 19.10.2016

dim5555 пишет:

не могу понять как это сделать.

до этого с ардуиной не работал.

могу рассмотреть вариант Вашей помощи на материальной основе

Для помощи на материальной основе есть раздел "Ищу исполнителя". Если не будете тянуть, то сразу откликнусь.

dim5555
Offline
Зарегистрирован: 12.01.2019

При всем моем уважении я постесняюсь продложить Вам копейки. На али готовое *железное*устройство на 16 каналов 500 руб.   https://hz.ru.aliexpress.com/item/16-Channel-28J60-W5100-RJ45-Network-Control-Switch-5V-Internet-Relay-Module-5V-DC-Network-Relay/32826476670.html?spm=a2g0s.13010208.99999999.27.12b83c00EOUtnF  Завтра оплачу, мегу куда нибудь потом пристрою.. Тему прошу закрыть. Всем спасибо за помощь.

b707
Offline
Зарегистрирован: 26.05.2017

dim5555 пишет:

При всем моем уважении я постесняюсь продложить Вам копейки. На али готовое *железное*устройство на 16 каналов 500 руб. 

у вас неправильная логика. если вы считаете, что если на Али готовый блок стоит 500. то доработка вашего кода должна быть дешевле. Заказная разработка всегда дороже.

dim5555
Offline
Зарегистрирован: 12.01.2019

Я сам работаю с кодом в области автомобилей, цену работы умом и руками знаю и ценю.

У меня и в мыслях не было никого обидеть. Было бы время - сам сел бы и разобрался.

Мне тема кода всегда была и будет интересна. Просто если есть готовое устройство которое будет включать у меня на даче свет, ,боилер, электро_теплый пол и прочее когда я буду в любой точке мира и это все за 500 рублей. Дома и так все работает на Sonoff, теперь очередь дачи.

Я и сам за копейки не работаю и Вам мизерную оплату мне предлагать стыдно.

С уважением.Дмитрий.

 

qwone
qwone аватар
Offline
Зарегистрирован: 03.07.2016
mykaida
mykaida аватар
Offline
Зарегистрирован: 12.07.2018

dim5555 пишет:

Я сам работаю с кодом в области автомобилей, цену работы умом и руками знаю и ценю.

У меня и в мыслях не было никого обидеть. Было бы время - сам сел бы и разобрался.

Мне тема кода всегда была и будет интересна. Просто если есть готовое устройство которое будет включать у меня на даче свет, ,боилер, электро_теплый пол и прочее когда я буду в любой точке мира и это все за 500 рублей. Дома и так все работает на Sonoff, теперь очередь дачи.

Я и сам за копейки не работаю и Вам мизерную оплату мне предлагать стыдно.

С уважением.Дмитрий.

 

За 500рублей скорее всего не получится - исполнительные устройства будут стоить дороже. А реальные проекты такого посмотри в разделе "проекты". Там народ решает подобные задачи и бесплатно раздает их нам.

dim5555
Offline
Зарегистрирован: 12.01.2019

lДобрый вечер. Спасибо за видео. Очень познавательно.

По поводу исполнительных устройств - их цена на али -копейки.

На предыдущий проект брал на али 40 амперные Твердотельные реле под силовую нагрузку+радиатор по 500 рублей,материнку под проект MajorDoMo снял с автосканера Faw ( индустриальная плата мини пк на Intel Atom) он все равно валялся без дела, старий tp-link 1043(с прошивкой OpenWrt) достал с полки.

Купил по мелочи на али разные побрякушки от Sonoff сенсорные Wi-fi выключатели, реле. бюджет всего купленного пока не превысил 5000 рублей. За работу мне никому платить не нужно.

 

sadman41
Offline
Зарегистрирован: 19.10.2016

Штука интересная (теоретически). На борту ENC28J60, а не W5100 и какой-то STM8 (не могу рассмотреть модель). Вот картинки покрупнее: https://www.aliexpress.com/item/8-Channel-ENC28J60-28J60-W5100-RJ45-Network-Relay-Control-Switch-5V-Internet-Relay-Module-P2P-WIFI/32958288720.html

Вроде даже разъем программирования выведен на плату, так что любители СТМ-ок могут получить для экспериментов готовый модуль с сетью.

P.S. Судя по всему на одной плате собираются 8-relay module и 16-relay module. Так что по старой китайской тридиции ляовай может получить не W5100 / 16 outputs, а вполне себе Brand new ENC28J60 / 8 outputs. Причём, выходы, видимо, будут с TTL 3.3V

P.P.S. Удалось сыскать брата на W5100, но только в музее: https://wiznetmuseum.com/portfolio-items/w5100-network-relay-control-module-weiba/?portfolioID=10935 . Партномер FC-188, МК Nuvoton. Думал, что хоть там будет ATMega, которую можно приспособить под свои нужды...

 

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

sadman41 пишет:

Штука интересная (теоретически). На борту ENC28J60, а не W5100 и какой-то STM8 (не могу рассмотреть модель). Вот картинки покрупнее: https://www.aliexpress.com/item/8-Channel-ENC28J60-28J60-W5100-RJ45-Network-Relay-Control-Switch-5V-Internet-Relay-Module-P2P-WIFI/32958288720.html

Вроде даже разъем программирования выведен на плату, так что любители СТМ-ок могут получить для экспериментов готовый модуль с сетью.

На фотографии там STM8005C6T6. Но придти может и с Nuvoton-ом каким-нибудь. Я пытался вольтметры с STM8 заказать. На фотках ясно было видно STM8, а пришли все (у 3-х продавцов заказывал) с Nuvoton-ами

sadman41
Offline
Зарегистрирован: 19.10.2016

Что-то гугел про STM8005C6T6 ничего не знает. Я у нескольких продавцов вглядывался в мутнофотки... То ли 005, то ли 003... Но, так как не разбираюсь в СТМ-ках - ничего так и не выглядел. 

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

S пропустил - STM8S005C6T6

https://www.st.com/en/microcontrollers/stm8s005c6.html

dim5555
Offline
Зарегистрирован: 12.01.2019

Mожет кому-то поможет.Mне помогло в понимании кода http://startingelectronics.org/tutorials/arduino/arduino-MEGA-24-output-web-server/

sadman41
Offline
Зарегистрирован: 19.10.2016

Лучше про девайс с алиэкспресс поведайте - чего он и как.

dim5555
Offline
Зарегистрирован: 12.01.2019

девайс уже оплачен и покинул китай . едет почтой финляндии . как приедет - протестирую и отпишусь в этой теме.

sadman41
Offline
Зарегистрирован: 19.10.2016

Posti Finland..  ждем в гости через месяц ))

dim5555
Offline
Зарегистрирован: 12.01.2019

посылку получил. работает стабильно. питание платы 5 вольт.  16 каналов выходных. управляемый выход 3.3 вольта положительной полярности. 

sadman41
Offline
Зарегистрирован: 19.10.2016

МК - STM? Какие буквы написаны на ём?