I seem to be having some problems getting my basic webserver sketch working. I have included it into a datalogging and differential control system for solar hot water which works well on its own (Thanks to all the coders from whom I have plagiarised much of the script).
When the webserver script is included the relay pin 7 stops going high and I am unable to access the mega via ip address (mega connected to wireless router).
Not sure if it may be an issue with lines in "setup" ie do I need to bring pin 53 low again to use w5100 chip and if so where.
// Initialize sd card
pinMode(53, OUTPUT); // set the SS pin as an output (necessary!) pin 53 on mega
digitalWrite(53, HIGH); // but turn off the W5100 chip!
When I plug mega into router there appears to be a lot of activity and the router indicates that it has a wired connection.
Below is some of loop part of code, hopefully someone will be able to make sense of it.
void loop ()
{
//get all sensor values
sensors.requestTemperatures();
//Call function to check if file exists if not create file name ie 1 file for each month
getFileName();
//Write Datetime stamp to sd card
WriteDateTime(1);
//Serial print time and rtc temp data
PrintOut();
//assign value to some variables
collector = (sensorValue(collectorThermometer));
loopReturn =(sensorValue(loopReturnThermometer));
tankbottom = (sensorValue(tankbottomThermometer));
tank = (sensorValue(tanktopThermometer));
loopUsed = (sensorValue(loopReturnUsedThermometer));
coldIn = (sensorValue(coldinThermometer));
coldOut = (sensorValue(coldoutThermometer));
// Write temperature data to SD card second parameter is to determine linefeed
WriteSD(collectorThermometer,0);
WriteSD(loopReturnThermometer,0);
WriteSD(tankbottomThermometer,0);
WriteSD(tanktopThermometer,0);
WriteSD(loopReturnUsedThermometer,0);
WriteSD(coldinThermometer,0);
WriteSD(coldoutThermometer,1);
//Print temperature data to serial monitor
printTemperature(collectorThermometer,"Collector");
printTemperature(loopReturnThermometer,"Return");
printTemperature(tankbottomThermometer,"Tank Bottom");
printTemperature(tanktopThermometer,"Tank Top");
printTemperature(loopReturnUsedThermometer,"Loop Used");
printTemperature(coldinThermometer,"Cold In");
printTemperature(coldoutThermometer,"Cold Out");
differential = collector - tankbottom;
//if pump is running, set rise to difference between loopreturn and tankbottom else rise is set to 0
if (pumpOn)
{rise = loopReturn - tankbottom;}
else {rise = 0;}
Serial.print ("differential ");
Serial.println (differential);
Serial.print ("rise ");
Serial.println (rise);
Serial.print ("pump state ");
Serial.println (pumpOn);
Serial.println ("");
Serial.println ("");
Serial.println ("");
Serial.println ("");
if (tankMaxed)
{
if (tank < (tankMax - tankCooldown ) )
{
tankMaxed =false;
}
}
else
{
if ( tank > tankMax )
{
tankMaxed = true;
digitalWrite (pump, LOW);
pumpOn = false;
WriteSDPumpStatus(pumpOn);
}
}
//if tankMaxed bool is false, cycle as solar heat is available
if (!tankMaxed)
{
if (pumpOn)
{
if ( ( (rise < minRise) && (differential < (diff - 1) ) ) )
{
digitalWrite (pump, LOW);
pumpOn =false;
WriteSDPumpStatus(pumpOn);
}
}
else
{
if (differential > diff )
{
digitalWrite (pump, HIGH);
pumpOn = true;
WriteSDPumpStatus(pumpOn);
}
}
}
delay (10000);
val = digitalRead(switchPin); // read input value and store it in val
if (val == HIGH) { // check if the button is pressed
// digitalWrite(ledPin, HIGH); // turn LED on
ReadSerial(); // read serial input in format d201203 ie d for date then yyyymm
}
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("Collector - ");
client.print(collector);
client.print("Return - ");
client.print(loopReturn);
client.print("Tank Bottom - ");
client.print(tankbottom);
client.print("Tank Top - ");
client.print(tank);
client.print("Loop Used - ");
client.print(loopUsed);
client.print("Cold In - ");
client.print(coldIn);
client.print("Cold Out - ");
client.print(coldOut);
client.println();
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}