Pages: [1]   Go Down
Author Topic: Non-Blocking Ethernet Library  (Read 1618 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there !
I'm quite new in the arduino world, but i must admit it's a damn cool toy smiley


Anyway, i'm here, obviously, because i have a little problem.
I wanted to use the non-blocking Ethernet library updated by StoneHippo :
https://github.com/stonehippo/arduino-ethernet

Because i simply want to get some LEDs blinking during a server call which isn't possible with the standard Ethernet library due to the blocking behavior of all its methods.

So, I installed everything, i loaded the poll DHCP example, compiled and transfered it o my arduino R3 + Ethernet Shield R3 and it seems to execute correctly.
But, whether I use the polling option or not, it stucks at DHCP discovering steps.
With the standard library I have no problem, it finds the network's DHCP server after a few seconds, but with this lib it stucks until the end of time :3.

As i'm a bit noob i must be missing something but i really can't figure out what.
The only hint I have from the documentations i read is that it can stuck there if there is no DHCP server on the network. Which I actually have :/.


If some arduino guru had any kind of hint i would really appreciate it smiley

Thanks for reading me smiley
Have a nice day/night/whatever!
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because i simply want to get some LEDs blinking during a server call which isn't possible with the standard Ethernet library due to the blocking behavior of all its methods.
What ethernet functions do you see as blocking? The only blocking function would be client.write() if the tx buffer is full. It will wait for space in the buffer. AFAIK, nothing else is blocking, not even client.read() if nothing is in the rx buffer. It returns int -1 immediately.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep sorry you're right, actually client.print and write aren't blocking.
I was more thinking about connect() and begin() methods.

To be more precise, I have an Mifare module to capture RFID cards. When the user passes a card, its ID is sent to a server and during the server's connection i'd like to get those LEDs blinking to get something more fancy than my RGB LED going purple, then green when it completes.
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Ethernet.begin(mac) function is run only in the setup() routine, so you can forget about that being blocking, which it isn't. It returns whether it succeeds or fails. It is up to you to block there if the code needs that connection.

The connect function time is dependent on the server, but even it doesn't block if the connection cannot be established.

I know nothing of the other third party ethernet code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The connect function time is dependent on the server, but even it doesn't block if the connection cannot be established.
Yup, that's my point =).
As i said, a simple LED that stays ON in a specific color during the server's connection actually works, but i would like to get something more catchy and explicit like a circle of LEDs going ON and OFF more or less like a good old spinning.
This is impossible to do with the standard Ethernet Library. Or i have to fake it by doing that after the connection :/

As you're trying to make me understand, this is really not a big deal and I could do without that, but i'm curious and I'd like to get this lib working and understand what I am doing wrong =).
It's always more interesting to learn why we're stuck at something than getting around the problem, i think.

Thanks for your answers smiley-wink
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AFAIK, the ethernet functions do not use interrupts, and as long as the LED doesn't use the SPI, you could set up an interrupt function to blink the LED. However, I don't know if I would go to all that effort and program/SRAM memory to play "La Cucaracha" while waiting, if you know what I mean.  smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I forgot to say that i'm also a perfect newbie in the C world, so the interrupts are quite obscure for me, but as you said, it seems a bit complicated for such a little added value smiley-wink
And even if i would certainly learn loads of interesting things by doing that kind of stupid thing, I really don't have enough C background to do this anyway.

But, just to go back to the main problem, I guess you have no idea or not enough informations to know why it's not working.? smiley-red
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know the standard issue w5100/w5200 ethernet library. It works for me. Like I said in reply #3, I know nothing of third party ethernet libraries.
Logged

Aix en Provence, France
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Surfer Tim,

Just wondering if there is a way to "overcome" a failed DHCP request. I have a program running that happily connects to the intended surfer and when the ethernet cable gets unplugged in it just spins connect-disconnect etc, AND the rest of the sketch keeps running LCD sensors LED's etc.. So happy days there..
The issue that I have is when the Arduino -(Mega with Ethernet shield- w5100)- gets restarted and there is no Ethernet connection available like after a power failure, The sketch stalls completely.

Only after a restart WITH the router booted up will the unit resume its intended function, I hope that you would have some ideas how to tweak

( I read a post by http://gkaindl.com/software/arduino-ethernet/dhcp  that eluded to a mod of the dhcp.h file?

I am trying to achieve that the sketch runs -except the web connection- but when one becomes available it then eventually connects...

I'd be very grateful if you would be able to share your insights..

Erick
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This will keep trying to get an ip forever until it gets one. Is that what you want?
Code:
// start the Ethernet connection:
  Serial.println("Starting ethernet");

  while (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    delay(5000);
    Serial.println("trying DHCP again");
  }
Logged

Aix en Provence, France
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
This will keep trying to get an ip forever until it gets one. Is that what you want?

Well that could definitely help- Thank you- However my issue is that the rest of the sketch - the remainder of set up and loop- will not run.

I have functionality in this code that can run locally and notify the user - when they look- via lcd that there is no connection. The problem is that without the ethernet connection established nothing works.

If on start up the Ethernet connection is established it runs fine, even if afterwards the cable gets disconnected for a few turns of the loop it happily reconnects once a network is available again. I live in an area where the power goes of regular and the restarting of the modems takes infinitely longer than the Arduino.

I have yet to find out what happens when the DHCP server decides the lease is up and someone else takes the address in the mean time. reboot solves all but I am putting in sensors on a remote locationand hope to have reliable connection for 30 days at a time...

Thanks again,

Erick
Quote
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However my issue is that the rest of the sketch - the remainder of set up and loop- will not run.
Maybe you should post that sketch.

Quote
have yet to find out what happens when the DHCP server decides the lease is up and someone else takes the address in the mean time. reboot solves all but I am putting in sensors on a remote locationand hope to have reliable connection for 30 days at a time...
No, that is what Ethernet.maintain() is for.
http://arduino.cc/en/Reference/EthernetMaintain
Until half the lease time is expired, this does nothing and returns 0 (nothing happened). After that, it renews the dhcp lease just like it supposed to. I checked it. It works. I call it once every 20 minutes, but I don't see why you couldn't call it more often than that.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

Just wondering if you found what the problem is: I am facing the same issue with this library.

Thanks!


Hi there !
I'm quite new in the arduino world, but i must admit it's a damn cool toy smiley


Anyway, i'm here, obviously, because i have a little problem.
I wanted to use the non-blocking Ethernet library updated by StoneHippo :
https://github.com/stonehippo/arduino-ethernet

Because i simply want to get some LEDs blinking during a server call which isn't possible with the standard Ethernet library due to the blocking behavior of all its methods.

So, I installed everything, i loaded the poll DHCP example, compiled and transfered it o my arduino R3 + Ethernet Shield R3 and it seems to execute correctly.
But, whether I use the polling option or not, it stucks at DHCP discovering steps.
With the standard library I have no problem, it finds the network's DHCP server after a few seconds, but with this lib it stucks until the end of time :3.

As i'm a bit noob i must be missing something but i really can't figure out what.
The only hint I have from the documentations i read is that it can stuck there if there is no DHCP server on the network. Which I actually have :/.


If some arduino guru had any kind of hint i would really appreciate it smiley

Thanks for reading me smiley
Have a nice day/night/whatever!
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5388
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am facing the same issue with this library.
Why are you using that library? The ethernet library included with the IDE works good. What do you think you are getting with that library that is better than the standard library?
Quote
Because i simply want to get some LEDs blinking during a server call which isn't possible with the standard Ethernet library due to the blocking behavior of all its methods.
That is not true. The OP admits that is the first response.
Quote
Yep sorry you're right, actually client.print and write aren't blocking.
I was more thinking about connect() and begin() methods.
The connect() and begin() functions aren't blocking either. The DHCP begin() call is "blocking" if you have a SD card in the slot and don't disable or initialize it. Then the Ethernet.begin(mac) call will never return.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
The connect() and begin() functions aren't blocking either. The DHCP begin() call is "blocking" if you have a SD card in the slot and don't disable or initialize it. Then the Ethernet.begin(mac) call will never return.

Hmm... Correct if I am wrong but I believe begin() will block (at least for "timeout seconds") until it either gets an ip or if it fails.

In my case I need a resilient device, that can "run" other tasks while networking is being figured it out. Worst case scenario, the device is running and for some reason network needs to be re-established (after a power outage for instance) while other tasks are still running.

Does it make sense ?
Logged

Pages: [1]   Go Up
Jump to: