Is it really possible to manage more than one connexion with w5100 ?
Yes, the WizNet5100 can handle up to 4 connections. Usually these are reserved to handle incoming connections if the server class is used. You can ask for a specific socket index in the constructor of the EthernetClient class. In most situation you're probably successful if you ask for index 3 to open the client connection.
EthernetClient webclient(3);
if (webclient.connect(host, port)) {
Serial.println("Connected!");
}
Source code of the Ethernet library and datasheet of the WizNet5100 chip. As this is an officially not supported way to use the Ethernet library you won't find any higher level documentation.
clix.connect(host,port) --> gives 0 until I stop the current connexion
And host is an IPAddress? If the library must resolve a DNS name it needs another socket (maybe even two) for the DNS UDP traffic.
As I already wrote, your hardware choice is not ideal for the task. Why don't you use a Linux based board (p.e. Raspberry Pi) for the web stuff? There you have almost no restrictions and you can connect the Due to it if you need to do some hardware stuff on top.
Hardware choice : I need a very low power system ; the final goal is to use only one (maybe that will be 2) 1,5 sqm photovoltaic pannel with motorization for a whole house. Due is about 200mW (many times less than Pi)... I have a lot of ESP8266 in a variety of home made hardware to control every power usage. Every house has a wifi router now ; so my system is very easy and cheap to install.
All colllected data are in the W5100 shield SD card and can be downloaded to be analyzed.
I'm pretty satisfied with the system architecture.
Host is an IPAddress. I made lot of tests and I never could connect to an external server without stopping current client. I made tests with multiple servers using different ports and that works. I'm not expert about ethernet low level software (and I hope to avoid to learn it...). Is only "EthernetClient" using a socket ? and what about "EthernetServer" ? I have also UDP instance for NTP...
pylon:
it needs another socket (maybe even two) for the DNS UDP traffic.
Here is maybe the problem... First I will try without UDP...
I made a test without UDP ; that's working perfectly.
Then I've seen that there was no stop for the Udp connexion in my code. So I added the stop().
But that seems not enought ; Is there anything else to close and how ?
EthernetUDP Udp;
...
int getUDPdate(uint32_t* hms,uint32_t* amj,byte* js)
{
int returnStatus=0;
int year=0,month=0,day=0,hour=0,minute=0,second=0;
Udp.begin(localUDPPort);
sendNTPpacket(timeServer);
delay(1000);
if (Udp.parsePacket()) {
Udp.read(packetBuffer, NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
long secsSince1900 = highWord << 16 | lowWord;
long secsSince1970 = secsSince1900 -2208988800UL;
convertNTP(&secsSince1970,&year,&month,&day,js,&hour,&minute,&second);
*amj=year*10000L+month*100+day;*hms=hour*10000L+minute*100+second;
returnStatus=1;
}
Udp.stop();
return returnStatus;
}
Then I've seen that there was no stop for the Udp connexion in my code. So I added the stop().
But that seems not enought ; Is there anything else to close and how ?
That's all you have to do as the stop() method closes the socket. The socket may need a few ms to get into state SOCK_CLOSED but as soon as it reached that state it should be available again for next usage.
You can check the status using the W5100.readSnSR(socketNo); method. Any socket in status SOCKET_CLOSED is available for new connections.
Due is about 200mW (many times less than Pi)... I have a lot of ESP8266 in a variety of home made hardware to control every power usage. Every house has a wifi router now ; so my system is very easy and cheap to install.
That router probably makes the better domestic server than the Arduino Due. As it usually runs on Linux you have a full fledged OS that can handle dozens to hundreds of connections.
pylon:
That's all you have to do as the stop() method closes the socket. The socket may need a few ms to get into state SOCK_CLOSED but as soon as it reached that state it should be available again for next usage.
You can check the status using the W5100.readSnSR(socketNo); method. Any socket in status SOCKET_CLOSED is available for new connections.
I will try that
That router probably makes the better domestic server than the Arduino Due. As it usually runs on Linux you have a full fledged OS that can handle dozens to hundreds of connections.
I agree ... but I play in the very low power country every watt saved is important for me. I dont need lot of connections... I discovered the W5500 (with 8 connections). I have to evaluate its power consumption. 8 connections is enougth for my system.