title: Communicating between Raspberry Pi and Arduino over LAN
body: <p>I'm doing image processing with a raspberry pi, and I want it to be able to talk to my arduino over LAN to steer a light beam based on the pi's instructions. The only things I've seen a lot are direct connections between the Pi and the Arduino. It may seem naive of me, but I was trying to have them communicate using the Arduino as a server, programmed with the Ethernet library, and the Raspberry Pi as the client through the socket library. I gave them both static IP's on my router, and used the following code to try and get through, but I was met with <code>socket.error: [Errno 113] No route to host</code> when my python line came to the command to connect to the Arduino's IP through a specific port.</p>
  
  <p>Any ideas on how I could more properly do this connection? The main goal for me is to be able to do this over LAN, so the USB connections and the direct I2C connections aren't helpful, though they would definitely get the job done.</p>
  
  <p>Raspberry Pi:</p>
  
  <pre><code>from socket import *
  import select
  
  data = None
  
  timeout = 3 # timeout in seconds
  msg = "test"
  
  host = "192.168.1.113"
  print ("Connecting to " + host)
  
  port = 23
  
  s = socket(AF_INET, SOCK_STREAM)
  print "Socket made"
  
  ready = select.select([s],[],[],timeout)
  
  
  s.connect((host,port))
  print("Connection made")
  
  while True:
  
      if data != None:
          print("[INFO] Sending message...")
          s.sendall(msg)
          data = None
          print("[INFO] Message sent.")
          continue
  
      if ready[0]:        #if data is actually available for you
          data = s.recv(4096)
          print("[INFO] Data received")
          print data
          continue
  </code></pre>
  
  <p>Arduino:</p>
  
  <pre><code>//90-a2-da-0f-25-E7
  byte mac[] = {0x90, 0xA2, 0xDA, 0x0f, 0x25, 0xE7};
  
  //ip Address for shield
  byte ip[] = {192,168,1,113};
  
  //Use port 23
  EthernetServer server = EthernetServer(23);
  
  void setup() {
    //init device
    Ethernet.begin(mac,ip);
    //start listening for clients
    server.begin();
  
    Serial.begin(9600);     //For visual feedback on what's going on
    while(!Serial){
      ;   //cause Leonardo
    }
    delay(1000);
    if(server.available()){
    Serial.write("Client available");
  }
  }
  
  void loop() {
    // put your main code here, to run repeatedly:
    EthernetClient client = server.available();
      if (client == true){
        Serial.write("Client Connected.");
  
        if(client.read() &gt; 0){
          Serial.write(client.read());        
        }
        else{
          server.write("ping");
        }
      }
      else{
        Serial.println("No one's here yet...");
      }
      delay(1500);
  }
  </code></pre>