Arduino nano and ethernet shield (ENC28J60) posting to local emonsd with ethercard.h library

Hi all,

I recently bought 2 arduino nanos and 2 ethernet shields for them. The ethernet shield needs to use ethercard.h library. I am trying to post to my local emoncms with this library and there is no way.

I have tried multiple sketches and googling a lot with no result.

I have this sketch that is posting well to, but don’t work with my emoncms local. Please,can you help me?

  This is a basic web client demo sending test data to emoncms
  It sends a couple of example variables in a semi-json like format: {power:252.4,temperature:15.4}
  Try creating an account on then get the write api key and enter in line 51 replacing
  the text YOURAPIKEY.
  This example features both DCHP and DNS Lookup.
  DHCP is where we ask the router for an ip address.
  DNS is where we ask a Domain name server for the ip address of the server we want to send data to:
  the domain name is linked to the ip address
  Using DNS Lookup we can save having to remember these hard to remember strings of numbers. 
  Part of the project
  Licence: GNU GPL V3

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
unsigned long timer;

const char website[] PROGMEM = "";

void setup () 
  Serial.println("03 - Basic Web Client");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
  // DHCP Setup
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

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

  // DNS Setup
  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
  ether.printIp("SRV: ", ether.hisip);

void loop () {
  if ((millis()-timer)>5000) {
    timer = millis();
    Serial.println("Request sent");
    // Send some test data to the server:
    ether.browseUrl(PSTR("/emoncms/input/post?apikey=xxxxxxxx&json="), "{power:252.4,temperature:15.4}", website, 0);

I think you have not told it which server to use. "/emoncms [etc] " means local to your Nano, which is wrong.
You must use the “dotted IP Address” of the computer where emoncms is running to tell it where on your LAN to send the data. Your router will tell you what it is. It might be something like " …[etc] "

Thanks for your fast reply Robert,

I have replaced for my emonsd ip: at the top of the sketch.

(I looked for that, and did not see it.) Does emoncms appear at the root on your server?

Yes Robert, my server is at,

Another data is that via serial I get a DNS error, “DNS failed”, with no porblems only with my local server.

This url is working well as a test:{power:200}&apikey=190528xxxxxxxx

I have other arduinos posting well to the same server but they work with ethernet,h library and this posting code:

    // if there's a successful connection:
if (client.connect(server, 80)) {
    // send the HTTP GET request:
    client.print("GET /emoncms/input/post?apikey=");
    if (node > 0) {
    client.println("} HTTP/1.1");
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    // note the time that the connection was made:
    lastConnectionTime = millis();
  else {
    // if you couldn't make a connection:
    Serial.println("Conexió fallada");

I have found some sketches but nothing solved, I don’t know what mistake I have. Last sketch I have been working is this one, with stiatic ip. But nothing received at my emonsd server… This sketch is to use with DHT sensor to post H and T data. For now, post string is posting example data: {power:252.4,temperature:15.4}

I don’t understand where is the problem. How can i know how ether.browseUrl is composing the url??

This is working ok on webbrowser:{power:252.4,temperature:15.4}

I found this topic of the archived forum talking about that problem:
But the working sketch: NanodeRF_singleCT It’s not alive today…

#include <EtherCard.h>
#include <DHT.h>;

#define DHTPIN 5     // pin del sensor DHT
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

int chk;
float hum;  //Enmagatzema el valor humitat
float temp; //Enmagatzema el valor temperatura

#define REQUEST_RATE 5000 // milliseconds

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };  // ethernet interface mac address
static byte myip[] = { 192,168,1,32 };                    // ethernet interface ip address
static byte gwip[] = { 192,168,1,1 };                     // gateway ip address
static byte hisip[] = { 192,168,1,30 };                   // remote website ip address and port
const char website[] PROGMEM = "";            // Set this to the domain name of your hosted emoncms - leave blank if posting to IP address

byte Ethernet::buffer[300];   // a very small tcp/ip buffer is enough here
static long timer;

// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
  Serial.print("<<< reply ");
  Serial.print(millis() - timer);
  Serial.println(" ms");
  Serial.println((const char*) Ethernet::buffer + off);

void setup () {

  Serial.println("ARDUINO NANO MENJADOR");
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");

  ether.staticSetup(myip, gwip);

  ether.copyIp(ether.hisip, hisip);
  ether.printIp("Server: ", ether.hisip);

  while (ether.clientWaitingGw())
  Serial.println("Gateway found");
  timer = - REQUEST_RATE; // start timing out right away


void loop () {

    delay(2000); //2" entre lectures de sensor
    hum = dht.readHumidity();
    temp= dht.readTemperature();

  Serial.print("Temperatura: ");
  Serial.print("Humitat: ");

  if (millis() > timer + REQUEST_RATE) {
    timer = millis();
    Serial.println("\n>>> REQ");
    ether.browseUrl(PSTR("/emoncms/input/post?apikey=190528433xxxxx&node=2&json="), "{power:252.4,temperature:15.4}", website, 0);


It has been a year or two since I used the Ethercard library, I will have to leave it to someone more familiar with it to help you.

Ok, thanks you Robert, I thing I will replace arduino nanos to arduino UNO with ethernet shield to use ethernet.h shield.

That could be the best solution. I found the documentation for Ethercard not clear and confusing, and I am English. For you it must be really difficult.

I looked at the sketches I have for the NanodeRF, but they did not help.