/*
Created by Rui Santos
Visit: http://randomnerdtutorials.com for more arduino projects
Arduino with Ethernet Shield
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
int led = 4;
int led2 = 5;
int led3 = 6;
int led4 = 3;
Servo microservo;
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 131 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
microservo.attach(7);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
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;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>Kula Akilli Ev Otomasyonu V.1.0</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Kula Akilli Ev Otomasyonu V.1.0</H1>");
client.println("<hr />");
client.println("
");
client.println("<H2>Ev Kontrol Sistemine Hosgeldiniz</H2>");
client.println("
");
client.println("<a href=\"/?button1on\"\">Oturma Odasi Yak</a>");
client.println("<a href=\"/?button1off\"\">Oturma Odasi Sondur</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button2on\"\">Radyo Ac</a>");
client.println("<a href=\"/?button2off\"\">Radyo Kapat</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button3on\"\">Mutfak Lamba Ac</a>");
client.println("<a href=\"/?button3off\"\">Mutfak Lamba Kapat</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button4on\"\">Siren Calistir</a>");
client.println("<a href=\"/?button4off\"\">Siren Sustur</a>
");
client.println("<p>YunusEmreKula Tarafindan Kodlanmistir.2020</p>");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
}
if (readString.indexOf("?button2on") >0){
digitalWrite(led2, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(led2, LOW);
}
if (readString.indexOf("?button3on") >0){
digitalWrite(led3, HIGH);
}
if (readString.indexOf("?button3off") >0){
digitalWrite(led3, LOW);
}
if (readString.indexOf("?button4on") >0){
digitalWrite(led4, HIGH);
}
if (readString.indexOf("?button4off") >0){
digitalWrite(led4, LOW);
}
//clearing string for next read
readString="";
}
}
}
}
}
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
byte ip[] = { 192, 168, 1, 131 };
IPAddress server(94, 73, 150, 229); // website server IP address
String host = "www.denemeornek.site";
String page = "/";
boolean waitingResponse = false;
int count=0;
int maxcount=1;
EthernetClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
Serial.println("Starting...");
}
void (*restart)(void) = 0;
void loop() {
if(!waitingResponse) {
if(count==maxcount) { // after one connection
Serial.println("Sleeping for 50 seconds");
delay(50000);
Serial.println("Restarting...");
restart();
return;
}
connectToServer();
count++;
}
else {
processResponse();
}
}
void connectToServer() {
if(waitingResponse) return;
Serial.println("Connecting...");
int tries = 0;
while (!client.connect(server, 80)) {
delay(200);
tries++;
if (tries > 100) { // ok we have problem
Ethernet.begin(mac, ip); // solve it by brute force
tries=0;
}
}
client.print("GET ");
client.print(page);
client.println(" HTTP/1.0"); // here I can adjust as suggested, using HTTP/1.1 and force a connection close
client.print("Host: "); // needed in my case (virtualserver)
client.println(host);
client.println();
waitingResponse = true;
}
boolean processResponse() {
if(!waitingResponse) return true;
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting.");
client.stop();
waitingResponse = false;
return false;
}
return true;
}
1.code provides remote relay card control
2. code allows you to register my ip address on my mysql server by visiting the web page
i want it to work in 1&2 code
thanks
respects
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.