Buongiorno,
Ho un problema con la ethernet shield di Arduino programmata come router per pilotare 4 relais da remoto.
Lo sketch passa il controllo dell'IDE e viene compilato senza errori, apro il monitor seriale e mi dice "Domotic Server test 1.0", ho impostato l'indirizzo IP sulla stessa categoria del router (IP impostato 192.168.1.100 - IP Router 192.168.1.1), fin qui tutto ok, il problema è che nella mia rete la shield non si trova, pingo l'indirizzo ma mi da "Host di destinazione non raggiungibile". L'hardware che uso è:
n.1 Arduino UNO ( originale Arduino )
n.1 ethernet shield ( https://www.hobbytronics.co.uk/arduino-wiznet-shield )
n.1 modulo relè 8 canali
n.1 PC Windows
n.1 switch semplice a 5 porte.
I cavi ethernet sono testati e funzionanti.
Ho anche provato a disabilitare il DHCP al router ma niente. Il mac sulla shield non è riportato quindi ne metto uno ricavato su internet e che comunque non è assegnato a nessun altro device all'interno della mia rete. Se non chiedo troppo, mi potreste dare qualche dritta per provare a risolvere questo problema, sto impazzendo! Grazie anticipatamente. Posto lo sketch anche se dovrebbe essere corretto.
#include <SPI.h>
#include <Ethernet.h>
boolean statop1 = false;
boolean statop2 = false;
boolean statop3 = false;
boolean statop4 = false;
boolean statop5 = false;
boolean statop6 = false;
boolean statop7 = false;
boolean statop8 = false;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 31, 220, 16, 204 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
void setup(){
pinMode(9, OUTPUT); //pin selected to control
pinMode(8, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
pinMode(5, OUTPUT); //pin selected to control
pinMode(4, OUTPUT); //pin selected to control
pinMode(3, OUTPUT); //pin selected to control
pinMode(2, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("Domotic Server test 1.0"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println(F("<!DOCTYPE html><html><head><meta name='apple-mobile-web-app-capable' content='yes'><meta name='apple-mobile-web-app-status-bar-style' content='black-translucent'><link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css'><TITLE>Domotic Home JDM.snake</TITLE></HEAD><BODY><H1>Domotic Home JDM.snake</H1><hr>
<ul><li><p align=\"left\">Corridoio:<a href=\"/?light1on\">Accendi</a><a href=\"/?light1off\">Spegni</a></li></p>
<li><p align=\"left\">Salotto:<a href=\"/?light2on\">Accendi</a><a href=\"/?light2off\">Spegni</a></li></p>
<li><p align=\"left\">Cucina:<a href=\"/?light3on\">Accendi</a><a href=\"/?light3off\">Spegni</a></li></p>
<li><p align=\"left\">Bagno:<a href=\"/?light4on\">Accendi</a><a href=\"/?light4off\">Spegni</a></li></p>
<li><p align=\"left\">Ripostiglio:<a href=\"/?light5on\">Accendi</a><a href=\"/?light5off\">Spegni</a></li></p>
<li><p align=\"left\">Esterno:<a href=\"/?light6on\">Accendi</a><a href=\"/?light6off\">Spegni</a></li></p>
<li><p align=\"left\">Ufficio:<a href=\"/?light7on\">Accendi</a><a href=\"/?light7off\">Spegni</a></li></p>
<li><p align=\"left\">Camera da Letto:<a href=\"/?light8on\">Accendi</a><a href=\"/?light8off\">Spegni</a></li></p>
</ul></BODY><body bgcolor=\"grey\"></HTML>"));
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("?light1on") >0)//checks for on
{
statop1 = true;
}
if(readString.indexOf("?light1off") >0)//checks for off
{
statop1 = false;
}
if(readString.indexOf("?light2on") >0)//checks for on
{
statop2 = true;
}
if(readString.indexOf("?light2off") >0)//checks for off
{
statop2 = false;
}
if(readString.indexOf("?light3on") >0)//checks for on
{
statop3 = true;
}
if(readString.indexOf("?light3off") >0)//checks for off
{
statop3 = false;
}
if(readString.indexOf("?light4on") >0)//checks for on
{
statop4 = true;
}
if(readString.indexOf("?light4off") >0)//checks for off
{
statop4 = false;
}
if(readString.indexOf("?light5on") >0)//checks for on
{
statop5 = true;
}
if(readString.indexOf("?light5off") >0)//checks for off
{
statop5 = false;
}
if(readString.indexOf("?light6on") >0)//checks for on
{
statop6 = true;
}
if(readString.indexOf("?light6off") >0)//checks for off
{
statop6 = false;
}
if(readString.indexOf("?light7on") >0)//checks for on
{
statop7 = true;
}
if(readString.indexOf("?light7off") >0)//checks for off
{
statop7 = false;
}
if(readString.indexOf("?light8on") >0)//checks for on
{
statop8 = true;
}
if(readString.indexOf("?light8off") >0)//checks for off
{
statop8 = false;
}
if(statop1 == true)
{
digitalWrite(9, LOW);
}
if(statop1 == false)
{
digitalWrite(9, HIGH);
}
if(statop2 == true)
{
digitalWrite(8, LOW);
}
if(statop2 == false)
{
digitalWrite(8, HIGH);
}
if(statop3 == true)
{
digitalWrite(7, LOW);
}
if(statop3 == false)
{
digitalWrite(7, HIGH);
}
if(statop4 == true)
{
digitalWrite(6, LOW);
}
if(statop4 == false)
{
digitalWrite(6, HIGH);
}
if(statop5 == true)
{
digitalWrite(5, LOW);
}
if(statop5 == false)
{
digitalWrite(5, HIGH);
}
if(statop6 == true)
{
digitalWrite(4, LOW);
}
if(statop6 == false)
{
digitalWrite(4, HIGH);
}
if(statop7 == true)
{
digitalWrite(3, LOW);
}
if(statop7 == false)
{
digitalWrite(3, HIGH);
}
if(statop8 == true)
{
digitalWrite(2, LOW);
}
if(statop8 == false)
{
digitalWrite(2, HIGH);
}
//clearing string for next read
readString="";
}
}
}
}
}