Olá pessoal,

Terminei um projeto usando Ethernet Shield, porém o lugar onde vai ser instalado o projeto eu não sei a faixa de IP e quem irá instalar o Arduino não serei eu. Então eu preciso dar uma interface pra pessoa que for instalar (e que não sabe nem o que é Arduino) possa faze-lo. 

Eu não sei nada de WEB, eu queria saber se alguém tem um código pronto pra eu por no Arduino uma interface web com um campo que eu possa fazer essa alteração do IP.

Muito obrigado!

Exibições: 1846

Responder esta

Respostas a este tópico

Olá Julio, estou justamente trabalhando nisso, na verdade comecei hoje e como não sou bom de programação vai demorar um pouco.

A minha idéia e ter um ip fixo inicial e na página vc poder mudar o ip ou habilitar o dhcp e salvar essas informações na eeprom.

Se vc conseguir algo me avisa e se antes eu conseguir fazer algo...te mando.

Abraços.

Opa tivemos a mesma ideia!
Eu estou tentando fazer por PHP(XAMPP) bem complicado, consegui até mudar o IP, ainda não sei armazenar na EEPROM. 

Estou travado que eu consigo mudar o IP, mas ai o PHP no XAMPP fica travado, eu teria que fechar a conexão e abriu outra com o IP novo, não estou conseguindo é como se fosse culpa do próprio XAMPP

Muito fácil usar a EEPROM e eu achei que ia ser o mais difícil:

http://labdegaragem.com/profiles/blogs/tutorial-usando-a-eeprom-do-...

#include <EEPROM.h>

Responder até Fellipe Couto em 9 agosto 2012 at 17:21

Bem, funciona exatamente como no link que vc postou:


EEPROM.write(address, value);

Onde:

address – posição da memória que será escrito, é um inteiro entre 0 e 1023  (UNO);

value -  valor a ser armazenado inteiro entre 0 e 255 (um único byte).

O endereço fica a seu critério em qual usar. Supondo que vc use a regra que o valor ficará armazenado no endereço 1 da eeprom. Então:


int tempocafe;

EEPROM.write(1, tempocafe);

Quando precisar ler esse valor, é só usar o read:


tempocafe = EEPROM.read(1);

Pois é,,,facil facil, o problema é o resto...rsrs

Estou me baseando nisso:

http://forum.arduino.cc/index.php?topic=114436.0

Código - http://www.halfluck.com/source/webserver/TempControllerWebServer.ino

Tem um pouco de tudo, html, eeprom e ler pinos.

Mas parece que é difícil sair algo...rsrs

Abraços

Oi Júlio, conseguiu algo?

Segue o que consegui até agora...

- Inicio escrevendo o na eeprom para ter o ip fixo

- no setup tem o if para saber se é fixo ou dhcp

- na página tem a opção de trocar para fixo ou dhcp

---PRÓXIMOS PASSOS

- salvar o endereço ip digitado na pagina para a eeprom

- ler o endereço da eeprom no inicio do programa

- se for ip fixo ler o da eeprom 

- se for dhcp pegar o da rede

Abraços.

-------------- codigo 

//TESTE_IP_DHCP
//V3_1 dhcp e ip fixo ok
//v3_2 BOTAO DHCP OK
#include <EtherCard.h>
#include <EEPROM.h>

String versao = "--- VERSAO 3_2";

byte VarDHCP = 0; //IP INICIAL E FIXO SE POR 1 O IP SERA POR DHCP


// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[1000]; // tcp/ip send and receive buffer
BufferFiller bfill;

const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

static word ip() {

//$D = word data type
//$L = long data type
//$S = c string
//$F = progmem string
//$E = byte from the eeprom.

char* DHCP;
VarDHCP = EEPROM.read(0);
if ( EEPROM.read(0) == 0 ) {
DHCP = "FIXO";
} else {
DHCP = "DHCP";
}

bfill.emit_p(PSTR(
"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">"
"<html><head><title>---</title>"
"<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">"
"</head>"
"<body bgcolor=""#99CCFF"">"
"<center>"
"REDE:"
"<hr />"
"<form>"
"<p>ENDERECO IP:<BR>"
"<input name=ip1 type=text value=""192"" size=2 maxlength=""3"">"
"<input name=ip2 type=text value=""168"" size=2 maxlength=""3"">"
"<input name=ip3 type=text value=""1"" size=2 maxlength=""3"">"
"<input name=ip4 type=text value=""155"" size=2 maxlength=""3"">"
"<BR>"
"MASCARA: <BR>"
"<input name=mask1 type=text value=""255"" size=2 maxlength=""3"">"
"<input name=mask2 type=text value=""255"" size=2 maxlength=""3"">"
"<input name=mask3 type=text value=""255"" size=2 maxlength=""3"">"
"<input name=mask4 type=text value=""0"" size=2 maxlength=""3""><br>"
"<input name=""ipfixo"" type=""submit"" id=""ipfixo"" value=""FIXO"">"
"</form>"
"<form><input type=""button"" value=""DHCP"" onClick=""document.location.href='/?dhcp';""></form>"
"<hr />"
"<p>ATUAL: <font color=""#FF0000""><b> $S</b></font></p>"
"<hr />"
"</center></body></html>"),
DHCP);
return bfill.position();
}
//"<form><input name=""dhcp"" type=""submit"" id=""dhcp"" value=""DHCP""></form>"
//"<form><input type=""button"" value=""DHCP"" onClick=""document.location.href='/?dhcp';""></form>"
//"<form><input type=""button"" value=""Voltar"" onClick=""document.location.href='/?menu';""></form>"


void setup(){
EEPROM.write(0, VarDHCP); //GRAVA 0 NA EEPROM, SEMPRE QUE REINICIAR SERA IP FIXO, NO FUTURO ESSA LINHA SAI
Serial.begin(9600);
Serial.print("\n\n[REDE]");
Serial.println(versao);


if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
Serial.println( "Failed to access Ethernet controller" );

VarDHCP = EEPROM.read(0);
Serial.println(VarDHCP);
switch (VarDHCP) {
case 0:
Serial.println("IP FIXO");
static byte myip[] = { 192,168,1,155 };
static byte mymask[] = { 255,255,255,0 };
ether.staticSetup(myip, mymask);
Serial.println("IP: 192.168.1.155/24");
break;
case 1:
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
// } else {
ether.printIp("IP: ", ether.myip);
ether.printIp("MASK: ", ether.mymask);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
// }
break;
default:
Serial.println("ERRO NA REDE");
}

}

void loop(){

Serial.print("--- VarDHCP inicial: ");
VarDHCP = EEPROM.read(0);
Serial.println(VarDHCP);
// delay(1000);

word len = ether.packetReceive();
word pos = ether.packetLoop(len);

if (pos) { // check if valid tcp data is received // data received from ethernet
delay(1);
bfill = ether.tcpOffset();
Serial.println("--1");
char *data = (char *) Ethernet::buffer + pos;
if (strncmp("GET /", data, 5) != 0) {
bfill.emit_p(http_Unauthorized);
}
else
{
data += 5;
if (data[0] == ' ') {
// Return home page
ip();
}
else if (strncmp( "?dhcp" , data, 5 ) == 0)
{
VarDHCP = 1;
EEPROM.write(0, VarDHCP);
Serial.print("--- VarDHCP: ");
Serial.println(EEPROM.read(0));
delay(1000);
// bfill.emit_p(http_Found);
}
}


bfill = ether.tcpOffset();
ether.httpServerReply(ip());
delay(1000);
}

/*
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
*/
}

finalmente, alguem conseguiu fazer o que foi proposto nesse topico? mudar o ip sem recompilar! ajudem

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço