Computing stuff tied to the physical world

Ethernet web client

In Hardware, Software on Nov 29, 2010 at 00:01

The Ether Card and the associated EtherCard library offer an easy way to connect a JeeNode to a LAN and internet. I consider this option useful enough to even want it within reach on a breadboard, so I designed the Bridge Board to support it as well. Here’s the setup, based on a JeeNode Experimenter’s Pack:

Dsc 2365

This is all it takes for an Ethernet-connected setup, and all JeeNode ports are still freely available for project use.

However, the EtherCard library only includes some examples for the web server approach, such as the EtherNode. What about using this setup to send requests out, and POSTing results to a remote web server?

Well, encouraged by a few great DNS-related patches to the code by Gérard Chevalier, who was also so kind to show me how he does DNS lookups and web requests, I’ve come up with two new example sketches:

  • The getStaticIP.pde sketch does just a HTTP get to a fixed IP address.
  • The getViaDNS.pde sketch looks up my server’s IP address by name, via a DNS lookup on startup.

Here is the code of getViaDNS:

Screen Shot 2010 11 27 at 15.38.35

Note that to make any kind of outgoing request outside your LAN, the IP address of the local LAN gateway has to be specified at setup time.

The dependency on the Ports library is due to the use of the MilliTimer class in this code. And because of that, the RF12 library also needs to be mentioned (it won’t increase the code size). Welcome to dependency hell…

Here is some sample output:

Screen Shot 2010 11 27 at 15.29.28

Even though this example is relatively short, I still find it quite awkward. The EtherCard library code really needs a major overhaul – far too much of the underlying mess is still being exposed for no good reason, IMO.

Furthermore, a massive code cleanup will be needed to overcome the current limitations of the EtherCard library: the need for a large RAM buffer, and the limitation that TCP requests and replies may only use a single ethernet frame (approx 1500 bytes).

But getting it working first was more important, and with these new examples you can now see how to implement outgoing TCP/IP requests (not just web/http, btw). Pachube, anyone?

  1. Its a big step, but to be really deployable in ‘real’ (ie techie free) environments it needs DHCP to make it plug and play. Whilst the ENC chip can be just about coaxed into this the code starts getting huge. What we really need (well I do!) is a Jee Node with onboard Wiznet ethernet, and preferably (simple 12v) PoE. Any thoughts?

    • The code is not that large (8 Kb is not “huge”) – the client is only 2 Kb larger for ENC28J60 than for Wiznet (but more limited).

      I’m investigating POE options. Note that 12V is non-standard.

  2. Very neat, I’ve been wanting to play with a client connection for a while.

    Can I ask where the DNS IP is defined, or is it assumed to the same as the Gateway? This is usually okay, especially for home networks, unfortunately some of us (cough) have to be a bit different!

    • I found out that the Google DNS is built-in (, see “dnslkup.cpp”. I’ll probably bring it out for configurability once I start tweaking this code.

  3. I agree 12v POE is non standard, but 48v gets complex – dedicated PSUs are more expensive, and the POE’d device has to signal back to the switch or PSU, hence needing a dedicated ‘module’ rather than a couple of discrete components to split the power out. Going back to my theoretic ‘non techie’ domestic or small Biz ‘remote install’ a wall wart PSU and passive injector is probably acceptable and preferable – a bit like a lot of (for example) outdoor wireless network gear works.

  4. The first link «EtherCard» in the text of the message is broken

Comments are closed.