amigos,
gostaria de saber se é possivel iniciar o EthernetServer server(80) dentro do setup pois tentei e não consegui
a ideia seria ler a eeprom antes de iniciar o servidor e decidir que porta eu quero iniciar ele atraves da leitura da eeprom que vou deixar gravado a porta
eu tentei fazer a leitura da eeprom antes do setup mas da erro e tentei iniciar o servidor dentro do setup mas ai a função loop não reconhece ele
existe uma possibilidade?
dario
Tags:
vc ja tentou colocar o EthernetServer server(80) dentro do loop tb? vc ja estudou a possibilidade de usar um enc28j60 e mudar a biblioteca pra ethercard.h . acho que nela da
se eu colocar dentro do loop ele vai ficar executando sempre e isto não é correto, é perca de processamento.
não sei como funciona a enc28j60 mas eu tenho aqui o ethernet shield e não quero mudar o hardware.
amigo, cola aí pra nós teu sketch para conseguirmos entender o que há de errado.
abaixo segue o exemplo do proprio arduino, eu so quero tirar o trecho
EthernetServer server(80);
e jogar ele dentro do setup
nao quero que ele inicie antes do setup
pois dentro do setup vou ler a eeprom e definir que porta vou usar
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por