Finally realized how the ethercard code works and was able to edit your original code. Added 3 more text input boxes to the web page. My code has day and night temperature set points as well as day and night start times. I added a real time clock so it will automatically change the target temp based on the times i set on the web page. Thanks again for the source code, I didn't know what I was getting into when I got the Enc28J60 module.
#include <EtherCard.h>
#include <EEPROM.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
char DayTempTextbox[4]; // Data in text box
char NightTempTextbox[4]; // Data in text box
char DayTimeTextbox[4]; // Data in text box
char NightTimeTextbox[4]; // Data in text box
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0xAA,0xAA,0xAA,0xAA,0xAA,0xAA };
static byte myip[] = { 192,168,1,102 }; //used for static IP
byte Ethernet::buffer[1000];
BufferFiller bfill;
byte TargetTemp = 65;
byte DayTempSP = 70;
byte NightTempSP = 68;
byte DayStartTime = 7;
byte NightStartTime = 20;
byte value;
byte TempSensor = A3;
byte HeatONRelay1 = 3;
byte HeatONRelay2 = 4;
const int numReadings = 15;
byte TempReading[numReadings];
byte TempIndex = 0;
int TempTotal = 0;
byte RoomTemperature = 0;
byte TempDBMax = 71;
byte TempDBMin = 69;
byte TempDeadBandSP = 1;
byte Hour = 12;
byte Minute = 24;
byte Second = 36;
byte Month = 11;
byte Day = 23;
int Year = 2012;
//====================================================================================================
void setup () {
//====================================================================================================
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0);
ether.staticSetup(myip);
Wire.begin();
RTC.begin();
pinMode(HeatONRelay1, OUTPUT); // sets the digital pin as input
pinMode(HeatONRelay2, OUTPUT); // sets the digital pin as input
analogReference(INTERNAL);
DayTempSP = EEPROM.read(0);
NightTempSP = EEPROM.read(1);
DayStartTime = EEPROM.read(2);
NightStartTime = EEPROM.read(3);
}
//====================================================================================================
const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";
const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";
const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";
//====================================================================================================
static word homePage() {
//====================================================================================================
//$D = word data type
//$L = long data type
//$S = c string
//$F = progmem string
//$E = byte from the eeprom.
char* Heatstat;
if ( digitalRead(HeatONRelay1) == HIGH ) {
Heatstat = "On" ; }
else {
Heatstat = "Off"; }
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<!DOCTYPE html>"
"<html><head>"
"<meta http-equiv='refresh' content='10'/>"
"<title>ArduStat</title>"
"<body bgcolor=""#99CCFF"">"
"<center>"
"<hr />"
"Temperature: <b>"
"
"
"<font size=""5"">"
"$D °F</font></b>"
"
"
"Current Target Temperature: <b>"
"$D °F</b>"
"
"
"Heat is <b>$S</b> "
"<hr />"
"Current Temperature Setpoint: <b><font size=""4"">$D °F</font></b>"
"<form><input type=text name=daytemp size=4> <input type=submit value=Ok> </form>"
"Current Start Time: <b><font size=""4"">$D</font></b>"
"<form><input type=text name=daytime size=4> <input type=submit value=Ok> </form>"
"Current Temperature Setpoint: <b><font size=""4"">$D °F</font></b>"
"<form><input type=text name=nighttemp size=4> <input type=submit value=Ok> </form>"
"Current Start Time: <b><font size=""4"">$D</font></b>"
"<form><input type=text name=nighttime size=4> <input type=submit value=Ok> </form>"
"<hr />"
"Date: $D/$D/$D Time: $D:$D:$D "
"</center></body></html>"),
RoomTemperature, TargetTemp, Heatstat, DayTempSP, DayStartTime, NightTempSP, NightStartTime, Month, Day, Year, Hour, Minute, Second );
return bfill.position();
}
//====================================================================================================
void loop () {
//====================================================================================================
DateTime now = RTC.now();
Month = now.month();
Day = now.day();
Year = now.year();
Hour = now.hour();
Minute = now.minute();
Second = now.second();
TempTotal = TempTotal - TempReading[TempIndex];
TempReading[TempIndex] = ((analogRead(TempSensor)/9.31)-3);
TempTotal = TempTotal + TempReading[TempIndex];
TempIndex = TempIndex + 1;
if (TempIndex >= numReadings) {
TempIndex = 0; }
RoomTemperature = TempTotal / numReadings;
if ((Hour >= DayStartTime) & (Hour < NightStartTime)) {
TargetTemp = DayTempSP; }
if ((Hour >= NightStartTime) | (Hour < DayStartTime)) {
TargetTemp = NightTempSP; }
TempDBMin = (TargetTemp - TempDeadBandSP);
TempDBMax = (TargetTemp + TempDeadBandSP);
if (RoomTemperature < TempDBMin) {
digitalWrite(HeatONRelay1, HIGH);
digitalWrite(HeatONRelay2, HIGH); }
if (RoomTemperature > TempDBMax) {
digitalWrite(HeatONRelay1, LOW);
digitalWrite(HeatONRelay2, LOW); }
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) {
delay(1); // necessary for my system //TODO
bfill = ether.tcpOffset();
char *data = (char *) Ethernet::buffer + pos;
if (strncmp("GET /", data, 5) != 0) {
bfill.emit_p(http_Unauthorized); }
else {
data += 5;
if (data[0] == ' ') {
homePage(); }
else if (strncmp( "?daytemp=" , data , 8 ) == 0) {
if (ether.findKeyVal(data + 1, DayTempTextbox , sizeof DayTempTextbox , "daytemp") > 0) {
value = atoi(DayTempTextbox); // command to convert a string to number
if ((value >= 55) & (value <= 80)) {
DayTempSP = value;
EEPROM.write(0, value); }
}
bfill.emit_p(http_Found);
}
else if (strncmp( "?daytime=" , data , 8 ) == 0) {
if (ether.findKeyVal(data + 1, DayTimeTextbox , sizeof DayTimeTextbox , "daytime") > 0) {
value = atoi(DayTimeTextbox); // command to convert a string to number
if ((value > 0) & (value <= 24)) {
DayStartTime = value;
EEPROM.write(2, value); }
}
bfill.emit_p(http_Found);
}
else if (strncmp( "?nighttemp=" , data , 10 ) == 0) {
if (ether.findKeyVal(data + 1, NightTempTextbox , sizeof NightTempTextbox , "nighttemp") > 0) {
value = atoi(NightTempTextbox); // command to convert a string to number
if ((value >= 55) & (value <= 80)) {
NightTempSP = value;
EEPROM.write(1, value); }
}
bfill.emit_p(http_Found);
}
else if (strncmp( "?nighttime=" , data , 10 ) == 0) {
if (ether.findKeyVal(data + 1, NightTimeTextbox , sizeof NightTimeTextbox , "nighttime") > 0) {
value = atoi(NightTimeTextbox); // command to convert a string to number
if ((value > 0) & (value <= 24)) {
NightStartTime = value;
EEPROM.write(3, value); }
}
bfill.emit_p(http_Found);
}
ether.httpServerReply(bfill.position());
}
}
}
webpage: