Open Energy Monitor Port

Thank you very much to Hootie81 and to phec.
I have modified my bulid.mk file (there were some files which were not included) and it compiles. Thanks again!!!

Hello again phec,

I have tried your code modifying:
client.connect(ā€œ192.168.1.113ā€,80);//your PC address or emoncms.org
for:
client.connect(ā€œemoncms.orgā€,80);//your PC address or emoncms.org
Changing ā€œyour emoncms apikeyā€ fo my writing emoncms apikey :

client.println("&apikey=your emoncms apikey");

And changing:

client.println(ā€œ192.168.1.113ā€);

for

client.println(ā€œemoncms.orgā€);

It does not receive any answer from the server because the small led doesn’t blink.
Any suggestions???
I have used other emoncms codes posting on it without problems with Spark, but using HTTP client.

try addingĀ  a line digitalWrite(ledPin, HIGH); just after the if(client.connected()) line this will let you know if you are connecting or not, just for troubleshooting

if not… maybe try pinging the emoncms from your computer, and try using the IP address the ping uses, i have issues resolving hostnames and have to use ip address when on a really really slow connection (~500b/s maxing out at 3kb/s.)

Also i dont know why the reading the result is in the middle of the request, before all the header is sent?
I would change to something like (haven’t checked this im just thinking out aloud), this should wait up for 2 seconds for a reply, otherwise it will continue as soon as it gets one.

 unsigned long timeout = millis();
    while(!client.available() && timeout < millis() - 2000));
if (client.available()){
            if (client.read()=='o') digitalWrite(ledPin, HIGH);  //set LED high if client responded (should send ok)
        }

I do not know what I was doing wrong. I have rewrite all the fields and it works!!! Thank you very much.

Now, I am modifying the version of the code of @phec uploaded in github to measure all the parameters he measures except the interrupt parameters (gas and the 2 photoresistors) but sending them by TCP to emoncms.org

If someone has done it I will be pleaseful if it would be shared.

When I achieve it. I will try with my original goal, I need to measure triphasic signals. For my project I need three voltages (the three phases), three input currents and three output currents.

If you count there are 9 signals but only 8 analog inputs in SparkCore that is why I will try to develop my own SparkCore in the measuring board with a different microcontroller with more analogs inputs.

I will write here about my progress.

Thank you very much to all of you, specially @phec and @Hootie81

Sounds like an interesting project, what exactly are you trying to do?

the cost of the spark is so cheap why not use 2? if your buying 6 current clamps, 6 transformers etc
Could you have 2 units, both identical,
each unit has 3 phase current and voltage inputs?

that gives you extra flexibility with placement too

I do not know why but I am receiving different data that I expect. I have connected the V measurement to A2, the current I1 in A0 and the current I2 in A1.

I have measure with the multimeter VAC of 2.3 and VDC of 1.65 in the pin (how it is expected).

Where is my 240Vac in the emoncms? I am receiving 1.85

I have assured in the setup() the correct pin configuration and the correct calibration value:

pinMode(CT1Pin, INPUT);
pinMode(CT2Pin, INPUT);
pinMode(V1Pin, INPUT);
emon1.voltage(V1Pin, 250.0, 1.12); //initialise emon with pin, Vcal and phase
emon1.current(CT1Pin, 100); //pin, Ical correct at 1kW
emon1.current(CT2Pin, 100);

where CT1Pin = A0; CT2Pin=A1; V1pin=A2

I am racking my brain but I cannot find what is wrong. Can anybody help me?

@javier_pelaez, Those are sensible questions.
The main issue with your code is that you have defined the CT and voltage pins as digital inputs - that is what pinMode(CT1Pin, INPUT); does. You don’t need to declare analog inputs.

Regarding the pin definitions in the emon1.voltage() and emon1.current() statements …

A0 is defined as 10 and A1 as 11 in wiring.h. (I looked at core-firmware/inc/wiring.h)
I put I have the low alternating voltage input on pin A0 and the current clamp on pin A1 and my code is:

Ā Ā Ā  emon1.voltage(0, 250.0, 2.0); //initialise emon with pin, Vcal and phase
Ā Ā Ā  emon1.current(1, 30);Ā Ā Ā Ā Ā Ā Ā Ā  //pin, Ical correct at 1kW

Consequently there would appear to be an error in my code - but fortunately the very very nice guys at Spark (or Arduino?) realised people like me would make silly mistakes and they have built in the correction into the wiring.cpp code:

int32_t analogRead(uint16_t pin)
{
Ā Ā  Ā // Allow people to use 0-7 to define analog pins by checking to see if the values are too low.
Ā Ā  Ā if (pin < FIRST_ANALOG_PIN)
Ā Ā  Ā {
Ā Ā  Ā Ā Ā  Ā pin = pin + FIRST_ANALOG_PIN;
Ā Ā  Ā }

So, for a current clamp on A0 and voltage on A2 the two lines should be:

Ā Ā Ā  emon1.voltage(A2, 250.0, 2.0); //initialise emon with pin, Vcal and phase
Ā Ā Ā  emon1.current(A0, 30);Ā Ā Ā Ā Ā Ā Ā Ā  //pin, Ical correct at 1kW

but you could also use 2 and 0 or 12 and 10.

Good luck.

Why do you need 3 voltages? You need one reference voltage for timing and look at the three current phases relative to this (adding or subtracting 120 degrees phase advance). There is something on the OpenEnergyMonitor site about 3 phase monitoring and they use a single Arduino which has only 6 analog inputs. They use 1 voltage and 3 currents. Could you use 1 voltage and 6 currents?
Post 54 (above) works with local emoncms. Note that the OpenEnergyMonitor people seem to be planning to charge for using their public server so you might like to set up a local server instead.

Thank you very much, I have not consider measure only 1 voltage and apply and substract 120 degrees per phase.

I have on emoncms locally installed and there is no problem with it, so if they finally decided to charge for the service it is not a critical problem. I am using their server because I want to try my system in different houses, so if I connect the board the Wifi net I can consult data in the internet plattform. I know if I have an static IP I can do the same but it was easier for me using in this way.

I have tried both different options (A0 or 0) and I am receiving:

AppPow 0.96
Vrms 1.87
Irms 0.51
PowFact -0.05
RealPow -0.05

I am using this circuit for measure the voltage:

I am using 2x sct 013 000 current clamps (100 amps) for current measurement

Sorry @javier_pelaez, I missed this post before. I’ve not used the remote emoncms and I don’t have an account to experiment with. Have you checked that you can upload to your emoncms account from your PC?
I think that the emoncms or open energy monitor web site would be the better place to go for advice and examples because they have a large community of the relevant experts. I see that someone has just asked about accessing emoncms using an Arduino with GPRS which is very close to your situation. If you do get a solution from them it would be nice to have a link to it here for completeness.
Sorry I can’t be more helpful.

Ok, thanks but it seems it is not a problem with the web platform it is a problem with the measures the spark gets and them, the code generates to send to the plattform.

I have detected one thing I do not understand in the code:

Vwaveform[numberOfSamples%128]=char((filteredV+2048)/16);//SPARK save waveform
Iwaveform[numberOfSamples%128]=char((filteredI+1024)/8); //SPARK save waveform

They should be identical 2048)/16 in both cases, shouldn’t they?

@javier_pelaez, Yes they could be. I have scaled the current up by a factor of 2 so that I use more use of the 256 bit range of the waveform array. The V uses pretty much the full range but I only use a small part of the 30A range for current. The arrays can only be 8bit variables because of the RAM limitations of the Spark.
See post 30.

@phec, with the latest RAM optimizations, you should be able to use 16bit values (unint16_t) in the waveform array! :smile:

Thanks @peekay123. Yes I’ve used uint16_t in the beehive monitor but I’ve not fixed the energy monitor in case I break it. I did update the firmware with some trepidation and so far everything continues to run just fine. I lose communications for a few minutes every few days but I think that may be a feature of my new TalkTalk (HG533) router and the system recovers without intervention.

using the code phec posted (the first one, not the second, becaus second code includes a library (SemonLib20.h) that is not in the online IDE), if I change the ip address to emoncms.org and enter my api key, this should post numbers to emoncms right? I am just using the online IDE to upload the code to my spark

client.connect(ā€œemoncms.orgā€,80); //the address of the PC with emoncms running

    client.print("Host: ");
    client.println("emoncms.org");
    client.println("Connection: close");

@Mquist I’m pleased to see you are exploring the energy monitor. You will need the Spark version of Emonlib (Semonlib20.cpp and Semonlib20.h) whether you use the IDE or compile offline.
On the IDE you can add the ported library files as extra tabs - see screen dump below - you click on the little circle with an I in it on the tab bar with the .ino file name to open a new tab then copy the library file (.cpp) and the header (.h) file into new tabs. It then runs from the IDE. You will see that for the IDE version I lost the version number in the filename because of the way the IDE asks you to name files.

You may find that Spark have changed the names of some of their functions since I wrote the code so if you get compile errors check that there isn’t a new name (for example we have the better organised WiFi.xxx() and Spark.xxx() instead of System.xxx()).

I have used both Netbeans and the IDE to program the energy monitor but I don’t intend to touch the code I have running now to check out recent Spark IDE changes as it is stable and controlling my solarPV system.

Thank you sooo much for this detailed instructions, off course it did all work, when I knew how to add the library files :slight_smile:

now I can start to upload data from my micro hydro to emoncms :blush:

I’m delighted to hear it. Good luck with the micro hydro data.

@phec,

I have also started on learning how to interface a Current clamp sensor and the one i bought happened to be giving a current output! :smiley:

Also, the range is 100A/50ma but my application is only in the range of 1-8A. Do you think this will post a challenge to monitor the current usage?

I forgot about the decoupling capacitor between gnd and the analog pin so i have to add it in before testing.

Thanks for the help!