View difference between Paste ID: Hf34AKEh and WyLfRris
SHOW: | | - or go back to the newest paste.
1
//magikh0e.ihtb.org
2
3
#include <SPI.h>
4
#include <Ethernet.h>
5-
#include <OneWire.h>
5+
6-
#include <DallasTemperature.h>
6+
7
byte ip[] = { 1, 2, 3, 4 };  // IP Address
8-
#define ONE_WIRE_BUS 2
8+
9-
OneWire oneWire(ONE_WIRE_BUS);
9+
10-
DallasTemperature sensors(&oneWire);
10+
11
12-
DeviceAddress outsideThermometer = { 0x28, 0xB2, 0xBB, 0x3A, 0x04, 0x00, 0x00, 0x85 };
12+
13-
DeviceAddress insideThermometer = { 0x28, 0xD8, 0x91, 0x3A, 0x04, 0x00, 0x00, 0xCC };
13+
14
void setup(){
15
16
  pinMode(6, OUTPUT); 
17
18
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
19
  server.begin();
20
21
  Serial.begin(9600); 
22
  Serial.println("TCP/IP Power Controller - v1.5");
23
  Serial.println("By: magik"); 
24
  
25
   sensors.begin();
26
  // set the resolution to 10 bit (good enough?)
27
  sensors.setResolution(insideThermometer, 10);
28
  sensors.setResolution(outsideThermometer, 10);
29
30
}
31
32
void printTemperature(DeviceAddress deviceAddress)
33
{
34
  float tempC = sensors.getTempC(deviceAddress);
35
  if (tempC == -127.00) {
36
    Serial.print("Error getting temperature");
37
   } else {
38
    Serial.print("C: ");
39
    Serial.print(tempC);
40
    Serial.print(" F: ");
41
    Serial.print(DallasTemperature::toFahrenheit(tempC));
42
  }
43
}
44
45
void loop(){
46
  
47
  EthernetClient client = server.available();
48
  
49
  if (client) {
50
    while (client.connected()) {
51
      if (client.available()) {
52
        char c = client.read();
53
54
        //read char by char HTTP request
55
        if (readString.length() < 100) {
56
57
          //store characters to string 
58
          readString += c; 
59
          //Serial.print(c);
60
        } 
61
62
        
63
        if (c == '\n') {
64
          Serial.println(readString); //print to serial monitor for debuging 
65
66
67
          client.println("HTTP/1.1 200 OK"); 
68
          client.println("Content-Type: text/html");
69
          client.println();
70
71
          client.println("<HTML>");
72
          client.println("<HEAD>");
73
          client.println("<TITLE>Light Controller - By: magik</TITLE>");
74
          client.println("</HEAD>");
75
          client.println("<BODY>");
76
77
          client.println("<H1>TCP/IP Power Controller</H1>");
78
     
79
                
80
          client.print("<b>Socket 1</b><BR>");
81
                  
82
          client.print("<input type=submit value='Light ON' style=width:100px;height:45px onClick=location.href='/?Status=Light1_ON;'>");
83
          client.print("<input type=submit value='Light OFF' style=width:100px;height:45px onClick=location.href='/?Status=Light1_OFF;'>");
84
        //  ALL OFF - client.print("&nbsp;<input type=submit value='ALL OFF' style=width:100px;height:45px onClick=location.href='/?off3579;'>");
85
86
          client.print("<BR><b>Socket 2</b><BR>");
87
          client.print("<b>Socket 3</b><BR>");
88
          client.print("<b>Socket 4</b><BR>");
89
          
90
          client.print("<BR><BR><b>Temperature(s): </b> <BR>");
91
          client.print("Outside: ");
92
         
93
         client.print("<BR>Inside: ");
94
       
95
          client.print("<b>Weather Status: </b> <I>Not Connected</I><BR>");
96
          client.print("<b>Humidity: </b> <I>Not Connected</I><BR>");
97
          client.print("<b>GPRS Status: </b> <I>Not Connected</I><BR>");
98
99
          client.println("</BODY>");
100
          client.println("</HTML>");
101
 
102
          delay(1);
103
          client.stop();
104
         
105
          if(readString.indexOf('Light_1_ON') >0)
106
          {
107
            digitalWrite(6, HIGH);    
108
            Serial.println("Light On");
109
          }
110
          
111
          if(readString.indexOf('Light_1_OFF') >0)
112
          {
113
            digitalWrite(6, LOW);    
114
             Serial.println("Light Off");
115
          }
116
          
117
          readString="";
118
119
        }
120
      }
121
    }
122
  }
123
}