D
D
DVoropaev2017-07-26 14:55:48
Arduino
DVoropaev, 2017-07-26 14:55:48

Why won't arduino connect via ethernet?

Board - Arduino Mega, Arduino Uno (tried on both)
as an adapter - enc28j60
20130814093820798.JPG
Network setup: fe5a5485c4354a6a93549b18159b086f.png
Sketch:

#include <UIPEthernet.h>
#include <ethernet_comp.h>
#include <UIPClient.h>
#include <Dhcp.h>
#include <Dns.h>
#include <UIPUdp.h>


byte mac[] = {  0x94, 0xDE, 0x80, 0x3A, 0x90, 0xC9 }; //MAC-адрес Arduino
const unsigned long postingInterval = 600000;  // интервал между отправками
                                               // данных - 10 минут
// IP-адрес, назначаемый Ethernet shield:
byte ip[] = { 192, 168, 0, 2 };   
// IP-адрес, dns сервера:
byte sdns[] = { 192, 168, 0, 1 };   
// адрес шлюза:
byte gateway[] = { 192, 168, 0, 1 };
// маска:
byte subnet[] = { 255, 255, 255, 0 };
 
IPAddress server(192, 168, 0, 1); // IP сервера
//IPAddress server(91,122,49,168); // IP сервера
EthernetClient client;
unsigned long lastConnectionTime = 0;   // время последней передачи данных
boolean lastConnected = false;          // состояние подключения
char replyBuffer[160];
 
void setup()
  {
  Serial.begin(9600);
  // Ethernet connection:
  Ethernet.begin(mac,ip,sdns,gateway,subnet);
  // секунда для инициализации Ethernet
  delay(1000);
  //первое соединение через 15 секунд после запуска
  lastConnectionTime = millis()-postingInterval+15000;
}
 
void loop()
  {
    lastConnected = client.connected();
    Serial.println(lastConnected);
    delay(1000);
  }

Connected to laptop via ethernet. The port monitor displayed 0 (connection not established).
Looked into the arp table. She was empty.
Tried to ping:
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
From 192.168.0.1 icmp_seq=1 Destination Host Unreachable
From 192.168.0.1 icmp_seq=2 Destination Host Unreachable
From 192.168.0.1 icmp_seq=3 Destination Host Unreachable
From 192.168.0.1 icmp_seq=4 Destination Host Unreachable
^C
--- 192.168.0.2 ping statistics ---
18 packets transmitted, 0 received, +4 errors, 100% packet loss, time 17075ms
pipe 13

At the same time, on the adapter (on the ethernet connector itself, the green indicator was on, and orange was blinking (what does this mean?).
I looked again at the arp table:
? (192.168.0.2) в <не завершено> на enp3s0
then I added a new entry:
[email protected]:~$ sudo ip neigh add 192.168.0.2 llad 94:DE:80:3A:90:C9 dev enp3s0
[email protected]:~$ arp -a
? (192.168.0.2) в 94:de:80:3a:90:c9 [ether] PERM на enp3s0

Nothing has changed
. Before that, I tried to connect it to the router (I wrote down the ip address of the router, the network mask, the gateway, everything was as it should be in the sketch). The router did not see it (it was not in the list of clients), tried to ping, but it did not give any results.
How can I check if it is connected or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2017-08-02
@vanyamba-electronics

If memory serves me right, then the gateway is the address of the router should be. And in this case, the address of the Arduino is the same as the address of the router. Try setting it to 192.168.0.101.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question