found this example ,i edit it and it works.
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90,0xA2,0xDA,0x00,0x55,0x8D}; //Replace with your Ethernet shield MAC
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac);
delay(1000);
Serial.println("connecting...");
}
void loop(){
String data;
data+="";
data+="data=12.7%2C0%2C50"; // Use HTML encoding for comma's
data+="&submit=Submit"; // Submitting data
if (client.connect("myoffice-ip",80)) {
Serial.println("connected");
client.println("POST /?lightsoff HTTP/1.1");
client.println("Host: myoffice-ip");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
//Prints your post request out for debugging
Serial.println("POST /?lightsoff HTTP/1.1");
Serial.println("Host: myoffice-ip");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
}
delay(2000);
if (client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
exit(0);
}
}
now i have to put that code together with my webservers code and make it work somehow....I dont have a clue where to begin ![]()
my small webserver s code is that
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 120 }; // 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(4040); //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(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
// 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("<TITLE>HOME AUTO SERVER</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>HOME AUTOMATION PANEL</H1>");
client.println("<hr />");
client.println("
");
client.println("<H2>PRESS TO OPEN AND CLOSE</H2>");
client.println("
");
client.println("
");
client.println("<a href=\"/?button4on\"\"> INDOOR </a>");
client.println("
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button1on\"\"> OUTDOOR </a>");
client.println("
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button2on\"\"> LIGHTS ON </a>");
client.println("<a href=\"/?button2off\"\"> LIGHTS OFF </a>
");
client.println("
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button3on\"\"> MAIN SWITCH ON </a>");
client.println("<a href=\"/?button3off\"\"> MAIN SWITCH OFF </a>
");
client.println("
");
client.println("
");
client.println("
");
client.println("
");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
if (readString.indexOf("?button1on") >0){
digitalWrite(6, HIGH);
delay(3000);
digitalWrite(6, LOW);
}
if (readString.indexOf("?button2on") >0){
digitalWrite(7, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(7, LOW);
}
if (readString.indexOf("?button3on") >0){
digitalWrite(8, HIGH);
}
if (readString.indexOf("?button3off") >0){
digitalWrite(8, LOW);
}
if (readString.indexOf("?button4on") >0){
digitalWrite(9, HIGH);
delay(3000);
digitalWrite(9, LOW);
}
//clearing string for next read
readString="";
}
}
}
}
}
Any help from the experianced people here is welcome