I am trying to configure arduino to talk over a power line communications modem to a computer but I cannot control it. When I try to ping the ip address of the ethernet shield it comes back "destination host unreachable" but when I connect it directly to my computer it is fine. I thought the PLC modem was just a pass through do I need gateway info? How can I communicate with the arduino over the powerline modems? I can connect and ping a IP camera no problem. here is my code I am using:
#include <Ethernet.h>
#include <SPI.h>
#include <Servo.h>
//send a sequence to the arduino via your web browser like so: http://192.168.1.167/?23456789
//The way the code is currently setup is that the pins will go high one at a time, in sequence, for 25ms then move on to the next in line. So this example would blink pin 2,3,4,5,6,7,8 then 9.
// pin 9 controlls a servo
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
boolean reading = false;
////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte ip[] = { 169,78, 32, 18 }; //ip address to assign the arduino
byte gateway[] = {169, 78, 32, 10 }; //ip address of the gatewa or router
//Rarly need to change this
byte subnet[] = { 255, 255, 0, 0 };
// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Server server = Server(80); //port 80
////////////////////////////////////////////////////////////////////////
void setup(){
//Pins 10,11,12 & 13 are used by the ethernet shield
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
Serial.print(c);
switch (c) {
case '2':
//add code here to trigger on 2
triggerPin(2, client);
break;
case '3':
//add code here to trigger on 3
triggerPin(3, client);
break;
case '4':
//add code here to trigger on 4
triggerPin(4, client);
break;
case '5':
//add code here to trigger on 5
triggerPin(5, client);
break;
case '6':
//add code here to trigger on 6
triggerPin(6, client);
break;
case '7':
//add code here to trigger on 7
triggerPin(7, client);
break;
case '8':
//add code here to trigger on 8
triggerPin(8, client);
break;
case '9':
//add code here to trigger on 9
triggerPin(9, client);
break;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void triggerPin(int pin, Client client){
//blink a pin - Client needed just for HTML output purposes.
switch (pin){
case 8:
{client.print("Opening Door");
client.print("<br>");
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
break;}
case 9:{
client.print("Closing Door");
client.print("<br>");
for(pos = 180; pos> 0; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
break;}
default:
{
client.print("Turning on pin ");
client.println(pin);
client.print("<br>");
digitalWrite(pin, HIGH);
delay(25);
digitalWrite(pin, LOW);
delay(25); break;}
}
}