Advertisement
joeybab3

arduicode 12/8/13 v2

Dec 8th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 33.73 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. //ETHERNET SWITCH PROGRAM//FEED THA FISSIES                           //
  3. ////////////////////////////////////////////////////////////////////////
  4. #include <String.h>                                                   //
  5. #include <Ethernet.h>                                                 //
  6. #include <SPI.h>                                                      //
  7. #include <EEPROM.h>                                                   //
  8. #include <OneWire.h>                                                  //
  9. #include <DallasTemperature.h>                                        //
  10. #include <Wire.h>                                                     //
  11. #include <DS1307new.h>                                                //
  12. #define ONE_WIRE_BUS 2                                                //
  13. #define TEMPERATURE_PRECISION 12                                      //
  14. ////////////////////////////////////////////////////////////////////////
  15. //CONFIGURATION//                                                     //
  16. ////////////////////////////////////////////////////////////////////////
  17. //IP manual settings
  18. byte ip[] = {
  19.   192, 168, 1, 150 };   //Manual setup only LOOK FOR FORM ACTION @ END OF CODE
  20. byte gateway[] = {
  21.   192, 168, 1, 1 }; //Manual setup only GATEWAY
  22. byte subnet[] = {
  23.   255, 255, 255, 0 }; //Manual setup only SUBNET
  24.  
  25. // if need to change the MAC address (Very Rare)
  26. byte mac[] = {
  27.   0xFE, 0xED, 0xFE, 0xED, 0xFE, 0xED };
  28.  
  29. //Ethernet Port
  30. EthernetServer server = EthernetServer(3339); //default html port 80
  31.  
  32. //The number of outputs going to be switched.
  33. int outputQuantity = 16;  //should not exceed 10
  34.  
  35. //Invert the output of the leds
  36. boolean outputInverted = true; //true or false
  37. // This is done in case the relay board triggers the relay on negative, rather then on positive supply
  38.  
  39. //Html page refresh
  40. int refreshPage = 30; //default is 10sec.
  41. //Beware that if you make it refresh too fast, the page could become FROZEN.
  42.  
  43. //Display or hide the "Switch on all Pins" buttons at the bottom of page
  44. int switchOnAllPinsButton = true; //true or false
  45.  
  46. OneWire oneWire(ONE_WIRE_BUS);
  47.  
  48. // Pass our oneWire reference to Dallas Temperature.
  49. DallasTemperature sensors(&oneWire);
  50. //DeviceAddress insideThermometer, outsideThermometer;
  51. // arrays to hold device addresses
  52. DeviceAddress insideThermometer= {
  53.   0x28, 0xA4, 0x0E, 0x75, 0x04, 0x00, 0x00, 0x8B };
  54. DeviceAddress outsideThermometer= {
  55.   0x28, 0x49, 0xAC, 0x74, 0x04, 0x00, 0x00, 0xD7 };
  56. ////////////////////////////////////////////////////////////////////////
  57. int sensorPin = 0;           // Input pin for the photocell           //
  58. int ledPin = 22;             // Select the pin for the LED            //
  59. int sensorValue = 0;         // Value coming from the sensor          //
  60. int night = 0;               // Enabled                               //
  61. int nightValue = 750;        // Trigger                               //
  62. int led = 32;                //                                       //
  63. int noData = 2;              //                                       //
  64. ////////////////////////////////////////////////////////////////////////
  65. //Button Array
  66. //Just for a note, varables start from 0 to 9, as 0 is counted as well, thus 10 outputs.
  67. // Select the pinout address
  68.  
  69. byte outputAddress[8] = {
  70.   22,23,24,25,26,27,28,29}; //Allocate 10 spaces and name the output pin address.
  71. byte outputAddress2[8]= {
  72.   30,31,32,33,34,35,36,37};
  73. //PS pin addresses 10, 11, 12 and 13 on the Duemilanove are used for the ethernet shield, therefore cannot be used.
  74. //PS pin addresses 10, 50, 51 and 52 and 53 on the Mega are used for the ethernet shield, therefore cannot be used.
  75. //PS pin addresses 4, are used for the SD card, therefore cannot be used.
  76. //PS. pin address 2 is used for interrupt-driven notification, therefore could not be used.
  77.  
  78. // Write the text description of the output channel
  79. String buttonText[16] = {            //                               //
  80.   "01. Everything","02. Filter","03. Pump","04. Colorful lighting",   //
  81. "05. Heater","06. Auto Day Night Cycle","07. Used For Cycle",         //
  82. "08. Other","09. Other","10. Other","11. Other","12. Other",          //
  83. "13. Other","14. Other","15. Other","16. Other"};                     //
  84. // Set the output to retain the last status after power recycle.
  85. int retainOutputStatus[16] = {
  86.   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.
  87.  
  88. ////////////////////////////////////////////////////////////////////////
  89.  
  90. ////////////////////////////////////////////////////////////////////////
  91. //VARIABLES DECLARATION
  92. ////////////////////////////////////////////////////////////////////////
  93.  
  94. boolean printLastCommandOnce = false;
  95. boolean printButtonMenuOnce = false;
  96. boolean initialPrint = true;
  97. String allOn = "";
  98. String allOff = "";
  99. boolean reading = false;
  100. boolean outputStatus[8]; //Create a boolean array for the maximum ammount.
  101. boolean outputStatus2[8]; // relays 9-16
  102. unsigned long timeConnectedAt;
  103. boolean writeToEeprom = false;
  104. int outp =0;
  105. float tempI = 0.0;
  106. float tempO = 0.0;
  107. int boxX = 0;
  108. int boxY = 53;
  109. int boxHeight = 11;
  110. int boxWidth = 128;
  111. String readString; //
  112. boolean login=false;
  113.  
  114.  
  115. float newRange = 10; //height of the frame for histogram
  116. ////////////////////////////////////////////////////////////////////////
  117. //RUN ONCE
  118. ////////////////////////////////////////////////////////////////////////
  119. //Beginning of Program
  120. void setup(){
  121.   Serial.begin(9600);
  122.   initEepromValues();
  123.   readEepromValues();
  124.  
  125.   //Set pins as Outputs
  126.   boolean currentState = false;
  127.   for (int var = 0; var < 9; var++){
  128.     digitalWrite(outputAddress[var], HIGH);
  129.     pinMode(outputAddress[var], OUTPUT);
  130.  
  131.   }
  132.   for (int var2 = 0; var2 < 9; var2++){
  133.  
  134.     pinMode(outputAddress2[var2], OUTPUT);
  135.     digitalWrite(outputAddress2[var2], HIGH);
  136.   }
  137.  
  138.  
  139.   //Setting up the IP address. Comment out the one you dont need.
  140.   //Ethernet.begin(mac); //for DHCP address. (Address will be printed to serial.)
  141.   Ethernet.begin(mac); //setup. (Address is the one configured above.)
  142.   server.begin();
  143.   Serial.print("Server is at ");
  144.   Serial.println(Ethernet.localIP());
  145.   sensors.begin();
  146.  
  147.   if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for fis");
  148.   if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for room");
  149.  
  150.   sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  151.   sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
  152.  
  153. }
  154.  
  155.  
  156. ////////////////////////////////////////////////////////////////////////
  157. //LOOP//RUNS AGAIN AND AGAIN//
  158. ////////////////////////////////////////////////////////////////////////
  159. //LIGHT SENSOR READING//
  160. ////////////////////////////////////////
  161. void loop(){                          //
  162.   if (night > 0)                      //
  163.     if (sensorValue < nightValue){    //
  164.       digitalWrite(ledPin, HIGH);     //
  165.     }else{                            //
  166.     digitalWrite(ledPin,LOW);         //
  167.     }                                 //
  168.   sensorValue = analogRead(sensorPin);//
  169. ////////////////////////////////////////
  170.   //Serial.println(lcdrelay1);
  171.   sensors.requestTemperatures();  
  172.  
  173.   printTemperature(insideThermometer);
  174.   //Serial.println(tempI);
  175.   printTemperature2(outsideThermometer);
  176.   //Serial.println(tempO);
  177.  
  178.   // listen for incoming clients, and process requests.
  179.   checkForClient();
  180.  
  181. }
  182.  
  183. ////////////////////////////////////////////////////////////////////////
  184. //checkForClient Function
  185. ////////////////////////////////////////////////////////////////////////
  186. void checkForClient(){
  187.  
  188.   EthernetClient client = server.available();
  189.  
  190.   if (client) {
  191.  
  192.     // an http request ends with a blank line
  193.     boolean currentLineIsBlank = true;
  194.     boolean sentHeader = false;
  195.     boolean login = false;
  196.  
  197.     while (client.connected()) {
  198.       if (client.available()) {
  199.         //if header was not set send it
  200.  
  201.         //read user input
  202.         char c = client.read();                            //
  203.         readString.concat(c);
  204.         if(c == '*'){
  205.  
  206.           printHtmlHeader(client); //call for html header and css
  207.           printLoginTitle(client);
  208.           printHtmlFooter(client);
  209.           //sentHeader = true;
  210.           login=false;
  211.           break;
  212.         }
  213.  
  214.         if(!sentHeader){
  215.  
  216.           printHtmlHeader(client); //call for html header and css
  217.           printHtmlButtonTitle(client); //print the button title
  218.  
  219.           //This is for the arduino to construct the page on the fly.
  220.           sentHeader = true;
  221.         }
  222.  
  223.         //if there was reading but is blank there was no reading
  224.         if(reading && c == ' '){
  225.           reading = false;
  226.           login=false;
  227.  
  228.         }
  229.         if(c == '?') {
  230.           reading = true; //found the ?, begin reading what comes after
  231.  
  232.  
  233.         }
  234.         if (login==false) {
  235.             if(readString.indexOf("User=joey&Pass=pass") > 0) {//Password and Username
  236.               login=true;
  237. //              client.print("GET /writetemplocalserv.php?t0=");
  238. //              client.print(sensorValue);
  239. //              client.println(" HTTP/1.1");
  240. //              client.println(""); //mandatory blank line
  241.             }else;
  242.             if(readString.indexOf("User=guest&Pass=password") > 0) {//Password and Username
  243.               login=true;
  244.             }
  245.           }
  246.  
  247.         //if there is a ? there was user input
  248.  
  249.  
  250.         // if there was user input switch the relevant output
  251.         if(login && reading){
  252.  
  253.           //if user input is H set output to 1
  254.           if(c == 'H') {
  255.             outp = 1;
  256.           }
  257.  
  258.           //if user input is L set output to 0
  259.           if(c == 'L') {
  260.             outp = 0;
  261.           }
  262.            //print the value of c to serial communication
  263.           Serial.print(outp);
  264.           Serial.print('\n');
  265.  
  266.           switch (c) {
  267.  
  268.           case '0':
  269.             //add code here to trigger on 0
  270.             triggerPin(outputAddress[0], client, outp);
  271.             break;            
  272.           case '1':
  273.             //add code here to trigger on 1
  274.             triggerPin(outputAddress[1], client, outp);
  275.             break;            
  276.           case '2':
  277.             //add code here to trigger on 2
  278.             triggerPin(outputAddress[2], client, outp);
  279.             break;
  280.           case '3':
  281.             //add code here to trigger on 3
  282.             triggerPin(outputAddress[3], client, outp);
  283.             break;
  284.           case '4':
  285.             //add code here to trigger on 4
  286.             triggerPin(outputAddress[4], client, outp);
  287.             break;
  288.           case '5':
  289.             //add code here to trigger on 5
  290.             night = (outp);
  291.             break;
  292.           case '6':
  293.             //add code here to trigger on 7
  294.             triggerPin(outputAddress[5], client, outp);
  295.             break;
  296.           case '7':
  297.             //add code here to trigger on 6
  298.             triggerPin(outputAddress[6], client, outp);
  299.             break;
  300.           case '8':
  301.             //add code here to trigger on 8
  302.             triggerPin(outputAddress[8], client, outp);
  303.             break;
  304.           case '9':
  305.             // add code here to trigger on 9
  306.             triggerPin(outputAddress[9], client, outp);
  307.             break;
  308.           case 'A':
  309.             triggerPin(outputAddress[10], client, outp);
  310.             break;
  311.           case 'B':
  312.             triggerPin(outputAddress[11], client, outp);
  313.             break;
  314.           case 'C':
  315.             triggerPin(outputAddress[12], client, outp);
  316.             break;
  317.           case 'D':
  318.             triggerPin(outputAddress[13], client, outp);
  319.             break;
  320.           case 'E':
  321.             triggerPin(outputAddress[14], client, outp);
  322.             break;
  323.           case 'F':
  324.             triggerPin(outputAddress[15], client, outp);
  325.             break;
  326.           case 'r':
  327.             digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  328.             break;
  329.           case 'Logout':
  330.             login=false;
  331.             readString="";
  332.             break;
  333.           }
  334.         }
  335.  
  336.         // readString.concat(c);
  337.         //if user input was blank
  338.         if (c == '\n' && currentLineIsBlank){
  339.  
  340.          
  341.           // Serial.print(readString);
  342.      
  343.          
  344.           if(login == false)
  345.           {
  346.  
  347.             printLoginTitle(client);
  348.             printHtmlFooter(client);
  349.             readString="";
  350.  
  351.           }
  352.  
  353.           printLastCommandOnce = true;
  354.           printButtonMenuOnce = true;
  355.           triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs
  356.  
  357.           break;
  358.         }
  359.  
  360.       }
  361.  
  362.     }
  363.  
  364.     printHtmlFooter(client); //Prints the html footer
  365.     //clearing string for next read
  366.     // readString="";
  367.     //stopping client
  368.     //  client.stop();
  369.   }
  370.   else
  371.   {  //if there is no client
  372.  
  373.     //And time of last page was served is more then a minute.
  374.     if (millis() > (timeConnectedAt + 60000)){          
  375.  
  376.       if (writeToEeprom == true){
  377.         writeEepromValues();  //write to EEprom the current output statuses
  378.         Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");
  379.         writeToEeprom = false;
  380.       }
  381.  
  382.     }
  383.   }
  384.  
  385.  
  386. }
  387.  
  388. ////////////////////////////////////////////////////////////////////////
  389. //triggerPin Function
  390. ////////////////////////////////////////////////////////////////////////
  391. //
  392. void triggerPin(int pin, EthernetClient client, int outp){
  393.   //Switching on or off outputs, reads the outputs and prints the buttons  
  394.  
  395.   //Setting Outputs
  396.   if (pin != 777){
  397.  
  398.     if(outp == 1) {
  399.       if (outputInverted ==false){
  400.         digitalWrite(pin, HIGH);
  401.       }
  402.       else{
  403.         digitalWrite(pin, LOW);
  404.       }
  405.     }
  406.     if(outp == 0){
  407.       if (outputInverted ==false){
  408.         digitalWrite(pin, LOW);
  409.       }
  410.       else{
  411.         digitalWrite(pin, HIGH);
  412.       }
  413.     }
  414.   }
  415.   //Refresh the reading of outputs
  416.   readOutputStatuses();
  417.  
  418.  
  419.   //Prints the buttons
  420.   if (printButtonMenuOnce == true){
  421.     printHtmlButtons(client);
  422.     printButtonMenuOnce = false;
  423.   }
  424.  
  425. }
  426.  
  427. ////////////////////////////////////////////////////////////////////////
  428. //printHtmlButtons Function
  429. ////////////////////////////////////////////////////////////////////////
  430. //print the html buttons to switch on/off channels
  431. void printHtmlButtons(EthernetClient client){
  432.  
  433.   //Start to create the html table
  434.   client.println("");
  435.   //client.println("<p>");
  436.   //LOGOUT
  437.   //client.print("<h2><a href='/?Logout'>Logout</a>");
  438.   client.print("<h3 align=\"center\"><input type=button onClick=\"location.href='/?Logout'\" value='Logout'></h3>");
  439.   client.println("<table border=\"0\" align=\"center\">");
  440.   client.print("<tr>\n");
  441.   client.print("<td><h4>");
  442.   client.println("<iframe frameborder=\"0\" seamless=\"seamless\" src=\"http://loachcam.joeybabcock.me\" width=\"565\" height=\"360\" scrolling=\"no\">");
  443.   client.println("</iframe>");
  444.  
  445.  
  446.   client.print("<td></td>");
  447.   client.print("</tr>");
  448.   client.println("<FORM>");
  449.   client.println("<table border=\"0\" align=\"center\">");
  450.  
  451.  
  452.   //Printing the Temperature
  453.   client.print("<tr>\n");        
  454.  
  455.   client.print("<td><h4>");
  456.   client.print("Temperature(fis, room)");
  457.   client.print("</h4></td>\n");
  458.   client.print("<td></td>");            
  459.   client.print("<td>");
  460.   client.print("<h3>");
  461.   client.print("(fis)");
  462.   client.print(tempI);
  463.   client.print(" &deg;F");
  464.   client.print("<br>");
  465.   client.print("(room)");
  466.   client.print(tempO);
  467.   client.print(" &deg;F</h3></td>\n");
  468.  /////////////////////////////////////////////
  469. //LIGHT SENSOR PRINTING//                    //
  470. //////////////////////////////////////////////
  471.   client.print("<td></td>");                //
  472.   client.print("</tr>");                    //
  473.   client.print("<tr>\n");                   //
  474.   client.print("<td><h4>");                 //
  475.   client.print("Light Reading(");           //
  476.   client.print(sensorValue);                //
  477.   client.print("/ 1024)");                  //
  478.   client.print("</h4></td>\n");             //
  479.   client.print("<td></td>");                //
  480.   client.print("<td>");                     //
  481.   client.print("<h3>Set to go off at (");   //
  482.   client.print(nightValue);                 //
  483.   client.print(")");                        //
  484.   client.print("<br>");                     //
  485.     if (sensorValue < nightValue)
  486.     {    //
  487.      client.print("(");                        //
  488.      client.print(nightValue - sensorValue);   //
  489.      client.print(" More to go!)</h3></td>\n");//     //
  490.     }
  491.     else if (sensorValue < 10)
  492.     {
  493.      client.print("(");                        //
  494.      client.print("NO DATA!!");
  495.      client.print("!)</h3></td>\n");//
  496.     }  
  497.     else
  498.     {
  499.      client.print("(");                        //
  500.      client.print(sensorValue - nightValue);   //
  501.      client.print(" Until off!)</h3></td>\n");//  
  502.     } //
  503.  /////////////////////////////////////////////
  504.  
  505.  
  506.   client.print("<td></td>");
  507.   client.print("</tr>");
  508.  
  509.  
  510.   //Start printing button by button
  511.   for (int var = 0; var < outputQuantity; var++)  {      
  512.  
  513.     //set command for all on/off
  514.     allOn += "H";
  515.     allOn += outputAddress[var];
  516.     allOff += "L";
  517.     allOff += outputAddress[var];
  518.  
  519.  
  520.  
  521.     //Print begining of row
  522.     client.print("<tr>\n");        
  523.  
  524.     //Prints the button Text
  525.     client.print("<td><h4>");
  526.     client.print(buttonText[var]);
  527.     client.print("</h4></td>\n");
  528.  
  529.     //Prints the ON Buttons
  530.     client.print("<td>");
  531.     //client.print(buttonText[var]);
  532.     client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
  533.     //client.print(buttonText[var]);
  534.     client.print("\" onClick=\"parent.location='/?H");
  535.     //Serial.print(var, HEX);
  536.     client.print(var, HEX);
  537.     client.print("'\"></td>\n");
  538.  
  539.     //Prints the OFF Buttons
  540.     client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
  541.     //client.print(var);
  542.     client.print("\" onClick=\"parent.location='/?L");
  543.     // Serial.print(var, HEX);
  544.     client.print(var, HEX);
  545.     client.print("'\"></td>\n");
  546.  
  547.  
  548.     //Print first part of the Circles or the LEDs
  549.  
  550.     //Invert the LED display if output is inverted.
  551.  
  552.     if (outputStatus[var] == true ){                                                            //If Output is ON
  553.       if (outputInverted == false){                                                             //and if output is not inverted
  554.         client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED
  555.       }
  556.       else{                                                                                    //else output is inverted then
  557.         client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
  558.       }
  559.     }
  560.     else                                                                                      //If Output is Off
  561.     {
  562.       if (outputInverted == false){                                                           //and if output is not inverted
  563.         client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED
  564.       }
  565.       else{                                                                                   //else output is inverted then
  566.         client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED                    
  567.       }
  568.     }  
  569.     //Print end of row
  570.     client.print("</tr>\n");  
  571.   }
  572.  
  573.   //Display or hide the Print all on Pins Button
  574.   if (switchOnAllPinsButton == true ){
  575.  
  576.     //Prints the ON All Pins Button
  577.     client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");
  578.     client.print("\" onClick=\"parent.location='/?");
  579.     client.print(allOn);
  580.     client.print("'\"></td>\n");
  581.  
  582.     //Prints the OFF All Pins Button            
  583.     client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");
  584.     client.print("\" onClick=\"parent.location='/?");
  585.     client.print(allOff);
  586.     client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
  587.   }
  588.   //Closing the table and form
  589.   client.println("</table>");
  590.   client.println("</FORM>");
  591.   //client.println("</p>");
  592.  
  593. }
  594.  
  595. ////////////////////////////////////////////////////////////////////////
  596. //readOutputStatuses Function
  597. ////////////////////////////////////////////////////////////////////////
  598. //Reading the Output Statuses
  599. void readOutputStatuses(){
  600.   for (int var = 0; var < outputQuantity; var++)  {
  601.     outputStatus[var] = digitalRead(outputAddress[var]);
  602.     outputStatus2[var] = digitalRead(outputAddress2[var]);
  603.     //Serial.print(outputStatus[var]);
  604.   }
  605.   // for (int var = 0; var < outputQuantity; var++)  {
  606.   //  outputStatus2[var] = digitalRead(outputAddress2[var]);
  607.   //  Serial.print(outputStatus2[var]);
  608.  
  609.   // }
  610.  
  611. }
  612.  
  613. ////////////////////////////////////////////////////////////////////////
  614. //readEepromValues Function
  615. ////////////////////////////////////////////////////////////////////////
  616. //Read EEprom values and save to outputStatus
  617. void readEepromValues(){
  618.   for (int adr = 0; adr < outputQuantity; adr++)  {
  619.     outputStatus[adr] = EEPROM.read(adr);
  620.   }
  621. }
  622.  
  623. ////////////////////////////////////////////////////////////////////////
  624. //writeEepromValues Function
  625. ////////////////////////////////////////////////////////////////////////
  626. //Write EEprom values
  627. void writeEepromValues(){
  628.   for (int adr = 0; adr < outputQuantity; adr++)  {
  629.     EEPROM.write(adr, outputStatus[adr]);
  630.   }
  631.  
  632. }
  633.  
  634. ////////////////////////////////////////////////////////////////////////
  635. //initEepromValues Function
  636. ////////////////////////////////////////////////////////////////////////
  637. //Initialiaze EEprom values
  638. //if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0
  639. void initEepromValues(){
  640.   for (int adr = 0; adr < outputQuantity; adr++){        
  641.     if (EEPROM.read(adr) > 1){
  642.       EEPROM.write(adr, 0);
  643.     }
  644.  
  645.   }
  646.  
  647. }
  648.  
  649. void printTemperature(DeviceAddress deviceAddress)
  650. {
  651.   tempI =sensors.getTempF(deviceAddress);
  652. }
  653. void printTemperature2(DeviceAddress deviceAddress)
  654. {
  655.   tempO = sensors.getTempF(deviceAddress);
  656. }
  657.  
  658.  
  659. ////////////////////////////////////////////////////////////////////////
  660. //htmlHeader Function
  661. ////////////////////////////////////////////////////////////////////////
  662. //Prints html header
  663. void printHtmlHeader(EthernetClient client){
  664.   // Serial.print("Serving html Headers at ms -");
  665.   timeConnectedAt = millis(); //Record the time when last page was served.
  666.   // Serial.print(timeConnectedAt); // Print time for debbugging purposes
  667.   writeToEeprom = true; // page loaded so set to action the write to eeprom
  668.  
  669.   // send a standard http response header          //
  670.   client.println("HTTP/1.1 200 OK");
  671.   client.println("Content-Type: text/html");
  672.   client.println("Connnection: close");
  673.   client.println();
  674.   client.println("<!DOCTYPE HTML>");
  675.   client.println("<head>");
  676.   client.println("<title>Fis Tank</title>");
  677.   client.println("<meta name=\"description\" content=\"Fis tank\"/>");
  678.  
  679.   // add a meta refresh tag, so the browser pulls again every x seconds:
  680.   client.print("<meta http-equiv=\"refresh\" content=\"");
  681.   client.print(refreshPage);
  682.   client.println("; url=/\">");
  683.  
  684.   // add other browser configuration
  685.   client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
  686.   client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");
  687.   client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");          
  688.  
  689.   //inserting the styles data, usually found in CSS files.
  690.   client.println("<style type=\"text/css\">");
  691.   client.println("");
  692.  
  693.   //This will set how the page will look graphically
  694.   client.println("html { height:100%; }");  
  695.  
  696.   client.println("  body {");
  697.   client.println("    height: 100%;");
  698.   client.println("    margin: 0;");
  699.   client.println("    font-family: helvetica, sans-serif;");
  700.   client.println("    -webkit-text-size-adjust: none;");
  701.   client.println("   }");
  702.   client.println("");
  703.   client.println("body {");
  704.   client.println("    -webkit-background-size: 100% 21px;");
  705.   client.println("    background-color: #c5ccd3;");
  706.   client.println("    background-image:");
  707.   client.println("    -webkit-gradient(linear, left top, right top,");
  708.   client.println("    color-stop(.75, transparent),");
  709.   client.println("    color-stop(.75, rgba(255,255,255,.1)) );");
  710.   client.println("    -webkit-background-size: 7px;");
  711.   client.println("   }");
  712.   client.println("");
  713.   client.println(".view {");
  714.   client.println("    min-height: 100%;");
  715.   client.println("    overflow: auto;");
  716.   client.println("   }");
  717.   client.println("");
  718.   client.println(".header-wrapper {");
  719.   client.println("    height: 44px;");
  720.   client.println("    font-weight: bold;");
  721.   client.println("    text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");
  722.   client.println("    border-top: solid 1px rgba(255,255,255,0.6);");
  723.   client.println("    border-bottom: solid 1px rgba(0,0,0,0.6);");
  724.   client.println("    color: #fff;");
  725.   client.println("    background-color: #8195af;");
  726.   client.println("    background-image:");
  727.   client.println("    -webkit-gradient(linear, left top, left bottom,");
  728.   client.println("    from(rgba(255,255,255,.4)),");
  729.   client.println("    to(rgba(255,255,255,.05)) ),");
  730.   client.println("    -webkit-gradient(linear, left top, left bottom,");
  731.   client.println("    from(transparent),");
  732.   client.println("    to(rgba(0,0,64,.1)) );");
  733.   client.println("    background-repeat: no-repeat;");
  734.   client.println("    background-position: top left, bottom left;");
  735.   client.println("    -webkit-background-size: 100% 21px, 100% 22px;");
  736.   client.println("    -webkit-box-sizing: border-box;");
  737.   client.println("   }");
  738.   client.println("");
  739.   client.println(".header-wrapper h1 {");
  740.   client.println("    text-align: center;");
  741.   client.println("    font-size: 20px;");
  742.   client.println("    line-height: 44px;");
  743.   client.println("    margin: 0;");
  744.   client.println("   }");
  745.   client.println("");
  746.   client.println(".group-wrapper {");
  747.   client.println("    margin: 9px;");
  748.   client.println("    }");
  749.   client.println("");
  750.   client.println(".group-wrapper h2 {");
  751.   client.println("    color: #4c566c;");
  752.   client.println("    font-size: 17px;");
  753.   client.println("    line-height: 0.8;");
  754.   client.println("    font-weight: bold;");
  755.   client.println("    text-shadow: #fff 0 1px 0;");
  756.   client.println("    margin: 20px 10px 12px;");
  757.   client.println("   }");
  758.   client.println("");
  759.   client.println(".group-wrapper h3 {");
  760.   client.println("    color: #4c566c;");
  761.   client.println("    font-size: 12px;");
  762.   client.println("    line-height: 1;");
  763.   client.println("    font-weight: bold;");
  764.   client.println("    text-shadow: #fff 0 1px 0;");
  765.   client.println("    margin: 20px 10px 12px;");
  766.   client.println("   }");
  767.   client.println("");
  768.   client.println(".group-wrapper h4 {");  //Text for description
  769.   client.println("    color: #212121;");
  770.   client.println("    font-size: 14px;");
  771.   client.println("    line-height: 1;");
  772.   client.println("    font-weight: bold;");
  773.   client.println("    text-shadow: #aaa 1px 1px 3px;");
  774.   client.println("    margin: 5px 5px 5px;");
  775.   client.println("   }");
  776.   client.println("");
  777.   client.println(".group-wrapper table {");
  778.   client.println("    background-color: #fff;");
  779.   client.println("    -webkit-border-radius: 10px;");
  780.  
  781.   client.println("    -moz-border-radius: 10px;");
  782.   client.println("    -khtml-border-radius: 10px;");
  783.   client.println("    border-radius: 10px;");
  784.  
  785.  
  786.   client.println("    font-size: 17px;");
  787.   client.println("    line-height: 20px;");
  788.   client.println("    margin: 9px 0 20px;");
  789.   client.println("    border: solid 1px #a9abae;");
  790.   client.println("    padding: 11px 3px 12px 3px;");
  791.   client.println("    margin-left:auto;");
  792.   client.println("    margin-right:auto;");
  793.  
  794.   client.println("    -moz-transform :scale(1);"); //Code for Mozilla Firefox
  795.   client.println("    -moz-transform-origin: 0 0;");
  796.  
  797.  
  798.  
  799.   client.println("   }");
  800.   client.println("");
  801.  
  802.  
  803.   //how the green (ON) LED will look
  804.   client.println(".green-circle {");
  805.   client.println("    display: block;");
  806.   client.println("    height: 23px;");
  807.   client.println("    width: 23px;");
  808.   client.println("    background-color: #FF0000;");
  809.   //client.println("    background-color: rgba(60, 132, 198, 0.8);");
  810.   client.println("    -moz-border-radius: 11px;");
  811.   client.println("    -webkit-border-radius: 11px;");
  812.   client.println("    -khtml-border-radius: 11px;");
  813.   client.println("    border-radius: 11px;");
  814.   client.println("    margin-left: 1px;");
  815.  
  816.   client.println("    background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");
  817.   client.println("    border: 2px solid #ccc;");
  818.   client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
  819.   client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
  820.   client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
  821.  
  822.   client.println("    }");
  823.   client.println("");
  824.  
  825.   //how the black (off)LED will look
  826.   client.println(".black-circle {");
  827.   client.println("    display: block;");
  828.   client.println("    height: 23px;");
  829.   client.println("    width: 23px;");
  830.   client.println("    background-color: #040;");
  831.   client.println("    -moz-border-radius: 11px;");
  832.   client.println("    -webkit-border-radius: 11px;");
  833.   client.println("    -khtml-border-radius: 11px;");
  834.   client.println("    border-radius: 11px;");
  835.   client.println("    margin-left: 1px;");
  836.   client.println("    -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");
  837.   client.println("    -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
  838.   client.println("    box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");
  839.   client.println("    }");
  840.   client.println("");
  841.  
  842.   //this will add the glare to both of the LEDs
  843.   client.println("   .glare {");
  844.   client.println("      position: relative;");
  845.   client.println("      top: 1;");
  846.   client.println("      left: 5px;");
  847.   client.println("      -webkit-border-radius: 10px;");
  848.   client.println("      -moz-border-radius: 10px;");
  849.   client.println("      -khtml-border-radius: 10px;");
  850.   client.println("      border-radius: 10px;");
  851.   client.println("      height: 1px;");
  852.   client.println("      width: 13px;");
  853.   client.println("      padding: 5px 0;");
  854.   client.println("      background-color: rgba(200, 200, 200, 0.25);");
  855.   client.println("      background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");
  856.   client.println("    }");
  857.   client.println("");
  858.  
  859.  
  860.   //and finally this is the end of the style data and header
  861.   client.println("</style>");
  862.   client.println("</head>");
  863.  
  864.   //now printing the page itself
  865.   client.println("<body>");
  866.   client.println("<div class=\"view\">");
  867.  
  868.   //////
  869.  
  870. } //end of htmlHeader
  871.  
  872. ////////////////////////////////////////////////////////////////////////
  873. //htmlFooter Function
  874. ////////////////////////////////////////////////////////////////////////
  875. //Prints html footer
  876. void printHtmlFooter(EthernetClient client){
  877.   //Set Variables Before Exiting
  878.   printLastCommandOnce = false;
  879.   printButtonMenuOnce = false;
  880.   allOn = "";
  881.   allOff = "";
  882.  
  883.   //printing last part of the html
  884.   client.println("\n<h3 align=\"center\">Joeybabcock.me<br> Joeysfishtank<br>(C)Loachcam Softwares All Rights Reserved");
  885.   client.println("</h3></div>\n</div>\n</body>\n</html>");
  886.  
  887.   delay(1); // give the web browser time to receive the data
  888.  
  889.   client.stop(); // close the connection:
  890.  
  891.   //Serial.println(" - Done, Closing Connection.");
  892.  
  893.   delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.
  894.  
  895. } //end of htmlFooter
  896.  
  897.  
  898. ////////////////////////////////////////////////////////////////////////
  899. //printHtmlButtonTitle Function
  900. ////////////////////////////////////////////////////////////////////////
  901. //Prints html button title
  902. void printHtmlButtonTitle(EthernetClient client){
  903.   client.println("<div  class=\"group-wrapper\">");
  904.   client.println("<h2 align=\"center\">Control fissies</h2>");
  905.   client.println();
  906. }
  907.  
  908.  
  909. ////////////////////////////////////////////////////////////////////////
  910. //printLoginTitle Function
  911. ////////////////////////////////////////////////////////////////////////
  912. //Prints html button title
  913. void printLoginTitle(EthernetClient client){
  914.   client.println("<h2 align=\"center\"></h2>");
  915.   client.println("<h2 align=\"center\">Enter Username and Password.</h2>")                                                                                                                                                                                                                                                                            ;
  916. +  client.println(" </div>");
  917.   client.print("<form action='LoachTriggerz/'>"); //change to your IP
  918.   client.print("");
  919.   client.println("    <div class=\"group-wrapper\">");
  920.   client.print("<h2 align=\"center\">Username:</h2>");
  921.   client.print("<h2 align=\"center\"><input name='User' value=''></h2>");
  922.   client.print("<h2 align=\"center\">Password:</h2>");
  923.   client.print("<h2 align=\"center\"><input type='text' name='Pass' value=''></h2>");
  924.   client.print("</div>");
  925.   client.print("<h2 align=\"center\"><input type='submit' value=' Login '></h2>");
  926.   //client.print("<input type='submit' value=' Login '>");
  927.   client.print("<hr /></form><hr />");
  928.   client.println("</head></center>");
  929. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement