Cannot keep session with Arduino alive
in
Integration and Hardware
•
1 year ago
I have set up an Arduino as a Webserver (using the Ethernet library) on my local network at IP address 192.168.0.177 and port 80. An LED is hooked up to the Arduino and lights up when a cmdT=1 is received and goes off when a cmdT=0 is received. I can control it without a problem from a browser (i.e. when I submit
http://192.168.0.177/?cmdI=1 the LED goes on and when I submit
http://192.168.0.177/?cmdI=0 it goes off).
However, when I try to control the LED from Processing only the first command is executed by Arduino. I am using the following code and the LED lights up when the sketch is started, but fails to go off 10 secs later although the sketch enters the IF function and prints "turn off". All suggestions/advice are welcome.
However, when I try to control the LED from Processing only the first command is executed by Arduino. I am using the following code and the LED lights up when the sketch is started, but fails to go off 10 secs later although the sketch enters the IF function and prints "turn off". All suggestions/advice are welcome.
- import processing.net.*;
Client c;
int mode = 0;
void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "192.168.0.177", 80); // Connect to server on port 80
c.write("GET /?cmdT=1 HTTP/1.1\r\n"); // Use the HTTP "GET" command to ask for a Web page
c.write("Keep-Alive: 300\r\n");
c.write("Connection: keep-alive\r\n");
c.write("\r\n");
}
void draw() {
if (millis() > 10000 && mode == 0){
mode = 1;
println("turn off");
c.write("GET /?cmdT=0 HTTP/1.1\r\n"); // Use the HTTP "GET" command to ask for a Web page
c.write("\r\n");
}
}
1