I have been working on a sensor node that monitors power consumption, and some other environmental characteristics. I have some simple code that seems to work well, for a while. It then freezes up, and I am not exactly sure why.
I have research this issue around this forum, as well as on the internet and come up with a few possible scenarios.
- WizNet chip is having issues > could connect a reset pin
- My code is crap (very likely)
- Arduino itself is freezing up (probably due to 2)
I am not exactly sure where to procede, but I have a few questions for any knowledgeable person:
Is it safe to call Ethernet.begin() repeatedly? If so, what condition should cause me to call it? Should there be a timeout first?
I am using the EthernetDHCP library (http://gkaindl.com/software/arduino-ethernet/dhcp), so I call EthernetDHCP.maintain() in my loop
Will that maintain the WizNet, as well as try to give me a nice IP address when my lease expires?
Also, I am trying to user yaler (yaler.org), to enable easy firewall penetration.
If anyone has experience with it, let me know. I am also uncertain about implementing it reliably.
Isaac
I have the "software reset pin" change installed.
I have a (re-)initialization routine that's called at startup and after a timeout. It looks, in part, like this:
pinMode(WIZNET_RESET_PIN, OUTPUT);
digitalWrite(WIZNET_RESET_PIN, HIGH);
delay(50);
digitalWrite(WIZNET_RESET_PIN, LOW);
delay(50);
digitalWrite(WIZNET_RESET_PIN, HIGH);
delay(100);
Ethernet.begin(mac, my_ip, gateway);
I haven't tried repeating Ethernet.begin without the Wiznet reset, so I won't predict what will happen without it.
Ran
Hi Isaac,
we currently use about the following code to run a Web service on an Arduino / WIZnet Ethernet shield and make it accessible via Yaler:
#include <Ethernet.h>
#include <EthernetDHCP.h>
byte mac[] = ...
byte yalerIp[] = ...
const char yalerId[] = "my-arduino";
...
void setup() {
EthernetDHCP.begin(mac); // calls Ethernet.begin()
... sensor setup ...
}
void loop() {
Client client(yalerIp, 80);
client.connect();
if (client.connected()) {
sendYalerPostRequest(client, yalerId);
int status = receiveYalerResponse(client);
if (status == 101) {
receiveBrowserRequest(client, ...);
... read sensor ...
sendBrowserResponse(client, ...);
} else {} // 204
client.stop();
}
}
With our DHCP server / office LAN, calling EthernetDHCP.maintain(); seems not to be necessary, as long as the DHCP server keeps running.
Cheers,
tamberg
http://yaler.org/
Here's a detailed write up of the Yaler Arduino Web LED demo including source code:
Cheers,
tamberg