Salve Ragazzi, da qualche giorno ho ricevuto la mia nuova Scheda Arduino Ethernet con Poe (Non la Shield).
Innanzitutto ho notato che questa scheda quando è alimentata da Trasformatore scalda Tantissimo, per essere + preciso è il modulo poe che diventa quasi intoccabile ma sembra un comportamento normale stando a quello che dice il datasheet del modulo poe. Veniamo invece al problema principale ...
Ho notato che il modulo ethernet mi si impalla di continuo, se per esempio se faccio un semplice sketch che visualizza lo stato di un led in una pagina web, alle prime risposte avrò un output corretto ma dopo una trentina di rischieste avrò una pagina piena di strani caratteri o addirittura la scheda non risponde propio.
Dato il fatto che sono alle prime armi con Arduino non vorrei che fosse un errore di codifica ma, dato che alle prime richieste fuziona non credo che sia un errore di codifica.
Vi allego il codice ... Grazie in anticipo.
#include <SPI.h>
#include <Ethernet.h>
#include <String.h>
#define ledPin 8
#define buttonPin 7
#define connectionTime 1000 // ms
#define maxLength 36
String inString = "";
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0x73, 0xC4 };
byte ip[] = {
192,168,0, 10 };
Server server(80);
boolean spegni=LOW;
boolean led=LOW;
boolean accendi=HIGH;
long requestNumber = 0;
void setup() {
Ethernet.begin(mac, ip);
server.begin();
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
ledOnOff(ledPin, buttonPin);
page();
}
int ledOnOff(byte byteLedPin, byte byteButtonPin) {
int sensorValue = digitalRead(buttonPin);
if ( sensorValue == HIGH && accendi == HIGH) {
led=HIGH;
accendi=LOW;
digitalWrite(ledPin,HIGH);
}
else if ( sensorValue == HIGH && spegni == HIGH) {
led=LOW;
spegni=LOW;
digitalWrite(ledPin,LOW);
}
else if ( sensorValue == LOW && led==HIGH) {
spegni=HIGH;
}
else if ( sensorValue == LOW && led==LOW) {
accendi=HIGH;
}
return led;
}
void page() {
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
requestNumber++;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (inString.length() < maxLength) {
inString+=(c);
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Server: Arduino");
client.println("Content-Type: text/html; charset=UTF-8");
client.println("Connection: close");
client.println();
client.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>");
client.print(" <meta http-equiv=\"refresh\" content=\"5\"> <title>Arduino Led Test Page</title>\n</head> <body> <p>");
client.print(millis()/1000);
client.print("s Richiesta Http: ");
client.print(requestNumber);
client.print(" - Led: ");
if (led) {
client.print("Accesso");
}
else {
client.print("Spento");
}
client.print("</p>\n</body> </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(connectionTime);
inString = "";
client.stop();
}
}