socket_connect() - Error 113 - PHP

Asked

Viewed 93 times

0

I’m trying to make an Arduino receive data according to a structure PHP. Explaining quickly, when the user changes the status, between 0 e 1, the same would send a signal to the Arduino according to what was chosen and the Arduino receiving this data, depending on it, turn on or turn off the LED. The code I use in Arduino is as follows:

#include <SPI.h>
#include <Ethernet.h>

//Configurações do Ethernet Shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 101 }; // ip que o arduino assumirá
byte gateway[] = { 192,168,0, 1 };  // ip do roteador
byte subnet[] = { 255, 255, 255, 0 };

// String que representa o estado dos dispositivos
//char Luz[7] = "0000L#";

EthernetServer server(80); // Cria o servidor na porta 8081

// String onde é guardada as msgs recebidas
char msg[7] = "0000L#";

void setup() {
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  //pinMode(A0,OUTPUT);
  //pinMode(A1,OUTPUT);
  //pinMode(A2,OUTPUT);
  //pinMode(A3,OUTPUT);
  //pinMode(A4,OUTPUT);
  //pinMode(A5,OUTPUT);
  // Configura o pino d13 como saída 
  pinMode(13, OUTPUT);
}

void loop() {
 EthernetClient client = server.available();
  // SE receber um caracter...
  if (client) {
    // guarda o caracter na string 'msg'
    msg[6] = client.read();

    switch(msg[6]) {
      case 0:
          // Configura o pino 13 como HIGH
          digitalWrite(13, HIGH);
      break;
      case 1:
          // Configura o pino 13 como LOW
          digitalWrite(13, LOW);   
      break;
    }
  }
}

And the code in my file PHP, that makes the communication with the Arduino is the following:

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    // Se conecta ao IP e Porta:
socket_connect($sock,"192.168.0.101", 80);

if (!socket_connect($sock, "192.168.0.101", 80)){
    die('Socket error : '.socket_strerror(socket_last_error()));
}

$msg = 0;

// Executa a ação correspondente ao botão apertado.
if($status == 0) {
    $msg = 0;
    socket_write($sock,$msg,strlen($msg));
} else if($status == 1){
    $msg = 1;
    socket_write($sock,$msg,strlen($msg));
}

//socket_write($sock,'R#',2); //Requisita o status do sistema.

// Caso ele não receba o status corretamente, avisa erro.
//else { echo "Falha ao receber status da casa."; }
socket_close($sock);

When I change the status and the above code is executed, it returns me the following error:

socket_connect() unable to connect 113 no route to host

In this case, both the Arduino and my computer are connected to a router and the Arduino "takes" the IP normally. When I drop in Arduino, I get response normally, but when I run the code described above, I can’t do this communication.

  • I don’t know Greenland or php, but there’s one thing that seems strange to me: socket_connect is being called twice, one after the other...this is right ?

  • @zentrunix In this case, the second time I call her is to test the connection, to see if everything is correct or not and if the connection does not work out, to be able to see what the error is, which in this case is what is described in the question.

  • I think it should be just a connect...but it would give error 56, not 113...I suspect that after you solve error 113 (route error) this error 56 will appear.... a simple test that you can do with respect to the route error would be to make a telnet for the Arduino "telnet 192.168.0.101 80" and see if it works... nay work then the error is not in your program, but in your network configuration

  • @zentrunix At the moment, now I have no way to do this test. As soon as I do I give back. If the error is on my network, how could I proceed to resolve this issue?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.