Go Down

Topic: button connected to the web (Read 241 times) previous topic - next topic

fire1

hello ,

I'm a beginner to arduino, I want to do a project that will let show to the web by using that this button and it's state been pressed , now what I'm trying to do is to connect with one device  , and I'm having this problem in coding , the code will execute like the following :

GET /192.168.0.66 HTTP/1.1
The state is LOW
GET /192.168.0.66 HTTP/1.1
The state is LOW
GET /192.168.0.66 HTTP/1.1
The state is LOW
....

until the end , I have two question , first does this code affect the arduino because the browser is repeating the same message to the same port , second about the code I have tried to do some changes but it gives me an error or the browser does not show any message , so what is my specific  real problem .

Code: [Select]
/* The user should open the browser and enter the specific IP
here I will use a button in the circuit , this button will show
the state of the circuit , the normal action is LOW , then the
browser will show a message " the state is LOW "
when the button is been pressed the browser will show the message
"The state is HIGH"*/

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x54, 0x04, 0xA6, 0x33, 0xF6, 0x8F }; //physical mac address
byte ip[] = { 192, 168, 0, 6 };// ip in lan
byte host[]={192,168,0,4};
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
int v = 0;

//I have connected the Vin and ground together
//the ground wire is in paralled with Pin9

void setup(){
  pinMode(9,INPUT);
  Serial.begin(9600);
  Ethernet.begin(mac , ip ,gateway , subnet );
  server.begin();
}
void loop(){
  EthernetClient client = server.available();
  if(client){
    boolean currentLineBlank = true ;
    if(client.available()){
      char c = client.read();
  if(digitalRead(9) == HIGH){
    digitalWrite(7,HIGH);
    sendGET();
  }
  else{
    digitalWrite(7,LOW);
    sendGET1();
  }}
}}
   
void sendGET() //server function to send/receive GET request data.
{
 
  if (server.available()) {
    //start a connection to the following URL using this port
    Serial.println("connected");
    server.println("GET /192.168.0.6 HTTP/1.1");
    server.println("The state is HIGH");
    server.println(); //end of get request
  }
}
void sendGET1() //server function to send/receive GET request data.
{
  if (server.available()) {
    //start a connection to the following URL using this port
    Serial.println("connected");
    server.println("GET /192.168.0. HTTP/1.1");
    server.println("The state is LOW");
    server.println(); //end of get request
  }
}

PaulS

Quote
the code will execute like the following :

GET /192.168.0.66 HTTP/1.1

No, it won't. What follows the / is the name of a script/application on the server to execute, NOT the IP address of the server.

You are STILL running server code trying to be a client.


DO NOT START ANY MORE THREADS.

Go Up