Galera, boa noite.

Mais uma vez estou aqui pra solicitar uma ajuda para um projetinho que estou fazendo.

No código abaixo para o W5100 é possível personalizar o botão que é mostrado pelo browser?

O browser simplesmente mostra on e off porém botões muito pequenos.

Gostaria de aumentá-los porém na estrutura abaixo não faço a mínima idéia de como fazê-lo.

Alguém pode me ajudar?

Obrigado!!!

#include <Ethernet.h>
#include <SPI.h>
//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

String inString = String(35);

String Luz;

int led[] = {00, 2, 3, 4 ,5 ,6 ,7 ,8,9 }; //Led pins num 0 in arry is not used
int numofleds = 8; //numofleds
String value[] = {"on","on","on","on","on","on","on","on","on"}; //startup all led are off

EthernetServer server(80);
String data;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
//set pin mode
for (int j = 1; j < (numofleds + 1); j++){
pinMode(led[j], OUTPUT);
}
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
}

void loop()
{
EthernetClient client = server.available();

if(client){
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {

if(client.available()) {

char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 35) {
inString.concat(c);
}
if (c == '\n' && current_line_is_blank) {

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><body><form method=get>");
client.println("<p><h1>YOSHIKAWA online</h1></font></p>");



for(int i=1;i < (numofleds + 1) ;i++){
Luz = String("Luz") + i;

if(inString.indexOf(Luz+"=on")>0 || inString.indexOf("all=on")>0){
Serial.println(Luz+"on");
digitalWrite(led[i], HIGH);
value[i] = "off";
}else if(inString.indexOf(Luz+"=off")>0 || inString.indexOf("all=off")>0 ){
Serial.println(Luz+"on");
digitalWrite(led[i], LOW);
value[i] = "on";
}
client.println("<br>"+Luz+" <input type=submit name="+Luz+" value="+value[i]+">");
}
client.println("<br><b>TODOS</b><input type=submit name=all value=on><input type=submit name=all value=off>");
client.println("</from></html></body>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
inString = "";
client.stop();
}
}

Exibições: 1361

Responder esta

Respostas a este tópico

bom, você pode colocar algo do tipo
digitalWrite(led[i], LOW);
value[i] = "on";
}
client.println("<br>"+Luz+" <input type=submit name="+Luz+" value="+value[i]+" style=\"width:35px;height:40px\">" );
}

 

O que eu acrescentei foi o style="width:35px;height:40px"
Onde width é a largura e height a altura do botão.

Isso é chamado CSS, e mexe em como os elementos HTML são formatados

Pensei melhor em vez de colocar o style ai coloca apenas isso.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><header><style>input {height:40px; width:35px }</style></header><body><form method=get>");
client.println("<p><h1>YOSHIKAWA online</h1></font></p>");

 

Isso vai afetar todos os botões do seu HTML e economizar espaço para o programa.

 

Marcelo, muito muito obrigado.

Funcionou perfeitamente!!!

Abs.

Marcelo, boa tarde.

Sabe me dizer como colocar um botão ao lado do outro?

É possível?

Obrigado. 

Fala ai Alexandre, ve se assim resolve

Abração

Max

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><body><form method=get>");
client.println("<p><h1>YOSHIKAWA online</h1></p>");



for(int i=1;i < (numofleds + 1) ;i++){ 
Luz = String("Luz") + i;

if(inString.indexOf(Luz+"=on")>0 || inString.indexOf("all=on")>0){
Serial.println(Luz+"on");
digitalWrite(led[i], HIGH);
value[i] = "off"; 
}else if(inString.indexOf(Luz+"=off")>0 || inString.indexOf("all=off")>0 ){ 
Serial.println(Luz+"on");
digitalWrite(led[i], LOW);
value[i] = "on";
}

client.println(<p><table><tr>);


client.println("<td>"+Luz+"</td>");

client.println("<td><input type=submit name="+Luz+" value="+value[i]+"></td></tr>");
}
client.println("<tr><td><b>TODOS</b></td>");

client.println("<td><input type=submit name=all value=on>");

client.println("<input type=submit name=all value=off></td></tr>");
client.println("</from></html></body>");
break;

Boa noite,

Estou a desenvolver uma aplicação industrial para monitorizar temperatura e pressao com web server ethernet.

Como posso de uma maneira facil ativar uma saida desde um botao no web server?

Posso dar uma forma diferente a este botao?

Obrigado

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço