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.