#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 110 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 22; // LED pin
int cikis1 = 23;
int fan1 = 24;
int cikis2 = 25;
int fan2 = 26;
int cikis3 = 27;
int fan3 = 28;
int cikis4 = 29;
int fan4 = 30;
int cikis5 = 31;
int fan5 = 32;
int cikis6 = 33;
int fan6 = 34;
int cikis7 = 35;
int fan7 = 36;
int cikis8 = 37;
int fan8 = 38;
int cikis9 = 39;
int fan9 = 40;
char link[]="http://sadopy.blogspot.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(fan3, OUTPUT);
pinMode(fan4, OUTPUT);
pinMode(fan5, OUTPUT);
pinMode(fan6, OUTPUT);
pinMode(fan7, OUTPUT);
pinMode(fan8, OUTPUT);
pinMode(fan9, OUTPUT);
pinMode(cikis1, OUTPUT);
pinMode(cikis2, OUTPUT);
pinMode(cikis3, OUTPUT);
pinMode(cikis4, OUTPUT);
pinMode(cikis5, OUTPUT);
pinMode(cikis6, OUTPUT);
pinMode(cikis7, OUTPUT);
pinMode(cikis8, OUTPUT);
pinMode(cikis9, OUTPUT);
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Create a client connection
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; //replaces readString.append(c);
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//dirty skip of "GET /favicon.ico HTTP/1.1"
if (readString.indexOf("?") <0)
{
//skip everything
}
else
//lets check if LED should be lighted
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to yellow
client.print("<body style=background-color:#26387b>");
//send first heading
if (readString.indexOf("A1") >0){
digitalWrite(ledPin, HIGH);
}
if (readString.indexOf("A0") >0)
{
digitalWrite(ledPin, LOW);
}
if (readString.indexOf("B1") >0)
{
digitalWrite(cikis1, HIGH);
}
if (readString.indexOf("B0") >0)
{
digitalWrite(cikis1, LOW);
}
if (readString.indexOf("C1") >0)
{
digitalWrite(fan1, HIGH);
}
if (readString.indexOf("C0") >0)
{
digitalWrite(fan1, LOW);
}
if (readString.indexOf("D1") >0)
{
digitalWrite(cikis2, HIGH);
}
if (readString.indexOf("D0") >0)
{
digitalWrite(cikis2, LOW);
}
if (readString.indexOf("E1") >0)
{
digitalWrite(fan2, HIGH);
}
if (readString.indexOf("E0") >0)
{
digitalWrite(fan2, LOW);
}
if (readString.indexOf("F1") >0)
{
digitalWrite(cikis3, HIGH);
}
if (readString.indexOf("F0") >0)
{
digitalWrite(cikis3, LOW);
}
if (readString.indexOf("G1") >0)
{
digitalWrite(fan3, HIGH);
}
if (readString.indexOf("G0") >0)
{
digitalWrite(fan3, LOW);
}
if (readString.indexOf("H1") >0)
{
digitalWrite(cikis4, HIGH);
}
if (readString.indexOf("H0") >0)
{
digitalWrite(cikis4, LOW);
}
if (readString.indexOf("I1") >0)
{
digitalWrite(fan4, HIGH);
}
if (readString.indexOf("I0") >0)
{
digitalWrite(fan4, LOW);
}
if (readString.indexOf("J1") >0)
{
digitalWrite(cikis5, HIGH);
}
if (readString.indexOf("J0") >0)
{
digitalWrite(cikis5, LOW);
}
if (readString.indexOf("K1") >0)
{
digitalWrite(fan5, HIGH);
}
if (readString.indexOf("K0") >0)
{
digitalWrite(fan5, LOW);
}
if (readString.indexOf("L1") >0)
{
digitalWrite(cikis6, HIGH);
}
if (readString.indexOf("L0") >0)
{
digitalWrite(cikis6, LOW);
}
if (readString.indexOf("M1") >0)
{
digitalWrite(fan6, HIGH);
}
if (readString.indexOf("M0") >0)
{
digitalWrite(fan6, LOW);
}
if (readString.indexOf("N1") >0)
{
digitalWrite(cikis7, HIGH);
}
if (readString.indexOf("N0") >0)
{
digitalWrite(cikis7, LOW);
}
if (readString.indexOf("O1") >0)
{
digitalWrite(fan7, HIGH);
}
if (readString.indexOf("O0") >0)
{
digitalWrite(fan7, LOW);
}
if (readString.indexOf("P1") >0)
{
digitalWrite(cikis8, HIGH);
}
if (readString.indexOf("P0") >0)
{
digitalWrite(cikis8, LOW);
}
if (readString.indexOf("R1") >0)
{
digitalWrite(fan8, HIGH);
}
if (readString.indexOf("R0") >0)
{
digitalWrite(fan8, LOW);
}
if (readString.indexOf("S1") >0)
{
digitalWrite(cikis9, HIGH);
}
if (readString.indexOf("S0") >0)
{
digitalWrite(cikis9, LOW);
}
if (readString.indexOf("T1") >0)
{
digitalWrite(fan9, HIGH);
}
if (readString.indexOf("T0") >0)
{
digitalWrite(fan9, LOW);
}
if (readString.indexOf("RESET") >0)
{
digitalWrite(ledPin, LOW);
digitalWrite(cikis1, LOW);
digitalWrite(fan1, LOW);
digitalWrite(cikis2, LOW);
digitalWrite(fan2, LOW);
digitalWrite(cikis3, LOW);
digitalWrite(fan3, LOW);
digitalWrite(cikis4, LOW);
digitalWrite(fan4, LOW);
digitalWrite(cikis5, LOW);
digitalWrite(fan5, LOW);
digitalWrite(cikis6, LOW);
digitalWrite(fan6, LOW);
digitalWrite(cikis7, LOW);
digitalWrite(fan7, LOW);
digitalWrite(cikis8, LOW);
digitalWrite(fan8, LOW);
digitalWrite(cikis9, LOW);
digitalWrite(fan9, LOW);
}
client.println("Analog Degerler");
client.println("<hr />");
for (int analogChannel = 0; analogChannel < 16; analogChannel++) {
client.print("analog_giris $");
client.print(analogChannel);
client.print("degeri_");
client.print(analogRead(analogChannel));
client.println("<br />");
}
client.println("<br />");
//client.println("22durumu#");
client.println("22durumu#" + String(digitalRead(ledPin)));
client.println("<br />");
client.println("23durumu#" + String(digitalRead(cikis1)));
client.println("<br />");
client.println("24durumu#" + String(digitalRead(fan1)));
client.println("<br />");
client.println("25durumu#" + String(digitalRead(cikis2)));
client.println("<br />");
client.println("26durumu#" + String(digitalRead(fan2)));
client.println("<br />");
client.println("27durumu#" + String(digitalRead(cikis3)));
client.println("<br />");
client.println("28durumu#" + String(digitalRead(fan3)));
client.println("<br />");
client.println("29durumu#" + String(digitalRead(cikis4)));
client.println("<br />");
client.println("30durumu#" + String(digitalRead(fan4)));
client.println("<br />");
client.println("31durumu#" + String(digitalRead(cikis5)));
client.println("<br />");
client.println("32durumu#" + String(digitalRead(fan5)));
client.println("<br />");
client.println("33durumu#" + String(digitalRead(cikis6)));
client.println("<br />");
client.println("34durumu#" + String(digitalRead(fan6)));
client.println("<br />");
client.println("35durumu#" + String(digitalRead(cikis7)));
client.println("<br />");
client.println("36durumu#" + String(digitalRead(fan7)));
client.println("<br />");
client.println("37durumu#" + String(digitalRead(cikis8)));
client.println("<br />");
client.println("38durumu#" + String(digitalRead(fan8)));
client.println("<br />");
client.println("39durumu#" + String(digitalRead(cikis9)));
client.println("<br />");
client.println("40durumu#" + String(digitalRead(fan9)));
client.println("<br />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}