Hello people!
I got a really tricky question i think!
I have an ethernet shield on my arduino and I tried something like that:
#include <SPI.h>
#include <Ethernet.h>
#define TDIECI 1000
#define TNOVAN 50000
int coordinata=0;
boolean is_moving=false;
boolean is_open=false;
char buffer[3];
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 111 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);
String readString;
byte out_1 = 8;
byte out_2 = 9;
void calcolaesposta (int coord){
;
}
void setup() {
Ethernet.begin(mac, ip);
pinMode(out_1, OUTPUT);
pinMode(out_2, OUTPUT);
}
void loop() {
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c);
if (c == '\n' && currentLineIsBlank) {
if(readString.indexOf("?") > -1) {
if(readString.indexOf("sx") > 0) {digitalWrite(out_1, HIGH); is_moving=true;}
if(readString.indexOf("dx") > 0) {digitalWrite(out_2, HIGH); is_moving=true;}
if(readString.indexOf("stop") > 0) {digitalWrite(out_2, LOW); digitalWrite(out_1, LOW); is_moving=false;}
if(readString.indexOf("sx10") > 0) {digitalWrite(out_1, HIGH); delay(TDIECI); digitalWrite(out_1, LOW);}
if(readString.indexOf("dx10") > 0) {digitalWrite(out_2, HIGH); delay(TDIECI); digitalWrite(out_2, LOW);}
if(readString.indexOf("sx90") > 0) {digitalWrite(out_1, HIGH); delay(TNOVAN); digitalWrite(out_1, LOW);}
if(readString.indexOf("dx90") > 0) {digitalWrite(out_2, HIGH); delay(TNOVAN); digitalWrite(out_2, LOW);}
if(readString.indexOf("apri") > 0) {is_open=true;}
if(readString.indexOf("chiudi") > 0) {is_open=false;}
if(readString.indexOf("coord") > 0) {
int poscoord=readString.indexOf("coord");
readString.substring(poscoord, poscoord+3).toCharArray(buffer, 3);
coordinata=atoi(buffer);
calcolaesposta(coordinata);
}
}
// PAGINA HTML
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>.::Museo del Bali - Arduino Autodome::.</title>");
client.print("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head>");
client.print("<body><center><h1>Dome Automation</h1><hr><h3>Museo del Bali</h3>
<h4>SPOSTAMENTO CUPOLA</h4>");
client.print("<table border=\"5\" cellspacing=\"3\" cellpadding=\"5\">");
client.print("<tr><td><span>SPOSTAMENTO SX</span></td><td><center>STOP</center></td><td>SPOSTAMENTO DX</td></tr>");
if (!is_moving) client.print("<tr><td colspan=\"3\" bgcolor=#00FF00><center>CUPOLA FERMA</center></td></tr>");
if (is_moving) client.print("<tr><td colspan=\"3\" bgcolor=#FF0000><center>CUPOLA IN MOVIMENTO</center></td></tr>");
client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");
client.print("<td><center><input type=\"button\" value=\"STOP\" onclick =\" location.href='/?stop'\"></center></td>");
client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");
client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");
client.print("<td></td>");
client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");
client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start sx\" onclick =\" location.href='/?sx'\"></center></td>");
client.print("<td></td>");
client.print("<td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"Start dx\" onclick =\" location.href='/?dx'\"></center></td></tr>");
/*client.print("<tr><form method=get><td colspan=\"2\">Coordinata stella:</td><td><center><input size=\"15\" value=\"\" name=coord STYLE=\"background-color:#FCFCFC\">");
client.print("<input name=\"S\" type=\"submit\" value=\"Vai\"></from></center></td></tr>"); */
client.print("</table>");
client.print("
<h4>APERTURA CUPOLA</h4><table border=\"3\" cellspacing=\"3\" cellpadding=\"8\">");
client.print("<tr><td><center><input type=\"button\" style=\"width:50px; height:50px\" value=\"Apri\" onclick =\" location.href='/?apri'\"></center></td>");
if (!is_open) client.print("<td bgcolor=#FF0000><center>CHIUSO</center></td>");
if (is_open) client.print("<td bgcolor=#00FF00><center>APERTO</center></td>");
client.print("<td><center><input type=\"button\" style=\"width:50px; height:50px\" value=\"Chiudi\" onclick =\" location.href='/?chiudi'\"></center></td></tr></table></center>");
client.print("
<p align=right> Powered by Arduino
Coded by Michelangelo
Supported by Peppe</p>");
client.println("</body></html>");
readString="";
delay(20);
client.flush();
client.stop();
}
}
}
}
}
wich works;
instead just changing the caption of a button like:
client.print("<tr><td><center><input type=\"button\" style=\"width:120px; height:120px\" value=\"90 sx\" onclick =\" location.href='/?sx'\"></center></td>");
would not work!!!
The only difference is that of the caption of two buttons!
In the first case I can load the webpage in a browser
In the second case it just freeze
I do not know what it have to do with that, but I see that in the first case a nmap of the arduino IP gives back port 80 opened
in the second case a nmap diges no port opened!
Isn't it in the setup() function the opening of ports?
Is there something very strange or is it normal?
Thank you
mic