What when wrong?
Code: Select all
#include <SPI.h>
#include <Ethernet.h>
#include "IRTemp.h"
#include <Dhcp.h>
#include <Dns.h>
#include <EthernetClient.h>
//ethernet items
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // arduino mac address
byte ip [] = {192, 168, 1, 30}; // arduino ip address
byte vbip[] = {192, 168, 1, 116}; // vera ip address
int vbport = 3480; //vera port
//IR module setup
static const byte PIN_DATA = 2; // Choose any pins you like for these
static const byte PIN_CLOCK = 3;
static const byte PIN_ACQUIRE = 4;
static const TempUnit SCALE = FAHRENHEIT; // Options are CELSIUS, FAHRENHEIT
IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);
int lowTemp = 50;
int highTemp = 90;
String rangeMsg;
float ambientTemperature;
float irTemperature;
int ambientoffset = 3;
int iroffset = 0;
char line1[100];
int okCount = 0;
int lowCount = 0;
int highCount = 0;
int everhl = 0; // only send OK get one time after a hi or lo situation
int alert = 0; // default alert on/off status = OFF 1=ON 0=OFF
String veramsg;
EthernetServer server(80);
void setup() {
//ethernet and com port items
Serial.begin(9600); //start Serial Port
Ethernet.begin(mac, ip); //start ethernet
server.begin(); //start server
EthernetServer Server = EthernetServer(80);
delay(50); //give everyone time to get up to speed
}
void loop() {
delay(2000);
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
while (client.connected()) {
if (client.available()) { // client data available to read
readHeader(client);
if (! pageNameIs("/")) //if this is not the root page stop
{client.stop(); //make sure 4th character is a "/"
return;}
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
//send html website info
client.print("<!doctype html>");
client.print("<html>");
client.print("<head>");
client.print("<title>KJN IR Temperature</title>");
client.print("</head>");
client.print("<body>");
client.print("<body style='background-color:white'>");
client.println("<form method='GET'>");
// auto refresh page every 10 seconds
client.print("<meta http-equiv='refresh' content='30'>");
client.print("KJN IR TEMPERATURE MONITOR");
client.println("<br />");
client.print("(IR = IfraRed sensor)");
client.println("<br><br><br>");
float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
float irTemperature = irTemp.getIRTemperature(SCALE);
//print current ambient temp to client
client.print("Ambient Temperature = ");
client.print(ambientTemperature - ambientoffset);
client.println(" F ");
client.println("<br />");
//print current IR temp to client
client.print("IR Temperature = ");
client.print(irTemperature - iroffset);
client.print(" F ");
client.println("<br>");
client.println(" (page auto refreshs every 30 seconds)");
client.println("<br><br><br>");
//get GET command info
//headerinfo();
//print low IR alarm setting to client
client.print("Low IR Temp Alarm Value = ");
client.print(lowTemp);
client.print(".00 F ");
client.print("<br>");
//print high IR alarm setting to client
client.print("High IR Temp Alarm Value = ");
client.print(highTemp);
client.print(".00 F ");
client.print("<br>");
client.print("<br><br><br>");
//client temp change input
client.print("Enter New Low IR Temp Alarm Value --------");
client.print("<input type='number' name='Lo' min='10' max='300'>");
client.println("<br>");
client.print("(range 10-300)");
client.println("<br><br>");
client.print("Enter New High IR Temp Alarm Value -------");
client.print("<input type='number' name='Hi' min='10' max='300'>");
client.println("<br>");
client.print("(range 10-300)");
client.println("<br>");
//client alert on/off input
client.println("<br>");
client.print("Current alert status = ");
client.println(alert);
client.println("<br>");
client.print("Enter desired Alert Status 1 = ON -- 0 = OFF ");
client.print("<input type='number' name='Al' min='0' max='1'>");
client.println("<br>");
client.print("<input type='submit' value='Submit Change(s)'/>");
} // end if (client.available())
} // end while (client.connected())
delay(1000); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
//read header
void readHeader(EthernetClient client)
{
char ch;
int i = 0;
while (ch != '\n')
{
if (client.available())
{ch = client.read();
line1[i] = ch;
i ++;}
} //end while (ch != '\n')
line1[i] = '\0';
}
boolean pageNameIs(char* name)
{
// page name starts at char pos 4
// ends with space
int i = 4;
char ch = line1[i];
while (ch != ' ' && ch != '\n' && ch != '?')
{
if (name[i - 4] != line1[i])
{
return false;
}
i ++;
ch = line1[i];
}
return true;
}