I am using ENC28J60 and EthernetENC library to connect an Arduino UNO with ATmega328 to the network. Everything works fine within the local network, but outside of it, I cannot ping the device. What could be the problem? The network settings are 100% correct (other devices work fine, and examples from the Ethernet library also respond to pings).
////////////////////////////////////// Settings //////////////////////////////////////
#define DHCP false // true/false
#define CUSTOM_MAC true // true/false
#if CUSTOM_MAC // if true you can enter your custom mac address
#define MAC 0x00,0x5f,0x1C,0x05,0x5f,0x1C
#else
#define MAC 0x00,0x5f,0x1C // Organizationally Unique Identifier (OUI)
#endif
#define IP_ADDRESS 192,168, 11,242
#define SUBNET 255,255,255,248
#define GATEWAY 192,168, 11,241
#define DNS 192,168, 11,241
// #define UIP_CONF_MAX_CONNECTIONS 0
///////////////////////////////////// Libraries //////////////////////////////////////
#include <Arduino.h>
#include <EthernetENC.h> // Include the Ethernet library
#include <Agentuino.h> // SNMP library
#include <EEPROM.h>
#include <microDS18B20.h>
/////////////////////////////// Arduino sensor pins //////////////////////////////////
#define TEMPERATURE_1_PIN 0
#define TEMPERATURE_2_PIN 1
#define TEMPERATURE_3_PIN 2
#define TEMPERATURE_4_PIN 3
#define SENSOR_220V_PIN 4
#define SERVO_PIN 5
#define LED_ALERT_PIN 6
#if !SOUND_MUTE
#define SPEAKER_PIN 7
#else
#define SPEAKER_PIN 8
#endif
#define FLOOD_PIN A0
#define DOOR_PIN A1
#define GAS_PIN A2
///////////////////////////// Ethernet / SNMP init ///////////////////////////////////
#if !DHCP
IPAddress ip(IP_ADDRESS); // IP Address for arduino
IPAddress gateway(GATEWAY); // Gateway for arduino
IPAddress subnet(SUBNET); // SubNet mask for arduino
IPAddress myDns(DNS); // DNS for arduino
#endif
byte mac[] = {MAC};
//////////////////////////////////// My OIDs /////////////////////////////////////////
...
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// function SNMP resived ////////////////////////////////
void pduReceived(){...}
//////////////////////////////////////////////////////////////////////////////////////
void setup(){
///////////////////////////////// init pins ////////////////////////////////////
pinMode(TEMPERATURE_1_PIN, INPUT);
pinMode(TEMPERATURE_2_PIN, INPUT);
pinMode(TEMPERATURE_3_PIN, INPUT);
pinMode(TEMPERATURE_4_PIN, INPUT);
pinMode(SENSOR_220V_PIN, INPUT);
// pinMode(SERVO_PIN, INPUT);
pinMode(FLOOD_PIN, INPUT);
pinMode(DOOR_PIN, INPUT);
pinMode(GAS_PIN, INPUT);
pinMode(LED_ALERT_PIN, OUTPUT);
#if !SOUND_MUTE
pinMode(SPEAKER_PIN, OUTPUT);
#endif
////////////////////////////// init other //////////////////////////////////////
Serial.begin(9600); // Serial monitor init
Agentuino.begin(); // Begin Snmp agent on Ethernet shield
///////////////////////// Generate random mac address //////////////////////////
#if !CUSTOM_MAC
if (EEPROM[0] == 255 && EEPROM[1] == 255 && EEPROM[2] == 255){
for (int i = 3; i < 6; i++){
randomSeed(analogRead(A5));
mac[i] = random(0xFF);
EEPROM.put(i - 3, mac[i]);
}
}
else{
for (int i = 3; i < 6; i++){
EEPROM.get(i - 3, mac[i]); // Reed saved mac addres from EEPROM
}
}
#endif
#if DHCP
Ethernet.begin(mac) // Initialize Ethernet Shield in DHCP mode
#else
Ethernet.begin(mac, ip, myDns ,gateway, subnet); // Initialize Ethernet Shield in static mode
#endif
///////////////////////////////////// Debug //////////////////////////////////////
Serial.println();
Serial.println();
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :("));
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
delay(500);
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
}
Serial.print(F("localIP: "));
Serial.println(Ethernet.localIP());
Serial.print(F("dnsServerIP: "));
Serial.println(Ethernet.dnsServerIP());
Serial.print(F("gatewayIP: "));
Serial.println(Ethernet.gatewayIP());
Serial.print(F("subnetMask: "));
Serial.println(Ethernet.subnetMask());
Serial.print(F("mac: "));
for (int i = 0; i < 6; i++){
Serial.print(mac[i], HEX);
if (i <= 4) Serial.print(F("."));
}
Serial.println();
////////////////////////////////////////////////////////////////////////////////
Agentuino.onPduReceive(pduReceived);
delay(10);
}
void loop(){
Agentuino.listen();
//////////////////////////////// Other code ////////////////////////////////////
...
////////////////////////////////////////////////////////////////////////////////
}