Arduino/Ethernet/DHCP/Pachube basic tutorial

This example will go through the use and modification for the official Arduino Ethernet shield. There are a few problems with the shield that we have to deal with.

What you will need:

First off, Internet without computer is quite tricky, many error could easily happen and cause the Arduino to crash. I’ve tried several solution to prevent that error and I found that preventing error is the “best” way but not the “easiest” way. In this example we make use of “Watchdog Timer” to reset the Arduino whenever it crashes. Watchdog timer(WDT) is a built-in timing device on the Atmega ship, which could trigger a system reset. Unfortunately the original Arduino bootloader doesn’t support WDT. We will need new bootloader from Lady Ada. The bootloader and how to burn it can be found on her page.

After you burned Lady Ada’s bootloader (which is a little tricky...), we can go to the next step. Another problem with this official shield is it doesn’t reset itself properly, it only works if we start it with serial monitor. Special thank to AGT from Arduino forum, we’ve got the solution! You will have to modify your pricey shield a little bit. Basically, we need to be able to reset the shield manually and seperately from the Arduino itself. First, we need to bend the shield’s reset pin, so it wont connect to the Arduino’s reset pin altogether. Second, we will use pin9 to reset the shield by putting a wire between pin 9 and reset pin. (see picture below).

Now, we need to download DHCP library for our Arduino application from here then install it in your library. The DHCP library will take care of finding the IP address for the shield, that means you could plug this shield to any Ethernet router without worrying about the IP address.

Download the code from the attachment bottom of this page then we will go through the Arduino code, there are a few place that you will have to change.

On the first tab (Pachube_client)

#define ID             		1

incase you have more than 1 unit on same network, just change the unit ID to other number

#define REMOTEFEED		2654 

Remote feed number here

#define LOCALFEED		2282 

Local feed number here, this has to be your own feed

#define APIKEY         		"YOUR_PACHUBE_API_KEY_HERE" 

Replace your pachube api key here

We set up WDT in setup() first.

wdt_enable(WDTO_8S); 

Setup Watch Dog Timer to 8 sec, WDT will reset the Arduino if it doesn’t get “wdt_reset()” every 8 seconds. So we will have a WDT loop that will perform “wdt_reset()” in this case every 5 seconds. This sketch will connect to Pachube every 10 seconds, sending then receiving data from Pachube.

On the second tab (Functions), you may need to modify you local sensors, also your remote sensor, depending on what feed and ID that you want.

analog1 = analogRead(analogPin1);
analog2 = analogRead(analogPin2);
analog3 = analogRead(analogPin3);  

Define the local sensors here

int content_length = length(analog1) + length(analog2) + length(analog3) + 2 ; 

This line is to count the lenght of the content = lenght of each local sensor data + "," in this case we have 3 data so we will need 2 commas.

Then you will have to change.....

client.print(analog1); 
client.print(",");
client.print(analog2);
client.print(",");
client.print(analog3);

Then, modify the code here according to what ID do you want to use in your sketch.

remote1 = remoteSensor[0];         
remote2 = remoteSensor[1]; 
remote3 = remoteSensor[2];

This is pretty much everything you need to know in order to use Arduino & Pachube reliably without computer.

Good luck and have fun.

AttachmentSize
Pachube_client_100317.zip3.35 KB

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Could you expand on the follwoing please, what is it I'm meant to buyt and what shoudl I do with it?

"Unfortunately the original Arduino bootloader doesn’t support WDT. We will need new bootloader from Lady Ada. The bootloader and how to burn it can be found on her page. "

Is it the Adafruits modified bootloader I'm meant to buy and if so why would I want to then reburn that?

Mike

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Arduino's bootloader (when you first buy it) doesn't support the watchdog timer. So you need to use Lady Ada's bootloader. You can either burn your Arduino with her bootloader (as explained on her site: http://www.ladyada.net/library/arduino/bootloader.html - you can also try it without a programmer: http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html though I haven't tried it myself) or you can buy a new atmega chip from her store, which includes the bootloader already on it: http://www.adafruit.com/index.php?main_page=product_info&cPath=17&products_id=123&zenid=71c1fb27578efcad43b089a540df2838

hope that helps.

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

It does thanks, given that Arduino is a means to end for me, I'll just purchase the new atmega chip with the Adafruit bootloader preloaded.

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

When you say...
"Unfortunately the original Arduino bootloader doesn’t support WDT. We will need new bootloader from Lady Ada. The bootloader and how to burn it can be found on her page. "

Is this still true for the Arduino UNO? My understanding is that the UNO has the new optiboot loader that includes at least some of the Lady Ada improvements....?

Do I need to burn the Lady Ada bootloader into the UNO?

Thanks
Jeremy

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Not sure - we don't have an UNO here... You might find out over at the Arduino forums: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl

If it works, please post back here with info, thanks!

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

I am using Arduino UNO, and latest Version v05 of the Ethernet Shield (Marked "Arduino ETHShield SD")

I have followed the instructions as per this tutorial, and I am having trouble as when I set Pin 9 to output in order to reset the Ethernet Board it also causes the Arduino Uno to reset... I suspect that with the boards that I am using there are actually two pin "RESET" connections between the two boards. So bending the reset pin out as shown on the picture disconnects one of the pins, but the reset pin on the ICSP connector is still connected between the Ethernet Shield and the Arduino..... Therefore this Tutorial as described does not work for the latest versions of the boards....need to find a way to disconnect the Reset connection on the ICSP 6pin header... Anyone got any ideas? Thanks Jeremy

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

I have now confirmed that for the Arduino UNO and the Ethernet Shield V5 there are two reset pin connections between the two boards…

Overall Image Arduino UNO and Ethernet Shield V5

Therefore to implement this tutorial with these boards it is necessary to disconnect both connections as shown in these pictures.
Bend out Reset pin -Power connector..

Cut Reset Pin -Pin 5 in ICSP connector

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Great, thanks for the update!

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

I have an "old" NKC Ethernet Shield connected to an Arduino Mega. I made all modifications but there is no extra reset. After I connected the Ethernet Reset with Pin 9 and over an extra 100kOhm Resistor to GND it works fine. I am not sure if it is a good way, but it works.

RaKa

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Would anyone have a link to a project that uses this method _and_ onewire-based sensors (such as the DS18S20)? It appears that the reset bypass required by the watchdog timer may in some way interfere with the proper operation of onewire. The reason I say this is because I can get Serial Monitor to output the correct temperature once, immediately after pressing the reset button on the ethernet shield, but after the system cycles through, the reading from the onewire device returns to its zombie state (-1.25 C).

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

I've updated the code to use the Arduino Uno which includes the Optiboot bootloader activating the watchdog timer out of the box-- you are no longer required to reflash the bootloader with Adaboot if you have the Arduino Uno. Also a few code changes have been made to allow the new Arduino IDE 21. I'd recommend using the Freetronics Ethernet Shield as it includes a reset pad for resetting the WIZNET and freeing you from bending out the RESET pin of your shield :)

See the Article Below for a New tutorial for making a Pachube Client with Arduino:
http://www.australianrobotics.com.au/node/266

Updated Code for Arduino IDE 21:
https://github.com/sirleech/pachube_client

- Chris Lee

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Hi Folks,
a relative newbie here.

I have the Arduino UNO and the Official Ethernet Shield.
Could you please clarify the steps needed to implement the watchdog reset?

Do I still follow the code in the original tutorial
DHCP Library
Pachube Client changes

and then cut / isolate the two reset pins per JCHPAUL's post?

Or
Can I use Chris Lee's code and tutorial above, with the Official Ethernet shield instead of the Freetronics one and if so what hardware changes are needed (eg pins etc)

thanks in advance folks

cheers
Andrew

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Hi Andrew,

Actually I've been doing without any resets to the Ethernet Shield and using only the Watchdog timer. It seems that there may be a bug in either the DHCP library or a problem with my router-- I am forced to roll my MAC addresses or I have connection problems.

Latest code with rolling MAC is in github, but you can comment it out if its not needed :)

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Thanks for the reply.
I didn't get a chance to test it out until last night.
Interestingly I dont need to roll the MAC, so you are probably right that it may be your router. I will see how it goes over a few days.

Im still trying to understand the code. (So far coding skills are a bit rough, but improving :)
This code is resetting very regularly and performing a new DHCP request a couple of times a minute?
Is this normal?

I was initially expecting that a reset of the board was going to be an exception rather than the norm. Though from what I can tell from the code it looks like normal operation is to reset regularly.

Cheers
Andrew

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

No, WDT_RESET is only issuing a watchdog registration. It will not reset until no registration has been made in 8 seconds (so the loop stops, 8 seconds later the AVR resets).

At this time the DHCP is requested again. Keep in mind my code rolls the MAC address so the Ethernet shield will most likely have variable IP addresses and would only useful for a datalogger and not as useful for automation.

A project that is on my extended to do (tickler) list is a non-DHCP sketch that uses Watchdog timer for reliability, so far I haven't seen this piece of code yet :)

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Hello,
I've built a few arduiono projects over the years, and in getting to the bottom of various problems, I invested in a Dragon hardware debugger. Great piece of kit.

Anyway, I'm about to embark on a (Pachube) project using the Ethernet shield. I'm concerned about the amount of reports of crashes and hangs. Can anyone tell me whether it's just the Eth Shield that hangs, or is it the Arduino? (Since folk are talking about watchdog timers, I'm guessing the latter).

Maybe it might be possible to locate the cause using hardware-assisted debugging. I'm certainly willing to try. Can anyone give me a consistent scenario that will lead to a hang / crash?

Cheers,
Con

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Hi,

I startet with arduino hardware base 3 weeks ago and used an Arduino Uno and the official Ethernet shield with the following hardware:
* SPI Bus for Ethernet and SD attached to pins 11, 12, 13 (Standard with new Ethernet & SD shield)
* Ethernet Chip Select attached to pin 10 (Standard with new Ethernet & SD shield)
* SD Chipselect attached to pin 4 (Standard with new Ethernet & SD shield)
* RTC Clock DS1307 to create Timestamp. I2C is assumed to be on A4/A5
* I was able to place a DS1307 with battery in a layer between the Arduino and the Ethernet shield.
* 7 DS18B20 OneWire temperature sensors attached to pin 3

I have the original bootloader with no hardware modifications to the reset line.
The watchdog timer is active to reset the device within 8 seconds without activity
There is no need to roll MAC addresses. The new shield comes with a sticker with a real Mac address and this address should be used solely.

My program basically does the following:

Once a day: synchronize RTC with NTP server
Every three minutes: append a line with timestamp and temperatures to a csv file (one file per day)
Every three minutes: update my pachube feed with 5 temperature values
regularly call wdt_reset()

I started the device outside the test environment 5 days ago and had constant updates to SD card and pachube until today where pachube logged my feed as frozen. I was able to verify that that the SD card updates continued to work.
After a hard reset everything was working again.

It happens that at the time the pachube updates stopped I was doing a lot of api calls to test my temperature graphs which are based on goggle api calls. So it is possible that the arduino received some error messages from the pachube server.

My next steps: I still assume that the reset pin hack described in this article is no longer needed when you use the UNO with the new Ethernet shield. I further assume that the reset caused by the watchdog timer resets both, the UNO and the Ethernet shield.

***** Please note !! *********
This thread was started over three years ago! In the meantime the problems with the reset of the ethernet controller have been solved. The newest version of the ethernet shield also includes a reset controller, to ensure that the W5100 Ethernet module is properly reset on power-up.
**************************

So I will check the pachube responses and if there is repeated fail I will force a reset of the device.

regards
Chris

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

@Con, if you remove the watchdog code in my sketch
https://github.com/sirleech/pachube_client

It will freeze consistently, perhaps 1 hours later, to 1 week.

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

Hi sirleech

I just had a short look on your sketch.

- you are using deprecated pachube api calls. -> use the highly recommended v2 api. If you want to save time use the
ERxPachube library http://code.google.com/p/pachubelibrary/

- you are using the manual reset of the ethernet shield. If you have a new Ethernet shield with reset controller you shouldn't do this.

- you are rolling your Mac addresses. There is absolute no need to change the MAC address of a network device while it is operating. Check your network setup

Re: Arduino/Ethernet/DHCP/Pachube basic tutorial

spreaderb wrote:Hi sirleech

I just had a short look on your sketch.

- you are using deprecated pachube api calls. -> use the highly recommended v2 api. If you want to save time use the
ERxPachube library http://code.google.com/p/pachubelibrary/

This looks great, I'm suprised it's not posted on the page for Pachube/Arduino.

spreaderb wrote:
- you are using the manual reset of the ethernet shield. If you have a new Ethernet shield with reset controller you shouldn't do this.

Yep-- this is old code form the original that needs to be removed.

spreaderb wrote:

- you are rolling your Mac addresses. There is absolute no need to change the MAC address of a network device while it is operating. Check your network setup

I agree-- this is a funny workaround that I should probably keep in a local branch. I reckon a new sketch, rewritten using ERxPachube is in order :) Combined with EthernetDHCP and the Watchdog timer on Optiboot Arduinos, it has the potential to make a reliable Pachube data logger.