Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //magikh0e.ihtb.org
- #include <SPI.h>
- #include <Ethernet.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 2
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress outsideThermometer = { 0x28, 0xB2, 0xBB, 0x3A, 0x04, 0x00, 0x00, 0x85 };
- DeviceAddress insideThermometer = { 0x28, 0xD8, 0x91, 0x3A, 0x04, 0x00, 0x00, 0xCC };
- byte mac[] = { 0xDA, 0xRP, 0xA0, 0xR0, 0xCK, 0xSS };
- byte ip[] = { 1, 2, 3, 4 }; // IP Address
- byte gateway[] = { 1, 2, 3, 1 }; // Default Gateway
- byte subnet[] = { 255, 255, 255, 0 }; // Netmask
- EthernetServer server(80);
- String readString;
- void setup(){
- pinMode(6, OUTPUT);
- Ethernet.begin(mac, ip, gateway, gateway, subnet);
- server.begin();
- Serial.begin(9600);
- Serial.println("TCP/IP Power Controller - v1.5");
- Serial.println("By: magik");
- sensors.begin();
- // set the resolution to 10 bit (good enough?)
- sensors.setResolution(insideThermometer, 10);
- sensors.setResolution(outsideThermometer, 10);
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- if (tempC == -127.00) {
- Serial.print("Error getting temperature");
- } else {
- Serial.print("C: ");
- Serial.print(tempC);
- Serial.print(" F: ");
- Serial.print(DallasTemperature::toFahrenheit(tempC));
- }
- }
- void loop(){
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- //read char by char HTTP request
- if (readString.length() < 100) {
- //store characters to string
- readString += c;
- //Serial.print(c);
- }
- if (c == '\n') {
- Serial.println(readString); //print to serial monitor for debuging
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.println("<HTML>");
- client.println("<HEAD>");
- client.println("<TITLE>Light Controller - By: magik</TITLE>");
- client.println("</HEAD>");
- client.println("<BODY>");
- client.println("<H1>TCP/IP Power Controller</H1>");
- client.print("<b>Socket 1</b><BR>");
- client.print("<input type=submit value='Light ON' style=width:100px;height:45px onClick=location.href='/?Status=Light1_ON;'>");
- client.print("<input type=submit value='Light OFF' style=width:100px;height:45px onClick=location.href='/?Status=Light1_OFF;'>");
- // ALL OFF - client.print(" <input type=submit value='ALL OFF' style=width:100px;height:45px onClick=location.href='/?off3579;'>");
- client.print("<BR><b>Socket 2</b><BR>");
- client.print("<b>Socket 3</b><BR>");
- client.print("<b>Socket 4</b><BR>");
- client.print("<BR><BR><b>Temperature(s): </b> <BR>");
- client.print("Outside: ");
- client.print("<BR>Inside: ");
- client.print("<b>Weather Status: </b> <I>Not Connected</I><BR>");
- client.print("<b>Humidity: </b> <I>Not Connected</I><BR>");
- client.print("<b>GPRS Status: </b> <I>Not Connected</I><BR>");
- client.println("</BODY>");
- client.println("</HTML>");
- delay(1);
- client.stop();
- if(readString.indexOf('Light_1_ON') >0)
- {
- digitalWrite(6, HIGH);
- Serial.println("Light On");
- }
- if(readString.indexOf('Light_1_OFF') >0)
- {
- digitalWrite(6, LOW);
- Serial.println("Light Off");
- }
- readString="";
- }
- }
- }
- }
- //Pull stats, print to serial
- delay(2000);
- Serial.print("Getting Socket(s) Status\n\r");
- Serial.print("Socket #1\n\r");
- Serial.print("Getting temperatures...\n\r");
- sensors.requestTemperatures();
- Serial.print("Inside temperature is: ");
- printTemperature(insideThermometer);
- Serial.print("\n\r");
- Serial.print("Outside temperature is: ");
- printTemperature(outsideThermometer);
- Serial.print("\n\r");
- Serial.print("\n\r\n\r");
- }
Advertisement
Add Comment
Please, Sign In to add comment