Answer the question
In order to leave comments, you need to log in
Why won't arduino connect via ethernet?
Board - Arduino Mega, Arduino Uno (tried on both)
as an adapter - enc28j60
Network setup:
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);
}
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
? (192.168.0.2) в <не завершено> на enp3s0
[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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question