Professional Documents
Culture Documents
Include
Include
h>
#include <SPI.h>
#include <EEPROM.h>
byte ip[] = {
byte gateway[] = {
byte subnet[] = {
byte mac[] = {
//Ethernet Port
// This is done in case the relay board triggers the relay on negative, rather then on positive supply
//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 outputAddress[10] = { 22,23,24,25,26,27,28,29,30,31}; //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.
String buttonText[10] = {
"01. Prechauffage","02. Demarrage","03. fenetre 1","04. fenetre 2","05. fenetre 3","06. fenetre 4","07.
porte","08. panne","09. panne","10. panne"};
// Set the output to retain the last status after power recycle.
int retainOutputStatus[10] = {1,0,0,0,1,1,1,1,1,1};//1-retain the last status. 0-will be off after power cut.
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//VARIABLES DECLARATION
////////////////////////////////////////////////////////////////////////
int outp = 0;
//EthernetClient client;
int fusState=0;
void setup(){
Serial.begin(9600);
pinMode(tab,INPUT);
pinMode(ou1, OUTPUT);
initEepromValues();
readEepromValues();
pinMode(outputAddress[var], OUTPUT);
//digitalWrite(outputAddress[var], HIGH);
digitalWrite(outputAddress[var], currentState);
else{
//digitalWrite(outputAddress[var], LOW);
digitalWrite(outputAddress[var], currentState);
//Setting up the IP address. Comment out the one you dont need.
Ethernet.begin(mac, ip, gateway, subnet); //for manual setup. (Address is the one configured above.)
server.begin();
Serial.println(Ethernet.localIP());
////////////////////////////////////////////////////////////////////////
//LOOP
////////////////////////////////////////////////////////////////////////
//Run once
void loop(){
checkForClient();
void checkForClient(){
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if(c == '*'){
printHtmlHeader(client); //call for html header and css
printLoginTitle(client);
printHtmlFooter(client);
//sentHeader = true;
break;
if(!sentHeader){
sentHeader = true;
// char c = client.read();
reading = false;
if(c == '?') {
}
// if there was user input switch the relevant output
if(reading){
if(c == 'H') {
outp = 1;
if(c == 'L') {
outp = 0;
//Serial.print(outp);
//Serial.print('\n');
switch (c) {
case '0':
break;
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
//printHtml(client);
break;
case '6':
break;
case '7':
break;
case '8':
break;
case '9':
break;
printLastCommandOnce = true;
printButtonMenuOnce = true;
triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any
outputs
break;
else
writeToEeprom = false;
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);
}
readOutputStatuses();
if (printButtonMenuOnce == true){
printHtmlButtons(client);
printButtonMenuOnce = false;
////////////////////////////////////////////////////////////////////////
//printHtmlButtons Function
////////////////////////////////////////////////////////////////////////
client.println("");
//client.println("<p>");
client.println("<FORM>");
int x=0;
fusState =digitalRead(tab);
if(fusState == LOW)
digitalWrite(ou1, HIGH);
else
{ digitalWrite(ou1, LOW);x=1;break;}
if(x==1)
client.print("<tr>\n");
client.print("<td><h4>");
client.print("prob de fus");
client.print("</h4></td>\n");
client.print("<td></td>");
client.print("<td>");
client.print("<h3>");
client.print(" °C</h3></td>\n");
client.print("<td></td>");
client.print("</tr>");
else{
client.print("<tr>\n");
client.print("<td><h4>");
client.print("pas de prob");
client.print("</h4></td>\n");
client.print("<td></td>");
client.print("<td>");
client.print("<h3>");
client.print(" °C</h3></td>\n");
client.print("<td></td>");
client.print("</tr>");
allOn += "H";
allOn += outputAddress[var];
allOff += "L";
allOff += outputAddress[var];
client.print("<tr>\n");
client.print("<td><h4>");
client.print(buttonText[var]);
client.print("</h4></td>\n");
client.print("<td>");
//client.print(buttonText[var]);
//client.print(buttonText[var]);
client.print("\" onClick=\"parent.location='/?H");
client.print(var);
client.print("'\"></td>\n");
//client.print(var);
client.print("\" onClick=\"parent.location='/?L");
client.print(var);
client.print("'\"></td>\n");
client.print("</tr>\n");
if (switchOnAllPinsButton == true ){
client.print("\" onClick=\"parent.location='/?");
client.print(allOn);
client.print("'\"></td>\n");
client.print("\" onClick=\"parent.location='/?");
client.print(allOff);
client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");
client.println("</table>");
client.println("</FORM>");
//client.println("</p>");
////////////////////////////////////////////////////////////////////////
//readOutputStatuses Function
////////////////////////////////////////////////////////////////////////
void readOutputStatuses(){
outputStatus[var] = digitalRead(outputAddress[var]);
//Serial.print(outputStatus[var]);
////////////////////////////////////////////////////////////////////////
//readEepromValues Function
////////////////////////////////////////////////////////////////////////
void readEepromValues(){
outputStatus[adr] = EEPROM.read(adr);
////////////////////////////////////////////////////////////////////////
//writeEepromValues Function
////////////////////////////////////////////////////////////////////////
void writeEepromValues(){
EEPROM.write(adr, outputStatus[adr]);
////////////////////////////////////////////////////////////////////////
//initEepromValues Function
////////////////////////////////////////////////////////////////////////
//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(){
////////////////////////////////////////////////////////////////////////
//htmlHeader Function
////////////////////////////////////////////////////////////////////////
timeConnectedAt = millis(); //Record the time when last page was served.
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<head>");
client.println("<title>Master SIE</title>");
client.print(refreshPage);
client.println("; url=/\">");
client.println("<style type=\"text/css\">");
client.println("");
client.println(" }");
client.println("");
client.println("body {");
client.println(" background-image:");
client.println(" -webkit-gradient(linear, left top, right top,");
client.println(" }");
client.println("");
client.println(".view {");
client.println(" }");
client.println("");
client.println(".header-wrapper {");
client.println(" background-image:");
client.println(" from(rgba(255,255,255,.4)),");
client.println(" from(transparent),");
client.println(" }");
client.println("");
client.println(".header-wrapper h1 {");
client.println(" }");
client.println("");
client.println(".group-wrapper {");
client.println(" }");
client.println("");
client.println(".group-wrapper h2 {");
client.println(" }");
client.println("");
client.println(".group-wrapper h3 {");
client.println(" }");
client.println("");
client.println(" }");
client.println("");
client.println(" margin-left:auto;");
client.println(" margin-right:auto;");
client.println(" -moz-transform :scale(1);"); //Code for Mozilla Firefox
client.println(" }");
client.println("");
client.println(".green-circle {");
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("");
client.println(".black-circle {");
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("");
client.println(" }");
client.println("");
//and finally this is the end of the style data and header
client.println("</style>");
client.println("</head>");
client.println("<body>");
client.println("<div class=\"view\">");
client.println(" </div>");
//////
} //end of htmlHeader
////////////////////////////////////////////////////////////////////////
//htmlFooter Function
////////////////////////////////////////////////////////////////////////
printLastCommandOnce = false;
printButtonMenuOnce = false;
allOn = "";
allOff = "";
client.println("\n<h3 align=\"center\">© sujet smart car <br> fes - fevrier - 2019 - ");
client.println(rev);
client.println("</h3></div>\n</div>\n</body>\n</html>");
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
////////////////////////////////////////////////////////////////////////
client.println("<div class=\"group-wrapper\">");
client.println(" <h2>Switch the required output.</h2>");
client.println();
////////////////////////////////////////////////////////////////////////
//printLoginTitle Function
////////////////////////////////////////////////////////////////////////
// client.println("<div class=\"group-wrapper\">");
client.println();