Advertisement
joeybab3

Arduinocode 12/8/13

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