/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27
/*-----( Declare Variables )-----*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0xCD, 0x4E
}; //physical mac address
byte ip[] = {
192, 168, 1, 139
}; // ip in lan
byte gateway[] = {
192, 168, 1, 1
}; // internet access via router
// byte subnet[] = {255, 255, 255, 0 }; //subnet mask
IPAddress dns(204,117,214,110); // OpenDNS IP
EthernetServer server(90); //server port
// DECLARE
String readString;
#define TSTAT 12
#define FAN 13
#define TEMP 0
#define PUMP 11
#define LITE 10
const long ONE_SECOND = 1000; //DEFINE ONE SECOND
const long ONE_MINUTE = 60 * ONE_SECOND; //DEFINE ONE MINUTE
const long ONE_HOUR = 60 * ONE_MINUTE; //DEFINE ONE HOUR
int T = 0; //ANALOG READ TEMP
int temp = 0; //ACTUAL TEMP
int tstat = LOW; //THERMOSTAT STATE VARIABLE
void setup()
{
// START Ethernet
//Ethernet.begin(mac, ip, gateway, subnet);
Ethernet.begin(mac, ip, gateway,dns);
server.begin();
pinMode(TSTAT, INPUT);
pinMode(FAN, OUTPUT);
pinMode(TEMP, INPUT);
pinMode(PUMP, OUTPUT);
pinMode(LITE, OUTPUT);
pinMode(8, OUTPUT); //pin selected to control
pinMode(9, OUTPUT); //pin selected to control FAN
//enable serial data print FOR TESTING ON Serial monitor
Serial.begin(9600);
}
void loop()
{
// Create a client connection
EthernetClient client = server.available();
// If someone connects to the server...
if (client)
{
// Create a variable to hold whether or not we have received a blank
// line from the web browser
boolean current_line_is_blank = true; //new
while (client.connected())
{
lcd.clear();
lcd.print("CONNECTED!");
lcd.blink();
// If the client has sent us some data...
if (client.available())
{
// Keep the last letter of whatever they sent us
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c;
//Serial.print(c);
digitalWrite(4, HIGH); // turn on "connected" LED
// If we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank)
{
client.println("HTTP/1.1 200 OK"); //send new page
client.println(F("Content-Type: text/html"));
client.println();
// ------------------------------------------------
client.println();
client.print(F("<body style=background-color:BLACK>")); //set background to BLACK
client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=35 URL=>"));
// client.println(F("<META HTTP-EQUIV=REFRESH CONTENT=5; url=>"));
client.println(F("<HTML>"));
client.print(F("<HEAD>"));
client.println(F("<center>"));
client.println(F("<font color=’green’><h1>INTERNET -- CONTROL </font></h1>/"));//send first heading
client.println(F("<hr />"));
client.println(F("<font color=’#0D8112’ size=’5?> "));
client.println(F("</center>"));
//if HTTP request has ended
if (c == '\n' && current_line_is_blank)
{
///////////////
Serial.println(readString); //print to serial monitor for debugging
if(readString.indexOf("off8") >0)//checks for off reading string from Ethernet web form button
{
digitalWrite(8, LOW); // set pin 8 low
digitalWrite(9, LOW); //FAN
Serial.println("Led 8 Off"); // blue led
}
if(readString.indexOf("sen11") >0)//checks for sensor loop test
{
heat();// goto heat function
}
// radiobuttons
client.print(F("<form method=get name=LED>"));
client.println(F("<button name=sen11 value=1 type=submit style=font-weight:bold;color:red;height:50px; width:60px>sen</button>"));
client.println("</center>");
client.println("</form>"); // new
client.println(F("<hr />")); // print a header on webpage ---------------------
}
client.println("<center>");
client.println(F("<hr />"));
client.println(F("</body></html>"));
//stopping client
client.stop();
digitalWrite(4, LOW); // turn OFF "connected" LED
delay(2000);
readString="";
// THIS IS A TEST FUNCTION //
void heat()
{
temp = analogRead(TEMP); //READ TEMP
Serial.println(temp); //PRINT TEMP FOR DIAG
delay(250); //WAIT 1/4 SECOND
tstat = digitalRead(TSTAT); //READ THERMOSTAT STATE
if (tstat == HIGH) // IF THERMOSTAT CALLS FOR HEAT
{
digitalWrite(FAN, HIGH); //TURN FAN ON
}
else //IF THERMOSTAT DOESNT CALL FOR HEAT
{
digitalWrite(FAN, LOW); //TURN FAN OFF
digitalWrite(PUMP, LOW);
return;
}
if (temp > 475)
{
coilWarmup;
}
}
}
}
}
}
}
}
--------------------------------------------------------------------------------------
I am attempting to learn how incorporate a function into my code.
The Ethernet part all works fine and the button displays the correct code when clicked in the web page
I setup a web button which sends a sen11 code and if so then it should jump to the heat function
The Ethernet part all works fine.
I cant seem to get the code to jump/go to my void [u]heat function[/u]
[u]Compile error - heat was not declared in this scope[/u]
How do i get rid of this... ?
Thanks
Joe
Lots of details missing. What version of the IDE are you using? What errors are you getting?
// THIS IS A TEST FUNCTION //
void heat()
Embedded in loop. Your crappy indentation isn't helping. Use Tools + Auto format to straighten that mess up.
There is a { missing here for a start:
void heat()
temp = analogRead(TEMP); //READ TEMP
I had to add about 5 x } here just to get the auto-format to work.
digitalWrite(4, LOW); // turn OFF "connected" LED
delay(2000);
readString="";
}
}
}
}
}
These braces are supposed to match you know. They aren't just there for decoration.
Thanks,
I knew i lost the { somewhere but could not match them up..
Joe
Is there an easy method / logic on how to keep track or determine when and where open { and } are placed?
Joe
First, do the auto-format in the IDE, and then the braces should more-or-less line up vertically.
Second, if you put the cursor after one, the other (corresponding) one should be highlighted slightly.
joeman:
Is there an easy method / logic on how to keep track or determine when and where open { and } are placed?Joe
When you place an opening brace, immediately place the closing brace. Remember, they should vertically line up.
Ah.. You declared your heat function -inside- your loop function. Maybe things have changed, but in my day I never saw stuff like that. Try moving your heat function up above your start function? Then call it from your loop function when you want it.
-jim lee