Basic configuration of ethercard library and arduino 1.0 for posting to emoncms3

A ready configured sketch can be downloaded from our github: https://github.com/openenergymonitor/NanodeRF/blob/master/NanodeRF_singleCT/NanodeRF_singleCT.ino

What you will need:

Goto: File -> Examples -> etherCard -> webClient

Change line 12 from:

char website[] PROGMEM = "www.google.com";

to:

char website[] PROGMEM = "www.vis.openenergymonitor.org";

Change line 48 from:

ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback);

to:

ether.browseUrl(PSTR("/emoncms3/api/post.json?apikey=53c13213f301f6427c857a9426ce0efa&json="), "{power:252.4,temperature:15.4}", website, my_callback);

Upload sketch

Check Serial Monitor window for successfull DHCP, DNS and server reply.

Goto http://vis.openenergymonitor.org/emoncms3 and log in as: demo: demo to see the result

Note these instructions are for posting to a server with a domain name. For posting to a server with only an IP address see the example on out Github under NanodeRF. Some changes are required, noted in the code comments. 

roedfjel's picture

hello trystian.   thanks for

hello trystian.

 

thanks for a wonderfull solution.

but can you make an example sketch for posting data to emoncms and pachub?

 

Ian Barton's picture

Compiler Errors in Library Code

 I have just tried compiling some examples from the EtherCard development branch, both downloaded from here and cloned from Github. I am getting loads of compiler errors like this:

/usr/share/arduino/libraries/EtherCard/tcpip.cpp: In function 'word www_client_internal_datafill_cb(byte)':

/usr/share/arduino/libraries/EtherCard/tcpip.cpp:458:20: error: variable 'c' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

/usr/share/arduino/libraries/EtherCard/tcpip.cpp:467:20: error: variable 'c' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

I am using Adruino 1.0 on Arch Linux. Am I doing something simple wrong, or do I need to go through the library code and try and fix this? I am not a C programmer, so it might take me a while:)

Ian.

 

glyn.hudson's picture

Re: emonBase EtherCard compile errors

Mmm thats strange, I've just tested it now and it still works fine. Others have reported succes http://openenergymonitor.org/emon/node/318#comment-2553.

Can you compile the examples which come with the EtherCard library. Did you downlod the EtherCard library from here: https://github.com/jcw/ethercard/tree/development ? Make sure you have the latest one. The dev branch will soon be merged into the master in the new few days/weeks. 

Are you using Arduino 1.0? and can you compile standard Arduino 1.0 examples such as Blink? 

Ian Barton's picture

 I have just pulled the

 I have just pulled the latest updates from github and switched to the development branch. Still get the same errors. I am using Arduino 1.0 and other stuff works fine. I am getting lots of errors like:

/usr/share/arduino/libraries/EtherCard/tcpip.cpp: In function 'word www_client_internal_datafill_cb(byte)':

/usr/share/arduino/libraries/EtherCard/tcpip.cpp:458:20: error: variable 'c' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

/usr/share/arduino/libraries/EtherCard/tcpip.cpp:467:20: error: variable 'c' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

Unfortunately, the function doesn't have a variable named 'c', so my attempts at debugging have ground to a halt. I expect it's a fairly simple C++ syntax problem. However, I haven't used C for about 25 years and anyway I hate it :)

Mr. Sharkey's picture

re: Compiling errors

I've been trying to use the new IDE 1.0 also, and have been getting "warnings" on perfectly functional sketches that are similar to those you posted. These warnings don't cause the compilation to actually fail, it will still upload and run on the processor.

Are the errors you are experiencing fatal to the process, or are they only warnings?

Ian Barton's picture

 Unfortunately, the are all

 Unfortunately, they are all fatal.

glyn.hudson's picture

Re: Arduino 1.0 errors

So you say that the EtherCard example lke webClient compile fine?

What OS are you using? We have only tested Arduino 1.0 on Ubuntu as thats what we use.  

Ian Barton's picture

 No, none of the examples

 No, none of the examples will compile. I am using Arch Linux. I'll try with Ubuntu in a VM and see how that goes.

 

Ian Barton's picture

 OK, so I installed Ubuntu

 OK, so I installed Ubuntu Natty and EtherCard stuff compiles correctly with IDE V1.0. However, gcc in Ubuntu is 4.5.2 and in Arch it is 4.6.2. I wonder if that's the problem.

[Edit]

Just to add that I have now got the nuelectronics shield working on Ubuntu with Arduino 1.0 and the development branch of EtherCard. I had some probems getting compiled code to upload from a Virtual machine, so I am now using one of our MythTV front ends for development. Luckily I can edit the code remotely using Emacs and tramp and run the Arduino IDE via ssh, so it's not too inconvenient. However, I would like to get it working on Arch.

xotet's picture

Compiler Errors

 I´m trying to test the emoncms v3, but can´t compile the github.com/openenergymonitor/NanodeRF/tree/master/NanodeRF_singleCT

 

  I´ve got this errors

  NanodeRF_singleCT.cpp: In function 'void my_callback(byte, word, word)':
  NanodeRF_singleCT:104: error: 'get_header_line' was not declared in this scope
  NanodeRF_singleCT:107: error: 'get_reply_data' was not declared in this scope

 

  I have the ethercard lib and jeelib on libraries folder. of course runing arduino IDE ver 1.0

 

 

 Thanks in advance
 

xotet's picture

Solved

 Sorry I solved just missed to include the reply skecth. Now is Working WOW!!!!!!!

segu's picture

A little explanation

Hello

Please can you explain a little more what you did. I can contact the emoncms server but do not see changes in the dashboard. That is why I am asking for some help.

Thank you in any case.

EnergyRnR's picture

 anyone use this sketch on

 anyone use this sketch on their own 'localhost' emoncms server? I'm able to post to the vis.openenergymonitor.org site, but can't 'see' my own server. I'm using a Nanode 5 and Arduino 1.0 IDE. Ubuntu 11.10 [Desktop distro, not server though]. Emoncms is in the /var/www dir.

I have enabled mod rewrite and clean urls. I don't have drupal installed.

I get past the DHCP/DNS section, and then the sketch fails as you can see below.

Tomorrow, I'll clean install ubuntu on another machine [server edition] and try again.

<<< REQ GET /emoncms3/api/post.json?apikey=481363b81db11b0c762e7323c0f80d52&json={power_EOB:252.4,temperature_EOB:15.4} HTTP/1.1

Host: localhost

Accept: text/html

Connection: close

>>>

HTTP/1.1 404 Not Found

Content-Type: text/html

Transfer-Encoding: chunked

Server: Allegro-Software-RomPager/4.03

Connection: close

...

>>>

0cc

<html>

<head>

<title>Object Not Found</title>

</head>

<body>

<h1>Object Not Found</h1>

The requested URL '/emoncms3/api/post.json' was not found.<p>

<SNIP>.........................

<<< REQ GET /emoncms3/api/post.json?apikey=481363b81db11b0c762e7323c0f80d52&json={power_EOB:252.4,temperature_EOB:15.4} HTTP/1.1

Host: localhost

Accept: text/html

Connection: close

 page</A><p>

</body>

</html>

0

>>>

HTTP/1.1 404 Not Found

Content-Type: text/html

Transfer-Encoding: chunked

Server: Allegro-Software-RomPager/4.03

Connection: close

...

>>>

0cc

<html>

<head>

<title>Object Not Found</title>

</head>

<body>

<h1>Object Not Found</h1>

The requested URL '/emoncms3/api/post.json' was not found.<p>

<SNIP>

EnergyRnR's picture

 anyone use this sketch on

 anyone use this sketch on their own 'localhost' emoncms server? I'm able to post to the vis.openenergymonitor.org site, but can't 'see' my own server. I'm using a Nanode 5 and Arduino 1.0 IDE. Ubuntu 11.10 [Desktop distro, not server though]. Emoncms is in the /var/www dir.

I have enabled mod rewrite and clean urls. I don't have drupal installed.

I get past the DHCP/DNS section, and then the sketch fails as you can see below.

Tomorrow, I'll clean install ubuntu on another machine [server edition] and try again.

<<< REQ GET /emoncms3/api/post.json?apikey=481363b81db11b0c762e7323c0f80d52&json={power_EOB:252.4,temperature_EOB:15.4} HTTP/1.1

Host: localhost

Accept: text/html

Connection: close

>>>

HTTP/1.1 404 Not Found

Content-Type: text/html

Transfer-Encoding: chunked

Server: Allegro-Software-RomPager/4.03

Connection: close

...

>>>

0cc

<html>

<head>

<title>Object Not Found</title>

</head>

<body>

<h1>Object Not Found</h1>

The requested URL '/emoncms3/api/post.json' was not found.<p>

<SNIP>.........................

<<< REQ GET /emoncms3/api/post.json?apikey=481363b81db11b0c762e7323c0f80d52&json={power_EOB:252.4,temperature_EOB:15.4} HTTP/1.1

Host: localhost

Accept: text/html

Connection: close

 page</A><p>

</body>

</html>

0

>>>

HTTP/1.1 404 Not Found

Content-Type: text/html

Transfer-Encoding: chunked

Server: Allegro-Software-RomPager/4.03

Connection: close

...

>>>

0cc

<html>

<head>

<title>Object Not Found</title>

</head>

<body>

<h1>Object Not Found</h1>

The requested URL '/emoncms3/api/post.json' was not found.<p>

<SNIP>

TrystanLea's picture

Hello Eamonn, Have you

Hello Eamonn, Have you modified the sketch to point to the ip address of your local server rather than a dns address? Could this be the issue?

EnergyRnR's picture

 Trystan,  thanks ; I am

 Trystan,

 thanks ; I am using 'localhost' as the address; 127.0.0.1 returns a DNS fail.

Eamonn

gb095666's picture

I am not sure localhost or

I am not sure localhost or 127.0.0.1 will resolve to the correct address, you need to specifiy the IP of the server that is running emoncms on, whats happening at the moment I think is the card is trying to send packets to itself, I got mine working by assigning a fixed IP address to the emoncms server, (192.168.1.200), then changing the software to point to that address, I am using Ubuntu desktop edition btw and it's working fine.

EnergyRnR's picture

 Thanks ; I think you're

 Thanks ; I think you're right and changed my IP address to 192.168.1.100. but I still get a DNS error. 

I think it shouldn't even get as far as DNS lookup, if my /etc/hosts entry had a valid match, so I'm doing something odd here I think. I notice that having assigned a static IP the ethercard returns an IP of 192.168.1.24 in the serial window....would have expected it to be the new static IP...

I'm including the basic info below ....

 

This is what I use in the sketch

char website[] PROGMEM = "192.168.1.100";

This is my /etc/hosts file where 'laptop' is the hostname....

127.0.0.1 localhost.localdomain   localhost

::1 laptop localhost6.localdomain6 localhost6

192.168.1.100 laptop

# The following lines are desirable for IPv6 capable hosts

::1     localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

This is my /etc/network/interfaces file

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 192.168.1.100

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

I also tried changing my loopback IP to be 192.168.1.100 in /etc/hosts, but ifconfig still showed 127.0.0.1. as the lo IP address.

any thoughts appreciated.....

Eamonn

gb095666's picture

ok, I think I see where you

ok, I think I see where you have gone wrong, you shouldnt need to change your etc/config, mine is just the default, I think you have changed the wrong line in the sketch.

Change the line you have changed back to blank, i.e. char website[] PROGMEM = "";

and then put your IP address into the line static byte hisip[] = {192.168.1.100};

it should be about 6 line up in the sketch.

You also need to change the sketch in a further 2 places, line 132-135 which does the DNS look up needs commenting out and the line ether.copyIp(ether.hisip hisip); at line 137 needs to be included, so remove the // at the beginning of the line.

All the line numbers above are based on the 2CT version of the sketch.

EnergyRnR's picture

Thanks a lot for your input;

Thanks a lot for your input;  Interesting ;I was using the webclient example, so no mention of static IP option.

I can't find the 2CT sketch you're referring to anywhere, but used the single CT example xotet mentions above. That works great, so I'll 'kick on from here'. Thanks again for the ideas/input.

Thanks. Eamonn

glyn.hudson's picture

 Hi Eamonn, How are you

 Hi Eamonn,

How are you getting on? I have updated the insuructions at the top of this page to also cater for posting to a server without a domina name (IP address only) in this case DNS is not used. I use this to post to a remote server that does not have a domain name, it's not been tested posting to local host. Please let us know how you get on.

All the best, 

EnergyRnR's picture

 Glyn,  It's working, using

 Glyn,

 It's working, using the single CT example; which is great. I'll use that as a base and link in my live gas/electricity . Tomorrow I go and get myself a water meter as well :-) so that'll be interesting. 

What confused me was that the web client sketch referenced at the top of the page, doesn't have any DNS or hisip variable, so it was only when I started looking at the single CT sketch, I started to make progress :-)

I'm didn't break ubuntu though - what an OS. I really thought I have a config problem.

Thanks a lot,

Eamonn 

MetPhoto's picture

 Hi   I have the same error,

 Hi

 

I have the same error, sorry but I do not understand the fix?

 

What do I need to do to resolve this?

 

I am so close!

 

Mark

MetPhoto's picture

 Just in case it was not

 Just in case it was not clear, I get this error:

NanodeRF_singleCT_ino.cpp: In function 'void my_callback(byte, word, word)':

NanodeRF_singleCT_ino:106: error: 'get_header_line' was not declared in this scope

When uploading NanodeRF_singleCT 

MetPhoto's picture

 Okay, I fixed it now., I

 Okay, I fixed it now.,

I added the decode_reply.ino routine to the bottom of the NandoRF_singleCT.ino sketch,

Mark

MetPhoto's picture

 Yikes! It works! I can post

 Yikes! It works!

I can post to my local home server, but I am getting some funky figures:

{rf_fail:0,ct1:15372,battery:16419}

{rf_fail:0,ct1:-31081,battery:16424}

{rf_fail:0,ct1:24728,battery:16421}

Any ideas before I start to debug?

Mark

 

MetPhoto's picture

Okay, as far as I can tell

Okay, as far as I can tell the emonTX (v1.4) is transmitting correctly. The NanodeRF is recieving data.  However it would appear that the voltage ADC on the emonTX is simply floating up and down.  The values being recieved vary from huge negatives to huge pluses from one data burst to the next.

I have tried using CT1 and CT2, moving the tap from one socket to the other, and recompliing the code, but nothing changes. I have even tried messing with some of the code, line 116 in particular.

I have double checked my soldering, all seems fine.

Is the version of emonTx_1CT_Voltage on GITHUB complatible with the v1.4 hardware?

Any advice would be appreciated!

TIA

Mark

Typical data burst:

RF recieved

{rf_fail:0,ct1:13180,battery:14215}

0

Date: Sat, 21 Jan 2012 21:02:21 GMT

ok recieved

 

MetPhoto's picture

 One thing that I forgot to

 One thing that I forgot to write is that I cannot get the emonTx code to upload when I set the Arduuno board type to "Uno". If I choose this board type I get a 'AVR not responding" message or similar. However if I select "Nano with 328" or "Duemilanove with 328" the code uploads fine.

Again any ideas?

TrystanLea's picture

I rewrote the 1CT+voltage

I rewrote the 1CT+voltage code the other day but am yet to push to git hub I will do that now.

MetPhoto's picture

 Great, I look forward to

 Great, I look forward to it.

Mark

TrystanLea's picture

Ok, If you use the sketch

Ok, If you use the sketch here: https://github.com/openenergymonitor/emonTxFirmware/tree/master/emonTx_CT123_Voltage, its the latest version, the old one should have worked, but I know this one worked for me a couple of days ago when I did this test: http://openenergymonitor.org/emon/node/361

 

TrystanLea's picture

I see you say your atmega is

I see you say your atmega is a Duemilanove so you will need to comment the line #define UNO for it to work, It should not make any difference to the strange readings issue though. It may be worth trying the sampler program to just see if the voltage and current waveforms are of the expected shape: http://openenergymonitor.org/emon/node/110 

MetPhoto's picture

 Good morning, I have loaded

 Good morning,

I have loaded the new code emonTX_CT123_Voltage and now I get:

{rf_fail:0,ct1:2,battery:3}

{rf_fail:0,ct1:2,battery:3}

{rf_fail:0,ct1:2,battery:3}

{rf_fail:0,ct1:3,battery:9}

{rf_fail:0,ct1:2,battery:4}

{rf_fail:0,ct1:3,battery:8}

{rf_fail:0,ct1:1,battery:9}

I have left out some repeat values, but basically ct1 remain low, while battery has incremented a little.

If I put the tap into ct2 the values remain at 0, as expected.

Ideas?

MetPhoto's picture

 Now I am getting confused. I

 Now I am getting confused. I thought that Atmega was the name of the microcontroller, either a 328 or 168. The only difference being the amount of RAM they have. With "Uno" and "Duemilanove" being variations of the board made by Arduino.

The only significant difference being that the Uno now longer uses the FTDI interface.

So I am puzzeled as to why commenting out the #define would make any difference.  Regardless I am using the emonTX 1.4 hardware. I get an aavrdude: stk500_getsync(): not in sync: resp=0x00 error if I select Uno as the board type.

I will try and run the sampler code now and see what happens.

I may also swap the ATMega out for a spare I have, just in case the ADC are fired.

TrystanLea's picture

The significance of

The significance of Dumenlinove vs Uno is not do do with the actuall board but to do with which bootloader is uploaded to the atmega chip itself: http://arduino.cc/en/Main/Bootloader. This is why you can only upload with the Dumenlinove option.

Could you uncomment line 139 in the emontx sketch: emon1.serialprint(); and also line 160 and 161: Serial.println(); delay(100);

and let me know what you see?

In the serial window of the emontx, rather than the nanoderf that is. 

glyn.hudson's picture

 Hi Mark,  The emonTx

 Hi Mark, 

The emonTx firmware examples with 'voltage' in the title are for use when using an AC-AC to make RMS voltage measurements and therefore measure real power. You are just using a single CT, I know this becasure the emonTx V1.4 does not contain the option for voltage measurement. You need to use emonTx_singleCT_example: 

https://github.com/openenergymonitor/emonTxFirmware/tree/master/emonTx_SingleCT_Example_watchdog

Remember to comment out #define UNO towards the beginning of the sketch if not using the UNO optiboot bootlaoder. 

Sorry for the confusion. 

MetPhoto's picture

 BINGO! It works, thanks for

 BINGO!

It works, thanks for that.

MetPhoto's picture

 Ah, I see now. Thanks for

 Ah, I see now. Thanks for the explantion.  As you can see from my post below, using the correct Sketch has made all the difference!  :-)