Nanode

Nanode

Ken Boak at the London Hackerspace recently sent over a Nanode to try out. This is a handy combination of Arduino and ENC28J60 Ethernet in one package. My mission is to try it out with Jee Labs’ EtherCard library. This code is by far the most mature, stable, and easiest to use ENC28J60 driver for Arduino.

I’m happy to report that the 7752 revision of EtherCard works perfectly out of the box with NO changes. Even the SPI chip select pin is right, because Jee Labs’ EtherCard hardware uses pin 8, just like Nanode.

Download EtherCard

The best way to get EtherCard is to check out the source from Jee Labs’ SVN. Open up a terminal, cd to your Arduino libraries directory, and fire this up. You can omit the “-r 7752” if you want to get the absolute latest.

svn co -r 7752 svn://svn.jeelabs.org/jeelabs/trunk/libraries/EtherCard

Jee Labs has a Questions and Support forum, which you may find useful if things don’t work just right.

Hello World

The ‘hello world’ of EtherCard is the getStaticIP example. This example works out of the box, as log as you’re on a 192.168.1/24 network, which is the default configuration for home routers. If not, simply change the static IP settings for your network and try again.

Just make these match your network setup.

// ethernet interface ip address
static byte myip[] = { 192,168,1,203 };
 
// gateway ip address
static byte gwip[] = { 192,168,1,1 };

 From a terminal monitor, you will see this, indicating that google.com heard you.

[getStaticIP]
Server: 74.125.79.99
Gateway found
 
>>> REQ
<<< reply 558 ms
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/foo/bar
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Sun, 07 Aug 2011 01:19:40 GMT
Expires: Tue, 06 Sep 2011 01:19:40 GMT
Cache-Control: public,
 
>>> REQ
<<< reply 362 ms
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/foo/bar
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Sun, 07 Aug 2011 01:19:44 GMT
Expires: Tue, 06 Sep 2011 01:19:44 GMT
Cache-Control: public,

Nanode to Pachube

Now, it’s time for a real-life example. This example will send data to Pachube, AND take advantage of the built-in MAC address.

  1. Sign up for a free account from Pachube.com
  2. Optionally, if you have a Nanode, upgrade to a Free Pachube Pro Account
  3. Create a new feed
  4. Create at least two data streams, named “1” and “2”.
  5. Download the nanode_pachube example from gist #1130021
  6. Change the Pachube settings to match your account.
  7. Change the static IP settings to match your network.

That is, change these to be appropriate:

// change these settings to match your own setup
#define FEED "33735"
#define APIKEY "3U_mvycWRlzWw_0o2RrPUY8cRG-E1wmDTsqTTeR5DrM"
 
// Static IP configuration to use if no DHCP found
// Change these to match your site setup
static byte static_ip[] = { 192,168,1,91 };
static byte static_gw[] = { 192,168,1,1 };
static byte static_dns[] = { 192,168,1,99 };

The example will pull the MAC address off the Nanode, and attempt to get configured via DHCP if it’s available on your network. If not, it will use the static configuration you set up.

After a few minutes, you should see this:

EtherCard/examples/nanode_pachube
MAC: 00:04:a3:2c:29:19
DHCP failed, using static configuration
IP: 192.168.1.91
GW: 192.168.1.1
DNS: 192.168.1.99
SRV: 173.203.98.29
Sending...
REQUEST: 177
PUT http://api.pachube.com/v2/feeds/33735.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: 3U_mvycWRlzWw_0o2RrPUY8cRG-E1wmDTsqTTeR5DrM
Content-Length: 14
 
1,289
2,107
 
REPLY:
HTTP/1.1 200 OK
Date: Sat, 06 Aug 2011 20:46:34 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
Cache-Control: max-age=0
Content-Length: 1
Age: 0
Vary: Accept-Encoding
 
ending...
REQUEST: 176
PUT http://api.pachube.com/v2/feeds/33735.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: 3U_mvycWRlzWw_0o2RrPUY8cRG-E1wmDTsqTTeR5DrM
Content-Length: 13
 
1,370
2,50
 
REPLY:
HTTP/1.1 200 OK
Date: Sat, 06 Aug 2011 20:46:44 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
Cache-Control: max-age=0
Content-Length: 1
Age: 0
Vary: Accept-Encoding

This is the ‘pachube’ example from EtherCard, with a few tweaks:

  1. Uses static IP configuration in case DHCP fails (which seems to be often)
  2. Reads MAC address from the Nanode chip
  3. Sends only 5 requests before stopping, so you don’t get rate-limited by Pachube
  4. Enables printf for easy printing convenience
  5. Fixed the example to accept feed ids > 32768

8 Comments

Filed under Arduino, Ethernet

8 responses to “Nanode

  1. Alexander

    Unfortunately your code does not compile for me. Any pointer why I get this error? Thanks!

    nanode_pachube:11: error: variable or field ‘read_MAC’ declared void
    nanode_pachube:11: error: ‘bytes6_t’ was not declared in this scope
    nanode_pachube:11: error: ‘mac_address’ was not declared in this scope

  2. Thanks for reporting this. I committed a fix, please try it now. It turns out the Arduino IDE does not allow functions to be declared using typedefs declared in the sketch. I should probably double-check code in the IDE before posting it!

  3. Alexander

    Thanks, that works. I havn’t been able to publish to Pachube yet.

  4. What do you use instead of the Arduino IDE?

  5. Brian

    Any suggestions for getting a floating variable to report to pachube in your sketch. I have tried multiple different ways and it works for a while, but then pachube returns a : CSV Parser Error: CSV is invalid. Incorrect number of fields. I have tried dtostrf along with sprintf to convert the float. It seems to me like the stash payload gets off sync and tries to put part of my API key where the .CSV should go.

Leave a comment