A DIY web server

Building a Nanode from a kit and getting it to talk to the world.

It was 2011 and the age of Arduino.

Embedded programmable chips were all the rage (remember this was a year before the first iteration of the now ubiquitous Raspberry Pi.)

At the inaugural Brighton Mini Maker Faire I bought my first Arduino R3 and saw the Nanode on a table.

I can’t remember if one available to buy at that point as I think Ken Boak was putting the kits together by hand.

(I had to resort to buying one from the London Hackspace and then having the postie deliver it.)

So, what is a Nanode?

Photograph of a Nanode SBC or ‘Single Board Computer’. It came in kit form and this is the finished outcome, a long row of resistors and the main processor an ATmega328 chip. An Ethernet port takes up a lot of space on the right hand side, the power jack and FDTI cable connection on the left. Nanode Finished

From the project page :

Nanode is an open source Arduino-like board that has in-built web connectivity. It connects to a range of wireless, wired and ethernet interfaces. It allows you to develop web based sensor and control systems – giving you web access to six analogue sensor lines and six digital I/O lines. It costs under £20 as an easy build it yourself kit. Nanode was designed with Hacking in mind.

From the project applications page :

Nanode is an Arduino like 8 bit micro-controller board with integrated Ethernet connectivity.
It has 6 analogue sensing channels and 6 spare digital I/O lines.
It can be used for a variety of web connected applications including remote control and monitoring, as a smart sensor, home automation, as a Tweeting device, and for publishing small amounts of data to the web.
The existing software allows it to be set up as an I/O webserver – a device which sends the state of its analogue and digital I/O to a web page – and which can be controlled from that webpage.
However it is not restricted to just that role, it can act as a publisher device and send data to an intermediary open data service such as Pachube, and it can act as a web connected I/O device, which subscribes to a Pachube data feed and acts according to the data received from that feed – for example setting its I/O, updating a display or controlling some actuator device.

Even though the board is capable of collecting an input from say a thermal sensor and reporting that via an API to a third party (it used to be Pachube which has long since vanished), I use mine to present a simple web page.

I had a lot of fun assembling mine and everything it entailed.

Relearning how to solder.

Then bungling that by bridging two connections and remembering why I gave up soldering.

(You can see the bridged connection in the photo, just above the six holes that look like a Lego brick.)

A close up photograph of soldering that has inadvertently bridged two pads causing the board to fail. Bungled Soldering

However, a couple of photos and an IRC session later the problem was identified and I dug out the solder sucker to rectify my mistake.

Programming a Nanode

To keep the costs low the board does not have an FTDI serial/USB chip on board, it needs an FTDI cable to be able to connect to a host computer.

In this respect it is also similar the Arduino Pro and Pro Mini (or any number of the clones available).

(One alternative would be to remove the ATmega328 chip, slot it into an Arduino and send code to it that way.)

However, like the Arduino, the board can programmed using the standard Arduino IDE.

I’m_Alive.ino

// Based on the EtherCard library example 'backSoon.ino'
// 2011-01-30 <jc@wippler.nl>
//
// License: GPLv2
//
// Present an "I'm Alive' web page"

#include <EtherCard.h>

#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,250 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x4e,0x61,0x6e,0x6f,0x64,0x65 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "I'm Alive"
  "</title></head>"
  "<body>"
    "<h3>The Nanode Lives Again !!</h3>"
      "<p><em>"
        "OK, so not exactly a lot to see here,<br />"
        "But the Nanode is alive.<br />"
    "</em></p>"
    "Link back to <a rel=""me"" href=""https://botsin.space/@ConsummateTinkerer"">Mastodon</a>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  Serial.println("\n[ImAlive]");

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, 8) == 0)
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

All of the Nanode code examples can also be found on Forgejo .