Git Product home page Git Product logo

ethernetenc's Introduction

First an important note: There are more suitable libraries for ENC28J60 with ESP8266, RP2040, ESP32 and Mbed Arduino platforms:

  • With ESP8266 and RP2040 platform you can use the EthernetCompat.h from the lwIP_enc28j60 bundled library.
  • With ESP32 platform version 3 you can use the EthernetESP32 library which integrates with networking on the ESP32 platform.
  • With Arduino Mbed Core boards you can use the ENC28J60-EMAC library with the platforms Ethernet library

EthernetENC

EthernetENC is the Ethernet library for ENC28J60. It is a modern version of the UIPEthernet library.

The modernization includes:

  • Ethernet 2.0.0 Arduino library functions
  • compatible include file names EthernetClient.h, EthernetServer.h and EthernetUdp.h
  • support of many Arduino architectures by using the SPI library
  • SPI transactions to share the SPI bus with devices with different communication settings
  • SPI communication at 20 MHz if the MCU supports it, else on the maximum supported by the MCU
  • client.flush() to send the packet immediately
  • calls yield() in blocking functions
  • has UDP backlog to receive more than one message at time
  • Arduino 1.5 library format built with dot_a_linkage option for optimal build result

The documentation of Arduino Ethernet library applies for classes and functions descriptions.

Limitations:

  • UDP.beginMulticast is not supported, because the uIP stack doesn't support multicast
  • UDP broadcasts receiving is turned off on ENC to lower the processing load on the library

This library doesn't have examples, because examples of the Arduino Ethernet library apply. You can find them in the Arduino IDE Examples menu Ethernet section. Only change #include <Ethernet.h> to #include <EthernetENC.h>. Some examples require a little change.

This library is based on the Norbert Truchsess's arduino-uip original source code repository and uses experience from the development of the multi-architecture support by Cassy. Applicable fixes and enhancements from development of EthernetENC were transfered to Cassy's UIPEthernet.

You can find more information in project's Wiki.

Original notes by Norbert Truchsess

UIPEthernet is written as a wrapper around the mature uIP Stack by Adam Dunkels, which provides the low-level implementation for all supported protocols. To overcome the memory-constrains (a 'regular' uIP-application does all processing in RAM) the ENC28J60 internal memory is used for all stream buffers (in and out). Only 400-600 Bytes of Arduinos RAM are used (depending on the number of concurrently open connections). As of Flash-memory a ATmega368-based Arduino is the minimum requirenment.

uIP was written by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.

This library was inspired by the SerialIP implementation by Adam Nielsen [email protected], actually I took this code as a starting point, but in the latest versions there are very few lines left.

Licenses

UIPEthernet.h
UIPEthernet.cpp
UIPServer.h
UIPServer.cpp
UIPClient.h
UIPClient.cpp
UIPUdp.h
UIPUdp.cpp
utility/mempool.h
utility/mempool.cpp

Copyright (c) 2013 Norbert Truchsess <[email protected]>
All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

--------------

utility/enc28j60.h

Author        : Pascal Stang (c)2005
Modified by Norbert Truchsess
Copyright: GPL V2

--------------

utility/Enc28J60Network.h
utility/Enc28J60Network.cpp

Copyright (c) 2013 Norbert Truchsess <[email protected]>
All rights reserved.

inspired and based on enc28j60.c file from the AVRlib library by Pascal Stang.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

--------------

utility/uip.c
utility/uip_arp.h
utility/uip_arp.c
utility/uip_arch.h
utility/uip.h
utility/uipopt.h

Copyright (c) 2001-2003, Adam Dunkels <[email protected]>, <[email protected]>.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. Neither the name of the Institute nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

--------------

Dhcp.h
Dhcp.cpp

DHCP Library v0.3 - April 25, 2009
Author: Jordan Terrell - blog.jordanterrell.com
- as included in Arduinos stock Ethernet-library, no special licence mentioned here

--------------

Dns.h
Dns.cpp

(c) Copyright 2009-2010 MCQN Ltd.
Released under Apache License, version 2.0

ethernetenc's People

Contributors

brunnels avatar hideakitai avatar jandrassy avatar nilrog avatar ntruchsess avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethernetenc's Issues

Problem getting http data at 256th char

Hi, I have this problem getting http response from my server. After the http header, the server simply responds with a string:
%ACK192168002098008008008008192168002001255255255000
This is a mark (“%”), an acknoledgment for the client and four ipaddresses; this string is done by a simple php script.
Using the code below, after the mark I get:
ACK19216800209800800800800819216800⸮2001255255255000
After some test, I see the junk char is -1 and it occur after 255 char retrieved.
Please note that this issue does not occur using the same code but UIPEthernet library

#include <EthernetENC.h>
#include <SPI.h>

char server_name[] = "receiver.xxx.eu";

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte static_ip[] = { 192, 168, 2, 177 };
byte static_dns[] = { 8, 8, 8, 8 };
byte static_gw[] = { 192, 168, 2, 1 };
byte static_mask[] = { 255, 255, 255, 0 };

byte server_ip[] = { 1xx, 2xx, 1xx, 141 };

EthernetClient client;

// ------------------

void setup()
{
Ethernet.begin(mac, static_ip, static_dns, static_gw, static_mask);
Serial.begin(9600);
delay(1000);
}

// ------------------

void loop() {
sendGET();
delay(2000);
}

// ------------------

void sendGET() {
char c;
int counter;
Serial.print(F("Connecting ... "));
if (client.connect(server_ip, 80)) {
Serial.println("Connected to ");
Serial.println(client.remoteIP());

client.print(F("GET /service_door.php?service=router_power_on&router_type=eth&router=000999"));
client.print(F("&lip="));
client.print(Ethernet.localIP());
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(server_name);
client.println(F("Connection: close"));
client.println();

while(client.connected() && !client.available()) delay(1); //waits for data
if (client.connected() || client.available()) { //connected or data available
  while (client.read() != '%') {}
  for (int i = 0; i < 52; i++) {
    c = client.read();
    Serial.print(c);
  }
  Serial.println();      
}  

} else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
client.stop();
}

// ------------------

lwIP_enc28j60

Hello,

In the readme I see the following statement:
"For esp8266 Arduino there is a much better option for enc28j60 than using this library. Use the lwIP_enc28j60 library bundled with esp8266 Arduino boards support package 3."

Can you please give me more details about that? Do you know some guide explaining how to use lwIP_enc28j60 for ESP8266?

Thank you in advanced.

trying to send broadcast SSDP message

Hi, I am trying to send broadcast SSDP, based on this example
https://github.com/arduino-libraries/Ethernet/blob/master/examples/UDPSendReceiveString/UDPSendReceiveString.ino
by changing the IP to 239:255:255:250 and the port to 1900.
But I don't receive any message on Wire Shark.
This is my code:

#include <EthernetENC.h>
#include <EthernetUdp.h>

#define UDP_TX_PACKET_MAX_SIZE 24

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(239, 255, 255, 250);

unsigned int localPort = 1900;      // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged";        // a string to send back
EthernetUDP Udp;

void setup() {
    Serial.begin(115200);
    Serial.println("START");
  Ethernet.init(25);  // Most Arduino shields
  Ethernet.begin(mac);
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("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) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start UDP
  Udp.begin(localPort);
  Serial.printf("local IP is %s \n", Ethernet.localIP().toString());
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) 
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i=0; i < 4; i++) {
      Serial.print(remote[i], DEC);
      if (i < 3) {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBuffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply to the IP address and port that sent us the packet we received
  }
    Udp.beginPacket(ip, localPort);
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  delay(10);
}  

Ping command with ENC28J60 + D1 mini Wemos ESP8266

I am using EthernetENC.h library ver. 2.0.4 with hardware ENC28J60 + D1 mini Wemos ESP8266 boards.
I program the ESP8266 with Arduino IDE 2.1.0; I tested the example sketch “WebClient” and it works correctly.
I would like to run the "ping" command on an IP address on my local network trought the ENC28J60 device. Could somebody suggest to me if there is a function available to do it?
Thanks

[FR] Project Examples for PlatformIO Registry

Hi,

Currently, the library page in the PlatformIO Registry doesn't contain any quick start projects for developers. Such examples serve both to highlight widespread use cases and to help newcomers to get up and running much more quickly.

Please consider adding a few comprehensive project examples to the PlatformIO Registry.

Useful links:

Enc28j60 Hangs or freeze

Hi, i am a newbee...
i have been trying to connect ENC28j60 with ESP 32s .. CS Pin 14.
i m able to communicate with my HMI with IP 192.168.1.100 and getting modbus tcp replies from it..
after running for 7 hours it freezes while sending the modbus request data to the HMI.
currently i am using WDT to reset if the system if it is not responding for more than 2 minutes...
i am trying to poll for every one minute... no memory leaks...
here is my code.. (removed the WDT part)..

#include <EthernetENC.h>
#include <SPI.h>

//modbus tcp
const int MODBUS_CONNECT_ERROR = -10;
const int MODBUS_NO_RESPONSE = -11;
const byte FNC_READ_REGS = 0x03;
const byte FNC_WRITE_SINGLE = 0x06;
const byte FNC_ERR_FLAG = 0x80;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
const int ETH_CS_PIN = 14;
const IPAddress isgAddress(192, 168, 1, 100);
EthernetClient client;
int clientstatus = 0;
IPAddress ip(192, 168, 1, 10);
IPAddress gateway(192, 168, 1, 1);
IPAddress DNSServer(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
String hostname = "ESP32";
int rst_Ethernet = 0;
int client_value = 0;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  pinMode(14, OUTPUT);
  digitalWrite(14, LOW);
  delay(2000);
  Serial.println("Configuring Ethernet");
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(4, HIGH);
  //pinMode(4,INPUT);
  delay(3000);
  Ethernet.init(ETH_CS_PIN);
  Ethernet.begin(mac, ip, gateway, DNSServer, subnet);
  ethernet_connect();
}

int tests(Client &client) {
  short regs[16];
  int res = modbusRequest(client, 1, 0, 8, regs);
  if (res != 0)
    return res;
  return 0;
}

void ethernet_connect() {
  client.connect(isgAddress, 8888);
  while (!client.connected()) {
    client.connect(isgAddress, 8888);
    Serial.println("Trying to Connect TCP...");
    delay(3000);
  }
  if (client.connected()) {
    client.setTimeout(1000);
    Serial.println("client connected");
    clientstatus = 0;
  } else {
    
    Serial.println("connection failed");
  }
  
}

int modbusRequest(Client &client, byte uid, unsigned int addr, byte len,
    short *regs) {
  const byte CODE_IX = 7;
  const byte ERR_CODE_IX = 8;
  const byte LENGTH_IX = 8;
  const byte DATA_IX = 9;
  
  byte request[] = { 0, 1, 0, 0, 0, 6, uid, FNC_READ_REGS, (byte) (addr / 256),
      (byte) (addr % 256), 0, len };
  Serial.println("Request");
  String bt_data = "";
  for (int i = 0; i < sizeof(request); ++i) {
    Serial.print(request[i], HEX);
    Serial.print(' ');
    bt_data += String(request[i], HEX);
  }
  Serial.println("");
  
  unsigned long Eth_currentMillis = millis(); // store the current time
      
  client.write(request, sizeof(request));
  int respDataLen = (len * 2);
  byte response[max((int) DATA_IX, respDataLen)];
  Serial.println("Response");
  int readLen = client.readBytes(response, DATA_IX);
  if (readLen < DATA_IX) {
    return MODBUS_NO_RESPONSE;
  }
  switch (response[CODE_IX]) {
    case FNC_READ_REGS:
      break;
    case (FNC_ERR_FLAG | FNC_READ_REGS):
      return response[ERR_CODE_IX]; // 0x01, 0x02, 0x03 or 0x11
    default:
      return -3;
  }
  readLen = client.readBytes(response, respDataLen);
  String br_data = "";
  for (int i = 0; i < respDataLen; ++i) {
    Serial.print(response[i], HEX);
    Serial.print(' ');
    br_data += String(response[i], HEX);
  }
  return 0;
}

void loop() {
  Ethernet.maintain();
  int res = tests(client);
  if (res != 0) {
    Serial.print("modbus error ");
    Serial.println(res);
  }
  Serial.println(ESP.getFreeHeap());
  delay(100);
}

Creating a PING request using EthernetENC

Hi, I'm using an ENC20J60 ethernet adapter, this is connected via SPI to an Arduino UNO.

What I'm attempting to do is to send a "ping"/ICMP message to another device on the network, in order to take some action when that device goes off line.

I've looked at many of the posts on the Arduino forum, and all of them recommend using ICMP libraries that are specific to the Wiznet Chips that the usual shields use, I have yet to find anything that works with this library and/or the ENC20J60.

My 2 questions are thus as follows:

  1. Are there any ICMP libraries for the Arduino IDE V2 that you know of that work with the combination given above, and specifically your library.

  2. Failing that, I could write my own implementation, but I don't see anything in this library (Using the Arduino documentation as mentioned in the wiki) that would allow me to craft a raw packet at byte level and send it.

If anyone here has any pointers on how I can achieve my goal, I'd be very much thankful for the help.

Either that, or I'll have to dump the box of ENC based devices I have, and order Wiznet based devices :-)

Cheers
Shawty

Soft Reset of the ESP8266

Hi,
I have connected ESP8266 to ENC28J60. Using 5 and 4 pins for CS and Reset respectively.
Following code works beautifully well.

#include <EthernetENC.h>

typedef unsigned char N8;

#define LED D0

EthernetServer server(port);
uint8_t mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip = {192,168,131,171};
uint8_t myDns[] = {192,168,131,1};

unsigned long ledmil;
unsigned char ledon=0;
unsigned char xmbuf[60];
unsigned char datrdy=0;
int xmcnt;

//=======================================================================
// Power on setup
//=======================================================================
void setup()
{
Serial.begin(9600);
Serial.println();

pinMode(4, OUTPUT);
digitalWrite(4,LOW);
delay(100);
digitalWrite(4,HIGH);

Ethernet.init(5);
Ethernet.begin(mac,ip,myDns); //Connect to wifi

Serial.println(Ethernet.localIP());
server.begin();
ledmil=millis();
}
//=======================================================================
// Loop
//=======================================================================
unsigned char buf;
unsigned long curmil;

void loop()
{
EthernetClient client = server.available();

if (client) {
if(client.connected())
{
Serial.println("Client Connected");
}

while(client.connected()){      
  while(client.available()>0){
    // read data from the connected client
    buf=client.read();
    Serial.write(buf); 
    if(buf=='X')
      { sprintf((char *)xmbuf,"Hello World1"); datrdy=1; }
    else if(buf=='B')
      { sprintf((char *)xmbuf,"Hello World2"); datrdy=1; }
    Ethernet.maintain();
  }
  //Send Data to connected client
  while(Serial.available()>0)
 {
    client.write(Serial.read());
  }

}
client.stop();
Serial.println("Client disconnected");
Ethernet.maintain();
}
Ethernet.maintain();
}//=======================================================================

However, moment I replace
while(Serial.available()>0)
{
client.write(Serial.read());
}

with
if(datrdy)
{
client.write (xmbuf,13');
datrdy=0;
}
ESP8266 starts resetting randomly on receipt of data.

Soft WDT reset >>>stack>>> ctx: cont sp: 3ffffd10 end: 3fffffc0 offset: 01a0 3ffffeb0: 3ffe85d9 3ffee852 00000000 40100298 3ffffec0: 3ffe85d9 3ffee852 39000000 40203bcf 3ffffed0: 3ffee852 3fffff80 3ffee852 3ffee8f8 3ffffee0: 3ffee852 3fffff80 00000039 40203d60 3ffffef0: 00000000 00000000 3ffee5a7 4020420e 3fffff00: 00001d83 3ffe0001 40100209 00000000 3fffff10: 00001f84 3fffff60 3fffff80 3ffee8f8 3fffff20: 3fffdad0 3ffee538 3ffee5a7 3ffee8f8 3fffff30: 3fffdad0 3fffff80 3ffee5a7 402028cd 3fffff40: 3fffdad0 3ffee538 3ffee539 3ffee8f8 3fffff50: 3fffdad0 3fffff80 3fffff80 40202d8c 3fffff60: 3fffdad0 0000000a 3ffee539 40202f1e 3fffff70: 3fffdad0 3ffee538 3ffee539 40202717 3fffff80: 40208f54 00000000 000003e8 40100168 3fffff90: 00000000 3ffee5aa 3ffee8e4 40100189 3fffffa0: feefeffe 00000000 3ffee8e4 402062ec 3fffffb0: feefeffe feefeffe 3ffe85ec 40100bc9 << --------------- CUT HERE FOR EXCEPTION DECODER ---------------

I am clueless about it as of now.

Request setting custom hostName

Hi there, currently the hostname is hardcoded to ENC28J + the last three hex digits of the MAC address:

https://github.com/JAndrassy/EthernetENC/blame/master/src/Dhcp.cpp#L195-L201

I was wondering if it could be possible to set it to a custom value? Perhaps something akin to this PR that is for WIZnet's Ethernet.h?
arduino-libraries/Ethernet#77

Great work BTW, I'm very impressed by how smooth this chip works. I didn't expect it to perform this good, so I appreciate your great library!

Fragmented Packets

Hi!
Thanks for all your work.

I'm trying to read a UDP packet from a device. After checking out the packet with wireshark I realized it is a fragmented packet, of about 4500 bytes. I do see packets of < 1500 bytes on the enc28j60.

I found the UIP_REASSEMBLY define in uipopt.h, I tried setting it to 1 and increasing UIP_BUFSIZE and UIP_REASS_MAXAGE but I'm still not seeing my packets.

Am I missing something ? Should this be possible ? I'm using an esp32.

Thanks!

ENC28J60 with Esp32 HTTP request

I have being try to set get request to my nodejs Server. On the upload first time the connection with the server is extablished, later if reboted the server fails to connect

#include <EthernetENC.h>
#include "esp_system.h"
#include <Update.h>
#include <EthernetENC.h>
#include <SPI.h>
#include <EthernetClient.h>


uint8_t mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip = {192,168,131,183};
IPAddress bc = {255,255,255,255};
IPAddress subnet = {255,0,0,0};
uint8_t myDns[] = {192,168,131,1};
char buf[100];

char serverAddress[] = "60.254.18.10"; // Server IP address
int serverPort = 5000;           // Server port
char temp[]="5000";
char path[] = "/?AUTH=adwdscsdc342423423rw@$@";
char host[] = "192.168.131.100:5000";


void setup(){
  Serial.begin(115200);
  Serial.println("Hello Esp32");
  Ethernet.init(2);
  Ethernet.begin(mac, ip, myDns, myDns, subnet);
  int checkLink = Ethernet.linkStatus();
  int checkHwd = Ethernet.hardwareStatus();

    //Cabel & Hardware Check
    while (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("ENC: not found");
      delay(1000);
    }

    while (Ethernet.linkStatus() != LinkON){
       Serial.println("ENC: cable not found");
       delay(1000);
    }
    Serial.println(Ethernet.localIP());
    GET(serverAddress,serverPort,"/checkOtaM/KVAR-1");
    
  
}
int count =0;
void loop(){
  Ethernet.maintain();
  delay(1000);
  if(count==5){
    ESP.restart();
  }else{
    count = count +1;
  }
}

void GET(const char* host, int port, const char* path){

  Serial.println("Check Status : Init");
  EthernetClient ethClient2;
  if (!ethClient2.connected()) { // Check if ethClient2 is not connected
    //ethClient2.flush();
    ethClient2.stop(); // Disconnect any previous connection
  }
   if (ethClient2.connect(host, port)) {
    Serial.println("Connected to server");

    // Send HTTP request
    ethClient2.print("GET ");
    ethClient2.print(path);
    ethClient2.println(" HTTP/1.1");
    ethClient2.print("Host: ");
    ethClient2.println(host);
    ethClient2.println("Connection: close");
    ethClient2.println();
    
    size_t totalBytesReceived = 0;
    bool bodyStarted = false; // Flag to indicate if HTTP response body has started
    String Body;
    while (ethClient2.connected() || ethClient2.available()) {
      if (ethClient2.available()) {
        char c = ethClient2.read();
        if (bodyStarted) {
//          file.write(c);
          Body = Body + c ;
          totalBytesReceived++;
        } else if (c == '\r' || c == '\n') {
          // Check for end of headers
          if (ethClient2.available() && ethClient2.peek() == '\r') {
            // Skip '\r\n\r\n' which indicates the end of headers
            ethClient2.read();
            ethClient2.read();
            bodyStarted = true;
          }
        }
      } else {
        delay(1);
      }
    }
  Serial.println(" Check OTA Body: " + Body);
  ethClient2.stop();
  }
}

Output
"rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:58:53.586 -> configsip: 0, SPIWP:0xee
10:58:53.586 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:58:53.586 -> mode:DIO, clock div:1
10:58:53.586 -> load:0x3fff0030,len:1184
10:58:53.586 -> load:0x40078000,len:13220
10:58:53.586 -> ho 0 tail 12 room 4
10:58:53.586 -> load:0x40080400,len:3028
10:58:53.586 -> entry 0x400805e4
10:58:53.727 -> Hello Esp32
10:58:53.773 -> 192.168.131.183
10:58:53.773 -> Check Status : Init
10:58:54.333 -> Connected to server
10:58:54.472 -> Check OTA Body: Master True
10:59:00.486 -> ets Jun 8 2016 00:22:57
10:59:00.486 ->
10:59:00.486 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:59:00.486 -> configsip: 0, SPIWP:0xee
10:59:00.486 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:59:00.486 -> mode:DIO, clock div:1
10:59:00.486 -> load:0x3fff0030,len:1184
10:59:00.486 -> load:0x40078000,len:13220
10:59:00.486 -> ho 0 tail 12 room 4
10:59:00.486 -> load:0x40080400,len:3028
10:59:00.486 -> entry 0x400805e4
10:59:00.672 -> Hello Esp32
10:59:00.719 -> 192.168.131.183
10:59:00.719 -> Check Status : Init
10:59:11.716 -> ets Jun 8 2016 00:22:57
10:59:11.716 ->
10:59:11.716 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:59:11.762 -> configsip: 0, SPIWP:0xee
10:59:11.762 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:59:11.762 -> mode:DIO, clock div:1
10:59:11.762 -> load:0x3fff0030,len:1184
10:59:11.762 -> load:0x40078000,len:13220
10:59:11.762 -> ho 0 tail 12 room 4
10:59:11.762 -> load:0x40080400,len:3028
10:59:11.762 -> entry 0x400805e4
10:59:11.902 -> Hello Esp32
10:59:11.948 -> ENC: cable not found
10:59:12.974 -> 192.168.131.183
10:59:12.974 -> Check Status : Init
10:59:24.011 -> ets Jun 8 2016 00:22:57
10:59:24.011 ->
10:59:24.011 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:59:24.011 -> configsip: 0, SPIWP:0xee
10:59:24.011 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:59:24.011 -> mode:DIO, clock div:1
10:59:24.011 -> load:0x3fff0030,len:1184
10:59:24.011 -> load:0x40078000,len:13220
10:59:24.011 -> ho 0 tail 12 room 4
10:59:24.011 -> load:0x40080400,len:3028
10:59:24.011 -> entry 0x400805e4
10:59:24.149 -> Hello Esp32
10:59:24.196 -> ENC: cable not found
10:59:25.209 -> 192.168.131.183
10:59:25.209 -> Check Status : Init
10:59:36.238 -> ets Jun 8 2016 00:22:57
10:59:36.238 ->
10:59:36.238 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:59:36.238 -> configsip: 0, SPIWP:0xee
10:59:36.238 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:59:36.238 -> mode:DIO, clock div:1
10:59:36.238 -> load:0x3fff0030,len:1184
10:59:36.238 -> load:0x40078000,len:13220
10:59:36.238 -> ho 0 tail 12 room 4
10:59:36.238 -> load:0x40080400,len:3028
10:59:36.238 -> entry 0x400805e4
10:59:36.424 -> Hello Esp32
10:59:36.469 -> ENC: cable not found
10:59:37.449 -> 192.168.131.183
10:59:37.449 -> Check Status : Init
10:59:48.486 -> ets Jun 8 2016 00:22:57
10:59:48.486 ->
10:59:48.486 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
10:59:48.486 -> configsip: 0, SPIWP:0xee
10:59:48.486 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:59:48.486 -> mode:DIO, clock div:1
10:59:48.486 -> load:0x3fff0030,len:1184
10:59:48.486 -> load:0x40078000,len:13220
10:59:48.486 -> ho 0 tail 12 room 4
10:59:48.486 -> load:0x40080400,len:3028
10:59:48.486 -> entry 0x400805e4
10:59:48.672 -> Hello Esp32
10:59:48.719 -> ENC: cable not found
10:59:49.687 -> 192.168.131.183
10:59:49.687 -> Check Status : Init
11:00:00.726 -> ets Jun 8 2016 00:22:57
11:00:00.726 ->
11:00:00.726 -> rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
11:00:00.726 -> configsip: 0, SPIWP:0xee
11:00:00.726 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
11:00:00.726 -> mode:DIO, clock div:1
11:00:00.726 -> load:0x3fff0030,len:1184
11:00:00.726 -> load:0x40078000,len:13220
11:00:00.726 -> ho 0 tail 12 room 4
11:00:00.726 -> load:0x40080400,len:3028
11:00:00.726 -> entry 0x400805e4
11:00:00.912 -> Hello Esp32
11:00:00.960 -> ENC: cable not found
11:00:01.941 -> 192.168.131.183
11:00:01.941 -> Check Status : Init
"

Nano with ENC28J60 stop transmitting packets

I have a Nano running withknolleary/pubsubclient (using a ENC28J60) connecting to HomeAssistent's add-on MQTT broker. I use Wireshark to monitor the network interface of the Nano.
The code I am using in the Arduino as a test test-setup

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <EthernetENC.h>
#include <PubSubClient.h>

#define INT_PIN 2

byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 100, 7);
IPAddress myDns(192, 168, 100, 4);
IPAddress gateway(192, 168, 100, 254);
IPAddress subnet(255, 255, 255, 0);
IPAddress mqttserver(192, 168, 100, 6);


EthernetClient ethClient;
PubSubClient mqttClient(mqttserver, 1883, ethClient);


uint8_t MqttRegisterCounter;
uint8_t MqttPublishFlag;

volatile int8_t SleepDelayCounter = 0;      // counter used for sleep
int8_t SleepDelay = 10;                    // maximum amount the wdt needs to hit (SleepDelay * 8sec => 450 * 8 = 3600 sec = 1 hour) + 1 extra to stop the loop
// test vars to see what works
const char* TOPIC = "room/plug";  // Topic to subcribe to
const char* MESSAGE = "toggle";   // Message to publish to our topic
// HA corresponding bin-sensor
const char* MQTT_TEST_TOPIC = "mcp/Arduinotestmessage";
boolean rc;

// special DTW wakup function, mustbe named ISR!!
ISR(WDT_vect)
{
  
    if(SleepDelay != SleepDelayCounter)
    {
      SleepDelayCounter=SleepDelayCounter+1;
      if (SleepDelayCounter == 4)
         MqttPublishFlag = true;
    }
    else
    {
      SleepDelayCounter = 0;
      MqttPublishFlag = true;
      
    }

    MqttRegisterCounter=MqttRegisterCounter+1;
  
}


void setup() {

  pinMode(INT_PIN, INPUT); 
  pinMode(LED_BUILTIN, OUTPUT); 

  /*** Setup the WDT ***/
  
  /* Clear the reset flag. */
  MCUSR &= ~(1<<WDRF);
  
  /* In order to change WDE or the prescaler, we need to
   * set WDCE (This will allow updates for 4 clock cycles).
   */
  WDTCSR |= (1<<WDCE) | (1<<WDE);

  /* set new watchdog timeout prescaler value */
  WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
  
  /* Enable the WD interrupt (note no reset). */
  WDTCSR |= _BV(WDIE);

  
  Serial.begin(115200);
  //Serial.begin(9600);

  // continue with MQTT setup
  //mqttClient.setServer(mqttserver);
  
  // You can use Ethernet.init(pin) to configure the CS pin
  Ethernet.init(10);  // Most Arduino shields
  Serial.println("Initialize Ethernet");
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  // Allow the hardware to sort itself out
  delay(1500);
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {  
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  }
  else
  {
    Serial.print("Arduino is at ");
    Serial.println(Ethernet.localIP());
    Serial.println(Ethernet.hardwareStatus());
    Serial.println(Ethernet.linkStatus());
  }

}



void reconnect() {
  // only every 30 seconds to avoid fludding the broker and be stuck in connect loop
  if (MqttRegisterCounter == 0)
  {

    if (Ethernet.linkStatus() == 1)
    {
      
      if (!mqttClient.connected()) {

        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (mqttClient.connect("MCP")) {
          mqttClient.setKeepAlive(60);
          Serial.println("connected");
          // Once connected, publish an announcement...
          //mqttClient.publish("outTopic","hello world");
          Serial.println("publishing on");
          rc = mqttClient.publish("mcp/Arduinotestmessage", "on",true);
          Serial.println(rc);
          // ... and resubscribe
          //mqttClient.subscribe("inTopic");
        } else {
          Serial.print("failed, rc=");
          Serial.println(mqttClient.state());
        }
      
      }
      
      
    } else {
      // no ethernet link
      Serial.println("Ethernet Cable disconnected");
    
    }
  
    MqttRegisterCounter=MqttRegisterCounter+1;
  }
  else if (MqttRegisterCounter > 3) {
    MqttRegisterCounter = 0;

  } else {
    MqttRegisterCounter=MqttRegisterCounter+1;
  }

  

}


void loop() {

  
  if (!mqttClient.connected()) {
    reconnect();
  }

  // publish on every x seconds    
  if (SleepDelayCounter == 0) {
    if (MqttPublishFlag) {
   
      //boolean rc = mqttClient.publish("mcpArduinotestmessage", "on");
      rc = mqttClient.publish("mcp/Arduinotestmessage", "on",true);
      
      Serial.print("ON Message 1: ");
      Serial.println(rc);
      SleepDelayCounter= 1;
      MqttPublishFlag = false;

    }

  // publish off every x seconds
  } else if (SleepDelayCounter == 5) {
    if (MqttPublishFlag) {

      //boolean rc = mqttClient.publish("mcpArduinotestmessage", "off");
      rc = mqttClient.publish(MQTT_TEST_TOPIC, String("off").c_str(), true);
      Serial.print("OFF Message: ");
      Serial.println(rc);
      SleepDelayCounter= 6;
      MqttPublishFlag = false;
   
    }
  }

}

The connect is sent, and the first publish message too, after that its quite in Wireshark.
The response (rc) from mqttClient.publish in the serial.print is 1, where it looks like the publish made it to the broker. In Wireshark the packet is not there.

How can I see what actually happens when the publish is being executed?

-Wsign-compare warning

There is a -Wsign-compare warning in utility/uip.c:

EthernetENC\src\utility\uip.c:856:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) {
                                       ^~

Found by enabling all compiler warnings.

STM32F103C8 After Inactive Connection.

Hello guys, im trying to understand what happen here, i have module connected SPI in STM32duino, i recive a code in IR and send it with UDP Using OSC Message.

For a while works great, but in 2 hours or 3, the module goes to inactive in Router.
In Loop i have Ethernet.maintain();
The IP is static with Mac Address.

I debug connection R45 Plug with millis each 4 seconds. and apear connect, and IP show correct.

ethernetENC http post request take too much time to execute on esp23

Hello All,
I've connected enc28760 with esp32 to push data over local server using post method.
while testing with postman tool, it shows some 100~180ms to complete post request.
while my esp32 module taking around ~2200ms.

String postData = "red=123&green=345&blue=123&white=123";
httpClient.post("/rgbw/val?", "application/x-www-form-urlencoded", postData);

Any help would be appreciated!

Ping

Howto use ping with EthernetENC?
I mean send icmp requests

not pingable after a while

Hi,
I use the library with the Nano Ethernet Shield on an ESP32 Dev Kit-C.
I also use the PubSubClient-Library to send MQTT messages.
After some time (varies between some seconds and half an hour) the shield won't answer on pings. The "LinkStatus" is still 1.
For me it looks like some buffer or memory problems. When I have less traffic, the problem takes longer to occure.

Thanks for the help!

Sending UDP message Error

Is it possible to broadcast a message on UDP ? I tried with 255.255.255.255 as IP address in UDP.beginPacket.
It does return 1, however, message is not sent on the network.

I can not IP address with only last digits as 255 because when device is connected on a network, the IP address of the PC is not known.

Teensy 4.1 connection issues

My work has a LED lighting controller that was designed around a Teensy 3.6 which receives a color command over Ethernet and controls APA102 LED strips. We recently built another batch of the controllers, but had to use Teensy 4.1's because 3.6's have been obsolete for quite a while now. The firmware originally used the UIPEthernet library, which we've removed and replaced with EthernetENC; but we can't get the Teensy 4.1 to connect. When we upload the firmware using EthernetENC to a 3.6 based controller, it connects and functions just fine. I can't provide our firmware because it's proprietary, but it really is about as basic as you can imagine. We have a ENC28J60-H by Olimex connected to pins 10-13, and we bit-bang the data/clock out to the APA102 on pins 2 & 3.

Our current theory is that the SPI connection isn't being set up correctly, so this may need to be an issue posted to Teensy's SPI library; since it appears the bus is initialized in the Enc28J60Network .cpp file. However, we aren't sure exactly where the problem lies so we just looking for any leads at the moment. Has there been any issues with Teensy 4.x boards before or is there a better library to use?

Olimexino-328 and MOD-ENC28J60 Ethernet not found

Should this library work with the Hardware ?:
https://www.olimex.com/Products/Duino/AVR/OLIMEXINO-328/open-source-hardware
https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60/

Hardware works with https://www.aelius.com/njh/ethercard/index.html

Serial output of the example:

Ethernet Example
Ethernet shield was not found. Sorry, can't run without hardware. :(

Example sketch code:

`
#include <SPI.h>
#include <EthernetENC.h>

// network configuration. gateway and subnet are optional.

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 192, 168, 0, 77 };
// the router's gateway address:
byte gateway[] = { 192, 168, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };

// telnet defaults to port 23
EthernetServerPrint server = EthernetServerPrint(23);

void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet Example");
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
// start listening for clients
server.begin();
}

void loop()
{
// if an incoming client connects, there will be bytes available to read:
EthernetClient client = server.available();
if (client == true) {
// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());
}
}
`

Problems with first sends using EthernetENC

Good evening, can anyone help me?

I'm using this LIB in a project where I have some buttons connected to the arduino and whenever someone presses a button I consump an API to inform the pressed button, it works fine, but I'm facing a strange problem, below is an example code:

#include <Arduino.h>
#include <EthernetENC.h>

EthernetClient clientLAN;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 103);

void setup()
{  
  Serial.begin(115200);

  Serial.println("Tentando conectar via ETHERNET...");

  if (Ethernet.begin(mac) == 0)
  {
      Serial.println("Falha ao configurar a ETHERNET usando DHCP");  
  }
  else
  { 
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5100) {
        Serial.println("W5100 Ethernet controller detected.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5200) {
        Serial.println("W5200 Ethernet controller detected.");
      }
      else if (Ethernet.hardwareStatus() == EthernetW5500) {
        Serial.println("W5500 Ethernet controller detected.");
      }
      else
      {
        Serial.print("Ethernet controller detected: ");
        Serial.println(Ethernet.hardwareStatus());
      }

      Serial.println("Conexão ETHERNET realizada com sucesso!");
     
      Serial.print(" IP: ");
      Serial.println(Ethernet.localIP());

      Serial.print("MSK: ");
      Serial.println(Ethernet.subnetMask());

      Serial.print(" GW: ");
      Serial.println(Ethernet.gatewayIP());

      Serial.print("DNS: ");
      Serial.println(Ethernet.dnsServerIP());
  }
  
  delay(500);
}

void loop()
{
    Serial.println("Abrindo conexão com o servidor (Via ETHERNET).");
    
    //clientLAN.clearWriteError();
    //clientLAN.setTimeout(10000);

    int clientLanStatus = clientLAN.connect(ip, 8083);
    Serial.print("Client CONNECT result:");
    Serial.println(clientLanStatus);

    if (clientLanStatus == 1)
    {
        Serial.println("Conectado ao servidor (Via ETHERNET).");
        Serial.println("Enviado dados para o servidor (Via ETHERNET).");
        
        clientLAN.println("GET /_Testes/api_teste.php?botao=B01&ligado=1&bancoDados=999&hash=ABCXYZ HTTP/1.1");
        clientLAN.println("Host: 192.168.0.103:8083");
        clientLAN.println("Connection: close");
        clientLAN.println();   

        //--.       
        
        while(clientLAN.connected()) {
          while(clientLAN.available()) {
            Serial.write(clientLAN.read());
          }
        }               

        clientLAN.flush();
        clientLAN.stop();      
        
        Serial.println();
        Serial.println("Envio finalizado.");
        Serial.println();

        delay(200);
    
    }
    else
    {         
        Serial.println("NÃO FOI POSSíVEL ENVIAR O COMANDO AO SERVIDOR!!!");  
              
        if (Ethernet.linkStatus() == 2) 
        {
          Serial.println("NÃO conectado ao servidor!!!");  
          Serial.println("Tentando reconectar...");   

          if (Ethernet.begin(mac) == 0)
          {
            Serial.println("Falha ao re-configurar a ETHERNET usando DHCP!!!");
          }
          else
          {
            Serial.println("Re-Conexão ETHERNET realizada com sucesso!");
          }
        }

        delay(500);
    }
  
    delay(2000);
}

It turns out that when connecting the arduino for the first time everything works normally, if I restart the arduino the first uploads give an error (randomly it can happen from the first to the sixth upload does not work), after that it stabilizes and all uploads work normally. I couldn't find the logic behind it.

Apparently if I comment out "clientLAN.stop();", "clientLAN.read()" and the API doesn't return anything, it doesn't. The API only returns the processing date.

Analyzing the LIB EthernetClient.ccp I arrived at this function:

int
UIPClient::connect(IPAddress ip, uint16_t port)
{
  stop();
  uip_ipaddr_t ipaddr;
  uip_ip_addr(ipaddr, ip);
  struct uip_conn* conn = uip_connect(&ipaddr, htons(port));
  if (conn)
    {
#if UIP_CONNECT_TIMEOUT > 0
      uint32_t timeout = millis() + 1000 * UIP_CONNECT_TIMEOUT;
#endif
      while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
        {
          UIPEthernetClass::tick();
          if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
            {
              data = (uip_userdata_t*) conn->appstate;
#ifdef UIPETHERNET_DEBUG_CLIENT
              Serial.print(F("connected, state: "));
              Serial.print(data->state);
              Serial.print(F(", first packet in: "));
              Serial.println(data->packets_in[0]);
#endif
              return 1;
            }
#if UIP_CONNECT_TIMEOUT > 0
          if (((int32_t)(millis() - timeout)) > 0)
            {
              conn->tcpstateflags = UIP_CLOSED;
              break;
            }
#endif
        }
    }
  return 0;
}

As I understand it, in the first submissions it does not enter this IF:

if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)

I've tried to increase the TimeOut (clientLAN.setTimeout(10000);) of the connection, but without success.

Does anyone have any idea what it could be?

I use EthernetENC version 2.0.2.

Evidence:

image

Port Reuse on TCP Connections

In my development Process with frequent restarting, I experienced issues with working code breaking after resetting or flashing.
After some Packet inspection with Wireshark, I figured out, that upon reset, the same sourcePort is used. THis however can be misinterpretedby the Server as an out of Sequence packet or simmilar.
This could also be the source of the issues described in #30 .

A simple Fix would be to set the lastport Variable randomly in uip.c.

Limitation of length in UDP ?

I am finding that any packet more than 18 bytes is not being received by following code.

#include <SPI.h>
#include <EthernetENC.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 35350; // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

char packetBuffer[1024]; //buffer to hold incoming packet,

void setup() {
// start the Ethernet and UDP:
Serial.begin(115200);
Ethernet.init(2);
Ethernet.begin(mac,ip);
Serial.println(Ethernet.localIP());
Udp.begin(localPort);

}

void loop() {
int packetSize = Udp.parsePacket();
if(Udp.available())
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());

// read the packet into packetBuffer
Udp.read(packetBuffer,255);
Serial.println("Contents:");
Serial.println(packetBuffer);

}
}

Problem by traffic through switches

the following structure:
ENC-----Managed Switch------ENC ->No Connection between devices
ENC-----Unmanged Switch------ENC ->Connection between devices

i use the libs with an ESP32 devkit

I have TP-Link and Netgear as Gigabit switches and two Fritzboxes. Everything runs stable for several days. Now the setup should change to its natural environment. This has a manageable Swtich for the purpose of Vlans. Nothing works anymore. I have several Linksys LGS310, HP, 3Com running here. PC, Internet, printer etc. runs over the switches without problems. I have also enabled all ports for UDP/TCP in the switches and set the ports to 10base/full or half. no change.
Tried ten times different ports without success. Also changed my code that actual sends and received udp traffic in server/client structure without any luck.

The helps in the internet do not bring me further:

  • 100 to 120ohm between pin 1/2, 3/6.
  • change to 10base full
  • crossover cable

Also on the HP switch, Microsnes, Linksys or Cisco nothing works. I am at a loss. but the switches shows that there is traffic on the ports. Even on the old router, which can only handle 100base-t, the udp connection works.

Not receiving DHCP Offer Packet

I've just tried to use the EthernetENC library with the DHCP Address Printer example, and get the following output:

Initialize Ethernet with DHCP:
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
udp, uip_packet to send: 0
Failed to configure Ethernet using DHCP

But I can see in Wireshark that the module is sending it's DHCP Discover, and the Router is responding with a DHCP Offer.

No.	Time	Source	Destination	Protocol	Length	Info
113	5.342738	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4a5
154	7.345124	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4a5
190	9.347130	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4a6
191	9.347631	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4a6
221	13.404441	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4a7
222	13.404441	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4a7
246	17.459337	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4a8
247	17.459797	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4a8
293	21.515242	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4a9
294	21.525351	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4a9
303	25.571324	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4aa
304	25.571758	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4aa
316	29.627390	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4ab
317	29.628571	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4ab
380	33.683590	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4ac
381	33.683994	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4ac
406	37.739906	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4ad
407	37.739906	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4ad
451	41.795579	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4ae
452	41.796027	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4ae
599	45.852460	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4af
600	45.852460	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4af
5270	49.908088	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4b0
5271	49.908334	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4b0
5368	53.964271	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4b1
5369	53.964271	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4b1
5457	58.020850	0.0.0.0	255.255.255.255	DHCP	317	DHCP Discover - Transaction ID 0x4b2
5458	58.020850	192.168.0.1	255.255.255.255	DHCP	590	DHCP Offer    - Transaction ID 0x4b2

I also check in the DHCP.c file. It seems that _dhcpUdpSocket.parsePacket() in DhcpClass::parseDHCPResponse never get's a packet.

ENC28J60 and SD card module on ESP32

Hi, I am using ENC28J60 Ethernet module (SPI) and SD Card module (SPI) with ESP32 as I need wired networking on ESP32. Ethernet Module and SD Card module are using different CS pin. Ethernet Module when connected to ESP32 without connecting the SD Card module will get the IP from DHCP. But when connected with SD Card module won't work but the SD Card module works alone. What may be the problem?

And when used Ethernet Module alone although it gets IP from DHCP is not connecting to MQTT (Hive MQ Public Client). What may be the problem?

Use pico-w with EthernetENC and WiFi problem

Hello,
I have the two problem:

  1. If I use bool before or after the Ethernet.begin(mac) ,will make Ethernet.begin(mac) stuck.but if bool's name first word is lowercase w~z Ethernet.begin(mac) will working.

like this ,Ethernet.begin(mac) will stuck:

EthernetState = true;
if (Ethernet.begin(mac) == 0) {
EthernetState = true;
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  while (true) {
    delay(1); // do nothing, no point running without Ethernet hardware
  }
}

2.I went use pico-w WIFI AND enc28j60 ,my code is use Ethernet.linkStatus() to identify whether there is an Ethernet connection,if cable no connection use WIFI,But if put in the WiFi.begin(ssid, password) or WiFi.run() in setup or loop even without using,Ethernet.begin(mac) will stuck.

    #include <SPI.h>
    #include <EthernetENC.h>
    #include <WiFi.h>
    
    #ifndef STASSID
    #define STASSID "SSID"
    #define STAPSK "STAPSK"
    #endif
    const char* ssid = STASSID;
    const char* password = STAPSK;
    
    const char* host = "djxmmx.net";
    const uint16_t port = 17;
    int status = WL_IDLE_STATUS; 
    
    WiFiMulti multi;
    
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    
    char server[] = "www.google.com";    // name address for Google (using DNS)
    
    // Set the static IP address to use if the DHCP fails to assign
    IPAddress ip(192, 168, 6, 201);
    IPAddress myDns(8, 8, 8, 8);
    
    EthernetClient client;
    
    // Variables to measure the speed
    unsigned long beginMicros, endMicros;
    unsigned long byteCount = 0;
    bool printWebData = true;  // set to false for better speed measurement
    bool EthernetState = false;
    void setup() {
      // You can use Ethernet.init(pin) to configure the CS pin
      Ethernet.init(21);  // Most Arduino shields
     delay(3000);
      // Open serial communications and wait for port to open:
       
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    
      // start the Ethernet connection:
      
       if (Ethernet.linkStatus() == LinkON)
      {
          Serial.println("Initialize Ethernet with DHCP:");
          if (Ethernet.begin(mac) == 0) {
          Serial.println("Failed to configure Ethernet using DHCP");
          // Check for Ethernet hardware present
          if (Ethernet.hardwareStatus() == EthernetNoHardware) {
            Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
            while (true) {
              delay(1); // do nothing, no point running without Ethernet hardware
            }
          }
          Serial.println("2");
          if (Ethernet.linkStatus() == LinkOFF) {
            Serial.println("Ethernet cable is not connected.");
          }
          // try to congifure using IP address instead of DHCP:
          Ethernet.begin(mac, ip, myDns);
          } else {
          Serial.print("  DHCP assigned IP ");
          Serial.println(Ethernet.localIP());
          }
      }
      else if (Ethernet.linkStatus() == LinkOFF)
      {
          while ( status != WL_CONNECTED) {
          Serial.print("Attempting to connect to WEP network, SSID: ");
          Serial.println(ssid);
          status = WiFi.begin(ssid, password);
          }
      }   
    }
    
    void loop() {
      
    }

I searched the library and found that the program would get stuck at DHCP

Thanks for any help

Ethernet.begin(mac) not working in ESP32

Hi,

I am having some troubles in getting Esp32 working with ENC28J60 module.
The Ethernet.begin function gets stucked, but I am not sure that the Ethernet.init function is working properly before of that.

Is there any way to check if the module has been initiated properly? I am using the GPIO_5 pin of ESP32 for the CS pin:

Ethernet.init(GPIO_NUM_5)

However if I check the Ethernet.hardwareStatus() is returning EthernetNoHardware.

I think that maybe the ENC28J60 is not even initalized.

Appreciate response.

receive packet failed error.

Hi everyone. I am using atmega2560+enc28j60+rc522 rfid reader in my project. Last days,
i'm struggling an interesting problem. Sometimes everything is working well but sometimes i am getting an error.

01:31:36.580 -> receivePacket [6-23C], next: 3A3A, stat: 3A, count: 25 -> failed
01:31:36.580 -> sendPacket(1) [801-93E]: 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 38 3A 3A 3A 3A 2 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 1A 3A 3A 3A 3A 3A 1A 3A 3A A 3A 3A 3A 3A 3A 3A 3A 3A 3A 38 2 3A 3A 3A 3A 3A 3A 3A 3A 3A A 3A 3A 3A 3A 0 3A 3A 3A 3A 3A 3A 3A 3A 3A 38 38 3A 3A 3A 3A 3A 38 3A 3A 3A 3A 3A 20 20 3A 3A 3A 3A 3A 3A 32 3A 3A 38 3A 3A 12 3A 3A 3A 3A 3A 12 3A 3A 2A 3A 3A 32 3A 3A 3A 3A 3A A 3A 3A 3A 3A 2 3A 3A 3A 3A 3A 3A 3A 3A 3A 12 2A 3A 3A 3A 3A 32 2 3A 3A 3A 3A 2 3A 3A 3A 1A 3A 3A 3A 3A 3A 0 3A 3A 3A 3A 10 3A 3A 3A 3A 3A 12 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 8 3A 3A 3A 3A 3A 10 3A 3A 3A 3A 3A 3A 18 3A 3A 3A 3A 3A 3A 22 3A 3A 3A 3A 20 20 3A 3A 3A 3A 3A 0 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 2 3A 3A 3A 3A 12 3A 3A 3A 3A 3A 20 3A 3A 3A 3A 3A 8 3A 3A 3A 10 1A 3A 3A 3A 3A 30 3A 3A 3A 3A 3A 3A 12 3A 3A 3A 3A 3A 32 22 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 38 32 3A 3A 3A 3A 38 3A 3A 3A 3A 3A 3A 12 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 3A 28 32 3A 3A 3A 3A 3A
01:31:36.580 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 25 -> failed
01:31:36.625 -> receivePacket [3240-476], next: 1A38, stat: 3A, count: 25 -> failed
01:31:36.666 -> receivePacket [123E-472], next: 3A3A, stat: 3A, count: 25 -> failed
01:31:36.749 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 25 -> failed
01:31:36.790 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 17 -> failed
01:31:36.832 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 9 -> failed
01:31:36.878 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 25 -> failed
01:31:36.967 -> receivePacket [3240-476], next: 3A3A, stat: 3A, count: 25 -> failed

I changed a line in Enc28J60Network.cpp. I added |ERXFCON_BCEN but nothing change.

//writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN|ERXFCON_BCEN);

How can it possible? one working one not working. I am pulling my hair.

Jandrassy, i need your help? maybe you can say something what is wrong in my project?

Not compiling: 'class EthernetServer' has no member named 'write'

I take this source https://www.arduino.cc/en/Tutorial/LibraryExamples/ChatServer
Then following these notes seems not compile:
https://github.com/jandrassy/EthernetENC/wiki/Examples

"Only change #include <Ethernet.h> to #include <EthernetENC.h>." <-- I did, and this is OK
"In ChatServer and DhcpChatServer examples please use EthernetServerWrite server(23)" <-- I replaced the line "EthernetServer server(23);" with "EthernetServerWrite server(23);" but I have the following error: 'EthernetServerWrite' does not name a type; did you mean 'EthernetServerPrint'?

Can you provide a modified example compiling please ?

Static code check

Hi..

Running the analysis I got this info from Cppcheck 2.6

image

``

UIPUDP::beginPacket(IPAddress ip, uint16_t port)
{
UIPEthernetClass::tick();
if ((ip[0] || ip[1] || ip[2] || ip[3]) && port)
{
uip_ipaddr_t ripaddr;
uip_ip_addr(&ripaddr, ip);

Maybe it is a false positive but better to check...

I hope it helps

Simone

conflict with webthing

Hi,
I'm trying to begin webthing with enc28j60. I used your library but, when I start the webthing adapter(adapter->begin();) ESP reboot constantly. Have you ever tried to use these two libraries together?
I'm using esp32 doit devkit v1 and ENC82j60 module.
I'm using following software.
ESP32 core version: 2.0.3
Arduino version: 1.8.16
EthernetENC library version: 2.0.3
webthing-Arduino library version: 0.12.0

Network connection goes deaf.

Hello;

I am having the same problem with EthernetENC as I did with UIPEthernet. That is the
stack stops receiving packets. You fixed the problem and afterwards the code ran without
problems. Perhaps there is a similar bug in your new code. The processor is an ESP-12N.
The code is part of the OpenSprinkler project.

The issue was previously discussed here:
UIPEthernet/UIPEthernet#129

The ethernet.begin(mac) doesn't work

I've just tried to use the EthernetENC library with the WebClient example, but the program it stays in an infinite loop in ethernet.begin (mac); I checked and saw that it does not come out of a while in Enc28J60Network.cpp line 263, because the function readReg(EIR) always return 0x00.

I am using a mkr1010 and enc28j60

Does anyone know what could be wrong?

Setting all PIN in ENC28J60 shield

Hi... I am trying this example to use your library with ESP32 and ENC28J60 shield.

``
#include <SPI.h>
#include <EthernetENC.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):

EthernetServer server_ethernet(80);
EthernetClient client_ethernet;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true; // set to false for better speed measurement

void Ethernet_Init(void)
{

// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(15); // Most Arduino shields

// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);

// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("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)
{
Serial.println("Ethernet cable is not connected.");
}

// start the server
server_ethernet.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

}

void Ethernet_Task(void)
{
// if there are incoming bytes available
// from the server, read them and print them:
int len = client_ethernet.available();
if (len > 0) {
byte buffer[80];
if (len > 80) len = 80;
client_ethernet.read(buffer, len);
if (printWebData) {
Serial.write(buffer, len); // show in the serial monitor (slows some boards)
}
byteCount = byteCount + len;
}

// if the server's disconnected, stop the client:
if (!client_ethernet.connected()) {
endMicros = micros();
Serial.println();
Serial.println("disconnecting.");
client_ethernet.stop();
Serial.print("Received ");
Serial.print(byteCount);
Serial.print(" bytes in ");
float seconds = (float)(endMicros - beginMicros) / 1000000.0;
Serial.print(seconds, 4);
float rate = (float)byteCount / seconds / 1000.0;
Serial.print(", rate = ");
Serial.print(rate);
Serial.print(" kbytes/second");
Serial.println();

// do nothing forevermore:
while (true) {
  delay(1);
}

}
``
I got always the same message
Ethernet shield was not found. Sorry, can't run without hardware .

The point is that I have the following HW configuration

image

Does the library provide a way for specify my special pinout ?

I just saw that you can select the CS PIn,,,,

Thanks a lot for your huge support...

problems with IP in sending UDP packets

Spent several hours and still can't find how to do it. I can not send UDP to a custom IP address, only to the one with which a connection is established. Maybe there is some kind of filter that does not allow this, or somewhere I can change the destination IP manually in udp packet?

no function `ethernet.MACAddress()` to drop-in replace ethernet.h

i am trying to use this library as a drop-in replacement for the standard arduino ethernet library inside the this artnet library

everything works perfectly - except for this line in artnet code where it calls:

#ifndef ESP8266
            Ethernet.MACAddress(mac);
#endif

which doesnt exist in the EthernetENC version.

ultimately i want to add support for EthernetENC to the artnet library - although its not clear to me if i should solve this by modifying the logic in artnet or adding this function to this library ? is this meant to be used as drop-in like this ? is it possible to add this function here or a reason why its not here ?

thanks for your help!

'class EthernetServer' has no member named 'write'

I am trying to replace UIPEthernet with EthernetENC for my tiny MySensors project but compilation fails with

/home/matkor/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportSend(MyMessage&)':
/home/matkor/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:297:27: error: 'class EthernetServer' has no member named 'write'
  nbytes = _ethernetServer.write(_ethernetMessage);
                           ^~~~~
Using library EthernetENC at version 2.0.2 in folder: /home/matkor/Arduino/libraries/EthernetENC 
Using library MySensors at version 2.3.2 in folder: /home/matkor/Arduino/libraries/MySensors 

Is it my error, MySensors or EthernetENC just lacks that method now?
Regards, TIA

Not receiving UDP responses

This is the not the code I want to run, but I was trying to attack it from another angle.

This is being run on a nano with an enc28j60 ethernet shield. I receive the udp message to the serial console as expected, but the client never receives the ack in response. local firewall is disabled.

I confirmed that the theory works with a python version, in case it was netcat being weird, but it behaved the way I expected, I sent text, and I received it back.

Here's my test code, ultimately I'm trying to work out why I wasn't seeing the subscription coming back from the nano to my ArtNet server. I tried removing the line suggested in #3 in case it was a similar thing, but no dice.

#include <EthernetENC.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE };
IPAddress ip(192,168,0,115);
//byte ip[] = {192,168,0,115};
unsigned int localPort = 6454;

// buffers for receiving and sending data
char packetBuffer[800];  // buffer to hold incoming packet,
char ReplyBuffer[] = "ack";        // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  Serial.begin(115200);
  //while (!Serial) {
  //  ; // wait for serial port to connect. Needed for native USB port only
  //}
  Ethernet.begin(mac, ip);
  //Serial.println(Ethernet.localIP());
  Udp.begin(localPort);
}

void loop() {
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print(F("Received packet of size "));
    Serial.println(packetSize);
    Serial.print(F("From "));
    IPAddress remote = Udp.remoteIP();
    for (int i=0; i < 4; i++) {
      Serial.print(remote[i], DEC);
      if (i < 3) {
        Serial.print(".");
      }
    }
    Serial.print(F(", port "));
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, 800);
    Serial.println(F("Contents:"));
    Serial.println(packetBuffer);

    // send a reply to the IP address and port that sent us the packet we received
    Serial.println(Udp.remoteIP());
    Serial.println(Udp.remotePort());
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Serial.println(ReplyBuffer);
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

UDP totally broken with Arduino Nano

Trying to send only UDP messages totally does not work. I have the following workaround:

#include <Arduino.h>
#include <EthernetENC.h>

void endPacket(EthernetUDP &Udp, IPAddress &remoteIP, uint16_t remotePort)
{
  auto endPacket = Udp.endPacket();
  Serial.println(String() + "endPacket = " + endPacket);
  for (int i = 0; endPacket; i++)
  {
    Serial.println(String() + i + ": beginPacket = " + Udp.beginPacket(remoteIP, remotePort));
    endPacket = Udp.endPacket();
    Serial.println(String() + i + ": endPacket = " + endPacket);
  }
}

void setup()
{
  Serial.begin(115200);
  while (!Serial)
  {
  }
  delay(3000);
  // Enter a MAC address and IP address for your controller below.
  // The IP address will be dependent on your local network:
  byte mac[] = {
      0xA0, 0x36, 0xBC, 0x30, 0xC1, 0x16};
  IPAddress ip(169, 254, 116, 89);

  unsigned int localPort = 32768; // local port to listen on

  // An EthernetUDP instance to let us send and receive packets over UDP
  EthernetUDP Udp;

  // You can use Ethernet.init(pin) to configure the CS pin
  Ethernet.init(10);

  // start the Ethernet
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware)
  {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true)
    {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }

  // start UDP
  Udp.begin(localPort);

  IPAddress remoteIP(169, 254, 116, 90);
  uint16_t remotePort = 32769;

  for (int i = 0; i < 10; i++)
  {
    Serial.println("next try");
    Serial.println(String() + "i = " + i);
    Serial.println();

    Serial.println(String() + "beginPacket = " + Udp.beginPacket(remoteIP, remotePort));
    Serial.println(Udp.println(i));
    endPacket(Udp, remoteIP, remotePort);
    Serial.println("---------------------------------");
  }
}

void loop()
{
}

The output is:

next try
i = 0

beginPacket = 1
3
endPacket = 1
0: beginPacket = 0
0: endPacket = 1
1: beginPacket = 0
1: endPacket = 1
2: beginPacket = 0
2: endPacket = 1
3: beginPacket = 0
3: endPacket = 1
4: beginPacket = 0
4: endPacket = 1
5: beginPacket = 0
5: endPacket = 1
6: beginPacket = 1
6: endPacket = 0
---------------------------------
next try
i = 1

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 2

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 3

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 4

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 5

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 6

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 7

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 8

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------
next try
i = 9

beginPacket = 0
3
endPacket = 1
0: beginPacket = 1
0: endPacket = 0
---------------------------------

I am using the following command on a "Debian GNU/Linux 11 (bullseye)" machine to set up the UDP receiver:

nc -ul -p 32769

The output is:

0
1
2
3
4
5
6
7
8
9

The numbers in the Debian terminal are only appearing if endPacket == 0. You can put delays here and there to verify.
Am I doing something wrong? Can someone reproduce the issue?

My setup:

  • Sender:
    • Arduino Nano
    • ENC28J60 Ethernet Shield for Arduino Nano
  • Receiver:
    • Debian GNU/Linux 11 (bullseye)
    • Dell 7-in-1 USB-C Multiport-Adapter – DA310
    • Dell Latitude 7285 2-in-1

This issue is probably related to #3.

client.write("somestring") fails after a random amount of calls

Hi:
I have a strange behaviour of EthernetClient client.write("somestring") returning zero bytes after a random number of calls.
My application is running on a Nano Every and a Enc28J60 shield (lots of code ommited for clarity):

#include <Arduino.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress clientIP(192, 168, 1, 177);
EthernetClient client;
int serverPort = 2323;
IPAddress serverIP(192, 168, 1, 80);

void setup() {
	if (initEth()) {
		isConnected = connectToFrame(serverIP, serverPort);
	}
	if (!isConnected) {
		Debug(msgNoEthLink);
               // FAULT
	}
}

long last_loop;
#define LOOP_PERIOD 50
void loop() {
	if (millis() > last_loop + LOOP_PERIOD) {
		last_loop = millis();
		reConnect(serverIP, serverPort); // in case the connection is lost
		readEncoder();  // when there is a change in the encoder value, it sends a message to the server
		readClient();     // receives then parses JSON from the server
		readPushBtns(); // when there is a change in the encoder value, it sends a message to the server

// HERE IS THE HACK WICH SOLVES MY PROBLEM
// BUT I DON'T KNOW WHY (!!?)
 		client.write((byte)0);
 
		}
	}

When a change is read in the encoder i send a message like this:

int sendCmd(const char *control, const char *param, int value) {
	int num = -1;
	int a, l;
	sprintf(strbuf, "{\"OP\":\"cmd\",\"Control\":\"%s\",\"%s\":%i}", control,
			param, value);
	num = client.println(strbuf);
        client.flush(); // TRIED THIS BUT NO CHANGE IN BEHAVIOUR
	sentCmd = true;
	return num;
}

After several sendCmd I get a return SMALLER than the length of the buffer sent (strbuf, which is a big enough char array) and the next one is zero, forever. I cannot recover from this fail. The client.write("string") returns after the 2000ms timeout without sending data.
I traced the error up to Enc28J60Network::allocBlock(UIP_SOCKET_DATALEN); which, apparently, returns NOBLOCK.
The only solution is to continuously client.write((byte)0); on the main loop, which is not really elegant and very brute-force.
I also tried to check client.availableForWrite() before sending a message, but no luck, it is always correct.

Any idea?

Ping response

Hi!

Sorry if the question is stupid, is there any example of how to implement ping response?

Thanks in advance

client.stop() not sending FIN packet to peer device?

I am using the V2.0.4 EthernetENC library with an MKR 1500 NB and ENC28J60 Ethernet board connected to a Windows PC through a router. DHCP, connection to peer and sending and receiving data is working. If I call client.stop() the Arduino device closes its connection. However, the PC program does not indicate a closed connection, in fact thinks the connection is still open. When data is sent by the Windows program, it finds the Arduino socket is closed so indicates the connection is closed.
Checking the Ethernet packet transactions with WireShark shows no FIN packet being sent by the Arduino.
Here is a code snippet.

// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.print("connected to server:");
Serial.println(server);
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}

void loop() {
if (client.connected()) {
client.print("Hello from Arduino.");
client.stop();
}
while (true) {
delay(1);
}
}

Here is the Wireshark capture. There is no FIN packet sent by the Arduino IP 192.168.1.137.
image
Also I cannot see any attempt in the EthernetENC code to send the FIN packet on stop() - but I might have missed it.

[FR] Project Examples for PlatformIO Registry

Hi,

Currently, the library page in the PlatformIO Registry doesn't contain any quick start projects for developers. Such examples serve both to highlight widespread use cases and to help newcomers to get up and running much more quickly.

Please consider adding a few comprehensive project examples to the PlatformIO Registry.

Useful links:

UDP services, does not work with ESP8266 arduino core above 2.7.4

I am trying to use UIPEthernet with ESP8266 arduino core 3.0.1, my hardware is ESP-12E and ENC28J60 Ethernet shield
Unfortunately UDP services like DHCP, SNMP etc. are not working properly and I had to downgrade my ESP8266 arduino core to 2.7.4
I also tried to change the definitions of conflict but to no avail
Any suggestion?! Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.