sstaub / ethernet3 Goto Github PK
View Code? Open in Web Editor NEWEthernet library for Arduino and Ethernetshield2 / WIZ550io / WIZ850io / USR-ES1 with Wiznet W5500 chip
License: Other
Ethernet library for Arduino and Ethernetshield2 / WIZ550io / WIZ850io / USR-ES1 with Wiznet W5500 chip
License: Other
Add a NTP SNTP library
Hello,
I have problem using ETHERNET3 library.
My code works on ETHERNET & ETHERNET2, but have problems with unexpected send delays, so I'm trying ETHERNET3 whis seems to be more robust, but I have problem with secondary server running on other TCP port. I'm using one server for streaming of meassurement data and secondary for Configuration of device.
Code is running on ARDUINO DUE, and main loop contains many other functions so I extracted only related parts. Streeming connection seems to be fine, but control one is not working.
Can you advice what is wrong (same approach was ok with ETHERNET.h). Thank you for help.
See my code extracted here:
EthernetServer server(80);
EthernetServer server1(88);
EthernetClient DataStream;
EthernetClient EthConfig;
void setup() {
//For Ethernet library V 3.0
Ethernet.setCsPin(10); //Set CS = 10
Ethernet.init(1); //-> 1 Socket with 16k RX/TX buffer
Ethernet.begin(CS_CFG.str.MAC_addr, CS_CFG.str.IP_addr,subnet, gateway);
server.begin();
server1.begin();
}
void loop() {
// Ethernet
// Listen for incoming clients
EthernetClient DataStream = server.available();
EthernetClient EthConfig = server1.available();
// Ethernet data streaming to PC
if (DataStream) {
if (DataStream.connected()) {
// ETH TCP connection status
if (DataStream.available()) {
// If some bufers are full to be send
DataStream.write(DAQ_buff[DAQ_buff_indx_sent].Bytes,ETH_sent_buff_length);
}
}
}
else { //No active connection
}
// Ethernet configuration channel to PC
if (EthConfig) {
if (EthConfig.connected()) {
if (EthConfig.available()) {
//Read 5 characters of command
EhtCmd_string="";
for(int i=0; i < 5; i++){
EthChar=EthConfig.read();
EhtCmd_string += EthChar;
}
if (EhtCmd_string == "GETCS"){ //Send parameters
EthConfig.write(CS.Bytes,sizeof(CS));
//EthConfig.write(reinterpret_cast<char*>(&CS),sizeof(CS));
InfoMsg("GETCS");
}
if (EhtCmd_string == "GETCA"){ //Send Act calibration parameters
EthConfig.write(Calibration.Bytes,sizeof(Calibration));
}
if (EhtCmd_string == "GETxx"){ //Test
EthConfig.write(DAC0);
}
}
}
}
}
Can you please add speed settings to this library?
User can set 10Mbit or 100Mbit.
Thank you
Dan
add the mDNS library from https://github.com/TrippyLighting/EthernetBonjour
with this library, I use
digitalWrite(10, LOW);
// send in the address and value via SPI:
SPI.transfer((IMR & 0x00FF0000)>>16);
SPI.transfer((IMR & 0x0000FF00)>> 8);
SPI.transfer((IMR & 0x000000F8) + 4);
SPI.transfer(0x10);
// take the SS pin high to de-select the chip:
digitalWrite(10, HIGH);
Ethernet.WoL(true);
after that , I send magic packet but w5500 doesn't wake up and INT is still high
Hello,
I can't help but notice that the repository contains no license file and that the source code file contain no license header. This would mean that the library is completely proprietary and that it's therefore illegal to use this library with the Arduino framework. Is this on purpose?
The library is deprecated ans shoul deleted
There should SPI optimizations for specific microcontrollers, like SPIFIFO for Teensy.
Using flush in the parsePacket is a slow way to skip unwanted data. I've modified my fork with code to simply update the pointer on the w5500 so we don't have to transfer it over SPI.
I've only implemented it in the parsePacket function but I think it could work or be better to simply rewrite the flush function with my changes.
I'd like to know if there's a reason for reading rather than skipping unwanted data using flush?
Hi,
I have been using a Metro M4 board with the Adafruit Ethernet2 library, Adafruit Ethernet W5500 Feather-wing DHCP my code always works fine and RX's data fine. Your library has some great new functions I like so I tried using your Ethernet3 library and DHCP fails to configure the board every time but it will (after a very long delay) assign static IP. However with the static IP assigned it will not accept any data seems to hangup. I believe the issue to be something with the Ethernet.init(). Not sure if I am missing something? Below is the order and code setup.
#include <SPI.h>
//#include <Ethernet2.h>
#include <Ethernet3.h>
#define WIZ_CS 12
byte mac[] = {
0x98, 0x76, 0xB6, 0x10, 0x9F, 0xAE
};
// Set the static IP address to use if the DHCP fails to assign IP Address
IPAddress ip(10, 0, 0, 14);
IPAddress gateway(10, 0, 0, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(9100);
EthernetClient client;
void setup() {
Ethernet.setCsPin(WIZ_CS); // used only with Ethernet3 lib
//Ethernet.init(WIZ_CS); // used only with Ethernet2 lib. this init works.
Ethernet.init(); // used only with Ethernet3 lib tried 1, 2, 4, 8 none work
Serial.begin(115200);
delay(3000);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
Serial.println(Ethernet.localIP());
}
One question: To change the buffer size for example: Ethernet.init(1) do I need to edit only the w5500.h and change both MAX_SOCKET = 1 and buffer size RX/TX = 16k? Do I need to edit any other files.
Hi SStaub!
First, thanks for that job. It´s cool.
So, We are working on scenario where we using 2 W5500, sharing the ESP32 SPI bus, but each W5500 has own CS, RST, INT pins. We´ve noted that w5100_Impl.h has an object W5100Class W5100 and mentioned as extern W5100Class W5100 at w5100.h file.
So, does it possible improve the library, e.g. put some void pointer at classes
class EthernetUDP;
class EthernetClient;
class EthernetServer;
class EthernetClass
and do a static casting to W5100Class objects to void the use that library with more than one W5500 sharing SPI , and put a method to turn on/off CS pin to control the "active" W5500 ?
In that scenario we can use a sharing SPI where just one W5500 is active (and disable the existing other at same SPI bus).
Other scenario is to use different SPI bus at ESP32 , and different CS, RST, INT pins, but with own implementation.
In short, allow different physical controllers to be used with the same library.
Thanks In Advace.
In few cases I've needed to call softreset()
upon startup. Right now, I have to do something like:
Ethernet.begin(mac, IPAddress(0, 0, 0, 0)); // HACK: set a static IP first, so we can do softreset
Ethernet.softreset();
Ethernet.begin(mac); // Then DHCP
Not sure what the best solution is here. Maybe have softreset
call w5500.init()
?
Hello i don't have a issue really. I'm trying to figure out how to keep the wiznet 550io module power down. I don't need to run it at a full 100 mb connection using your Library. Can you help me out please?
With Arduino made a Audio system (Teensy with the SGTL5000 codex) and the audio files can upload and download from pc to the teensy with a WIZ5500 ethernet board.
Form Teensy to PC is good.
From PC to Teensy is wrong, when de TCP buffer fulll, the data is not paused?
Thanks.
There doesn't seem to be a reason for the string to be non-const, so that would simplify things for the caller.
Thank you for cool job!!! I read all closed issues, but not found answer.
I use several arduino(micro, nano, mega) + W5500 in my home automation, and discovered:
if include <avr/wdt.h> for watchdog and then eth-client is trying, but can not connect to remote server (web- ftp- mqtt-) (communication problems, packets loss... errors...) - arduino freezes -> watchdog is triggered -> loop reboot! Endlessly! Even if i install wdt_enable(WDTO_8S) - does not help, too little time.
Ethernet.setRtCount(1); Ethernet.getRtTimeOut(50) - it also does not help.
Without watchdog, eth-client wait about 30...33 seconds. I checked it. Version of the library is the last.
You can check on example WebClient.ino
Maybe i 'm doing something wrong? I'm not so strong in programming... but I'm learning!
All datatypes from arduino API, like char, unsigned char, byte should changed into uint8_t
to avoid compiler problems with converting datatypes. Maybe also necessary for int (-> uint16_t, int16_t).
I am presently looking to use a W5500 board with a stm32f103 based "Bluepill" development board.
While I am successfully able to use this library on the default SPI pins, I'd like to be able to use the second SPI bus available on this microcontroller.
Thanks
P.S. I couldn't find a way attach a "question label" to this issue ..
I adapted the low overhead NTP client from https://playground.arduino.cc/Code/NTPclient to be a library and function with the Ethernet3 library. Working on setting it up as multicast on 124.0.1.1 to help keep network traffic down. I should do this as a pull request but have no idea how to do that. Do with it as you will. I was not able to keep the getUnixTime()
as an inline
funtion to reduce code overhead.
ntpUnixTime.h
#ifndef ntpunixtime_h
#define ntpunixtime_h
class EthernetUDP;
#include "Arduino.h"
#include "EthernetUdp3.h"
class UnixTime {
private:
EthernetUDP *_ntp;
const uint16_t _port=123;
uint8_t _udpInited;
public:
UnixTime(EthernetUDP *ntp);
UnixTime(EthernetUDP &ntp);
IPAddress timeServer;
void begin();
uint32_t getUnixTime();
void stop();
};
#endif
nrpUnixTime.cpp
/*
* © Francesco Potortì 2013 - GPLv3 - Revision: 1.13
*
* Send an NTP packet and wait for the response, return the Unix time
*
* To lower the memory footprint, no buffers are allocated for sending
* and receiving the NTP packets. Four bytes of memory are allocated
* for transmision, the rest is random garbage collected from the data
* memory segment, and the received packet is read one byte at a time.
* The Unix time is returned, that is, seconds from 1970-01-01T00:00.
*
* Modified by Cal Abel 2018
*/
#include "ntpUnixTime.h"
UnixTime::UnixTime(EthernetUDP *ntp){
_ntp = ntp;
}
void UnixTime::begin(){
_udpInited = _ntp->begin(_port); // open socket on specified port
}
void UnixTime::stop(){
_ntp->stop();
}
uint32_t UnixTime::getUnixTime() {
// Only the first four bytes of an outgoing NTP packet need to be set
// appropriately, the rest can be unspecified.
// https://www.cisco.com/c/en/us/about/press/internet-protocol-journal/back-issues/table-contents-58/154-ntp.html
// EC Peer Clock Precision: 0.000001 sec
// 06 Peer Polling Interval: 6 (64 sec)
// 03 Peer Clock Stratum: secondary reference (4)
// LI VN Mode
// E3 0b11 0b100 0b011
const uint32_t ntpFirstFourBytes = 0xEC0604E3; // NTP request header
// Fail if EthernetUDP.begin() could not init a socket
if (!_udpInited)
return 0;
// Clear received data from possible stray received packets
_ntp->flush();
// Send an NTP request
if (! (_ntp->beginPacket(timeServer, _port)
&& _ntp->write((uint8_t *)&ntpFirstFourBytes, 48) == 48
&& _ntp->endPacket()))
return 0; // sending request failed
// Wait for response; check every pollIntv ms up to maxPoll times
const uint8_t pollIntv = 150; // poll every this many ms
const uint8_t maxPoll = 15; // poll up to this many times
uint8_t pktLen; // received packet length
for (uint8_t i=0; i<maxPoll; i++) {
if ((pktLen = _ntp->parsePacket()) == 48)
break;
delay(pollIntv);
}
if (pktLen != 48)
return 0; // no correct packet received
// Read and discard the first useless bytes
// Set useless to 32 for speed; set to 40 for accuracy.
const uint8_t useless = 40;
for (uint8_t i = 0; i < useless; ++i)
_ntp->read();
// Read the integer part of sending time
uint32_t time = _ntp->read(); // NTP time
for (uint8_t i = 1; i < 4; i++)
time = time << 8 | _ntp->read();
// Round to the nearest second if we want accuracy
// The fractional part is the next byte divided by 256: if it is
// greater than 500ms we round to the next second; we also account
// for an assumed network delay of 50ms, and (0.5-0.05)*256=115;
// additionally, we account for how much we delayed reading the packet
// since its arrival, which we assume on average to be pollIntv/2.
time += (_ntp->read() > 115 - pollIntv/8);
// Discard the rest of the packet
_ntp->flush();
return time - 2208988800ul; // convert NTP time to Unix time
}
The MAX_SOCK_NUM definition should replaced by a dynamic version, depending on Etherner.init(socknumbers)
I used the eonardo ETH with Enernet2.h and the new function in version 3 is more or less what i reach for.
In general the function should renamed in BSD style. begin > open etc.
In ESP32, I have added W5500
Want to use both Wifi and LAN
While Compiling I am getting this Error.
cannot declare variable 'server' to be of abstract type 'EthernetServer'
Sorry for posting this issue but the last update to the Wiznet library is several years older. The following code snippet fails to return a lease from the DHCP server:
#include <Ethernet3.h>
#include <EthernetUdp3.h>
uint8_t MACaddress[6];
...
if (Ethernet.begin(MACaddress) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
;
}
The target machine is a Nano and the ETH shield is WIZ5500io. Thanks.
Kind regards.
Hi, I'm trying to run a basic piece of code to pick up the MAC address stored on my Wiz550io. I've had a look at the help files but can't find an example to start with. I've got this working on the Ethernet2 library but I need it working on Ethernet3. The code pick up the IP address fine but MAC is shown as 00:00:00:00:00:00. See code below:
`#include <SPI.h>
#include <Ethernet3.h>
#define WIZ550io_WITH_MACADDRESS
int8_t isConnected = 0;
uint8_t mac[6]; // array for mac address
void macAddress(uint8_t mac[]); // get the MAC Address
const char* macAddressReport();
IPAddress ip(192, 168, 0, 50);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);;
Serial.println("Write something here");
}
void loop() {
Serial.println(ip);
delay(1000);
}`
It should possible to initialize each sockets with different buffer sizes for RX/TX.
Maybe using an array for init.
Hai,
With Ethernet3 is it possible te sent and receive Multicast messages?
How can I do?
Thanks.
Hello, I was curious if I could use it with the Raspberry pi pico rp2040 ? If yes, should I use the spi0 or spi1 ?
Regards
Hello, I have encountered a problem with the library compatibility https://github.com/BlakeFoster/Arduino-Ping. Don't know another usable library of the same features, compatible with yours? Or you could not modify the icmp_ping library for use. My knowledge is not enough for this adjustment :-(
Thank you.
Ethernet3 or W5500 seems to have issues when the network link goes down and up. phyState() cannot be used as it will change to correct value if link goes up again. After occurrence my Arduino Nano cannot use the "EthernetClient client = server.available();" function or "client" gets not created.
Currently I solve the issue with a counter and recalling "server.begin();" function after 1000 loops when no new connection occurs.
Can you overload init() function? You can specify which SPI bus to use.
void EthernetClass::init(uint8_t sspin)
{
W5100.setSS(sspin);
}
void EthernetClass::init(uint8_t sspin, SPIClass &spi)
{
_spi = spi;
W5100.setSS(sspin);
}
"setHostname" dont work for me
I use W5500 shield and ESO8266
Init
Ethernet.setHostname("ethernet"); Ethernet.begin(mac);
DHCP return address
But when I link for ethernet.local there os no answer in browser.
What am I doing wrong?
P.S. Wifi host name works fine
Hello, I don't know exactly where the problem is, but if I try to create an html page larger than 2k, a part of the page will load in the browser (corresponds to a size of about 2k) and then restart for an internal error. I use W5500 (ethernet3), esp8266 (sdk 2.7.1), ethernetwebserver (v 1.0.7).
`void handleRoot()
{
char temp[3000];
uptime::calculateUptime();
float x1 = newVoltageSend;
int x2 = uptime::getDays();
int x3 = uptime::getHours();
int x4 = uptime::getMinutes();
int x5 = uptime::getSeconds();
snprintf(temp, 3000,
"\
.
I initialize ethernet according to the procedure from the example to the size 4k, I also tried a bigger one.
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
#define ETHERNET3_MAX_SOCK_NUM 4
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
Ethernet.begin(eeprom_config.mac, ip, subnet, gateway, dns_server);
I don't know where I can make a mistake, can you help me how to send a larger page as 2k.
Or are there other restrictions that prevent the use of more than 2k pages?
Thank you
PS: unfortunately the html code does not display correctly here, but it is valid.
This bug has been around forever. EthernetServer::available() is used to get a new inbound connection on a socket. But it won't actually return the new connection unless/until the remote end SENDs data to the socket. This causes trouble for several situations, including stuff I have ported from Ethernet and EthernetENC libraries.
Simple fix: get rid of the incorrect check of client.available() in there, which currently causes the connection attempt to be ignored unless data is available() from the remote end.
EthernetUdp3::parsePacket()
should be non blocking.
I'm pretty sure the problem stems from the do-while loop in w5500.getRXReceivedSize(_sock)
. Not sure how to fix at the moment.
Might be worth implementing some version of Ethernet.socketRecvAvailable(sockindex) > 0
as used in socket utility of Teensy version of Ethernet?
Hi :)
I am not sure, may be its a bug in my code. But i guess there is a problem with
the "MAX_SOCK_NUM 8" definition in w5500.h
In my case socket 1 is doing some UDP.
On socket 2 a webserver is running.
So i init the w5500 with Ethernet.init(2);
The webpage uses some javascript to get new values from the server.
But when the controller (in my case a Teensy 3.6) restarts with a cold reset
and the html page is already loaded, the javascript function gets no connection
to the server.
But after refreshing the page manually in the browser 6 times the js-function was fine.
So i took a look at all socket status registers with w5500.readSnSR() during the
manual webpage refreshing. And after each refresh a new socket was used from
socket 3 to socket 8.
Changing MAX_SOCK_NUM from 8 to 2 in w5500.h solved this for me.
Best
Putzlicht
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.