New entry

Hi guys,

just wanted to say hello and thanks for all the information and the effort you are putting in helping people get started with the openenergymonitor platform

I just received my first (I already know it won't be the last but the wife wouldn't allow me to spend more :) ) batch of hardware with wich I'm planning to monitor:

  • External temperature
  • PC and Entertainment enrgy consumption
  • Global house energy consumption
  • Main Power failure alerting
  • Flood rain pumps energy consumption and activity (I have two, one working means some rain but no worries, two working means a lot of rain and better someone gets home to check that power won't go off all of a sudden)
  • In the future: rain gauge and other weather data, and if I will ever be able to afford them PV monitoring

My emonbase of choice is the raspberry, and I plan on running emoncms on it (with mysql data on my nas over nfs, if possible) and to use it as a collector for all the other non emontx data I will be needing

 

I'll try not to bother you too often (I am already nagging a coworker that has some soldering skills as mine are pretty abysmal) but I think that once I get the hardware running I will be able to cope with the software (where my skills are much better)

 

Again, thanks for all the info and keep up with the good work

 

Mattia

Mattia Rossi's picture

Re: New entry

... quick update ... had a mate that can solder assemble the two emontxes ... uploading the firmware was a piece of cake, setting up the temperature sensors as well, setting up emoncms .. the same ... I am already logging main home consumption and a couple of temperatures ... the dashboards in emoncms are really great. Took me two hours yesterday and less than an hour today ... what can I say,  I never had an arduino in my hands before wednesday ... you guys rock!

At the moment the emontx are not where I want to have them, will have to do some (simple) electrical work to set up the different feeds monitoring, but the main idea is to have the two emontx in closed boxes separate from anything with a voltage higher than 9v , while the CT sensors will be placed in the aprropriate safe places (no wires dangling, no 'temporary' connections). Next in line is the optical sensor to monitor (in order to double check the ct global measuring) the electricity meter, then I'll start thinking about the weather data.

At the moment what looks like the best option (and cheapest) is to add an RFM01 to the raspberry and write/adapt some code to receive data from sensors coming from a Fine Offset Electronics WH1080 (just bought the whole sensors set on ebay for 40 euro: pluviometer/anemometer/temperature/pressure/humidity).

I 'think' I could also use one of the emontx and have them receive the data, but since that would mean changing the RF parameters in order to receive the data, then change them to send them to the pi (along with normal data) and then change them again to be able to receive the next transmission ... I think I would end up losing a lot of measurements...

 

Mattia Rossi's picture

Re: New entry

another update ... the software side looks almost done, I have managed to test and integrate all the ct senstors, the temperature sensors and the optical sensor, I have a 5-7% discrepancy between the calibrated watt calculation and the power sensor calculation.

I have followed the calibration procedure here: http://www.openenergymonitor.org/emon/modules/emontx/firmware/calibration%20 and I am using a dc adapter bought on the openenergymonitor shop (euro plug), the suggested initial constant is 228.268

I have measured the actual voltage (and calculated my actual constant) by measuring with a multimeter and a kill-a-watt, the problem is that the two instruments disagree on the actual voltage .. the multimeter measures around 228 volt plus or minus two volts, while the kill-a-watt measures 214 volts plus or minus one .... I tend to agree with the multimeter but I have a discrpenacy nonetheless.

 

Will let it run a couple of days and then run some comparisons, right now the optical reading has been running for less than an hour ...

 

I have also ordered a RFM01 receiver and already have the weather station sensors ... the next software project will be to tap into the sensors and add that data to emoncms ....

I still have to place the emontxes in their final boxes and do the correct electrical wiring, will take a couple of photos once that part is done.

 

Have fun

Paul Reed's picture

Re: New entry

I see from your first post above that you want to implement Main Power failure alerting.

How do you plan to achieve this Mattia?

Mattia Rossi's picture

Re: New entry

Hi,

I already have an UPS with which I am actually powering  my internet router, firewall, home switch, and a nas and with which I plan on powering the raspberry and one of the two emontx. The ups is able to power all this rigamarole for about two hours so I'll have plenty of time to fire up some warning messages.

Right now the ups is already in my basement, I'll have to do some re-wiring and will put it next to the electricity meter (I have it inside the house in my basement). This way, when power fails, the reading on the mains CT and voltage sensor will drop next to 0 (actually 0 for the voltage sensor) and I will use the event plugin to notify me.

I have hacked around the event plugin to have it working with a fixed email address, and am planning to change the code to have it working using emoncms settings so that maybe I can give back something to the community (there just aren't enough hours in a day to do all I would like to get done ....) and eventually to add Growl or Notify My Android support ...

As long as the UPS batteries (or the raspberry, or the emontx) don't fail it should be foolproof :) 

 

Mattia

Mattia Rossi's picture

Re: New entry

...sorry .. double post ...

xz81's picture

Re: New entry

I found the alarm very interesting, despite I have no programming idea, may be it could be integrated in emoncms like a processing tab for a signal? (when it goes under a value, emoncms sends an email)

 

Paul Reed's picture

Re: New entry

I look forward to that Mattia, as there are quite a few members wanting to use the event module.

The addition of Boxcar prowl would be a welcome addition especially for iPhone/iPad users. The app is free, reliable and very popular, and they have full api details on their website.

Paul

Mattia Rossi's picture

Re: New entry

Hi,

@xz81: you already have this functionality in the event module, the problem is that at the moment it is disabled because of a couple of problems.

The problems I have found (so far) :

  • adding new events
  • firing the event check function
  • being able to use the data stored in the event settings to send emalis (I haven't checked twitter and prowl ... I have no twitter account and don't use ios in general so you will be on your own there .... or at least until I finish with the base install and can get back to it ...)

and what I have fixed so far:

  • firing the event check function: patch Modules/feed/feed_model.php with the following:

diff --git a/Modules/feed/feed_model.php b/Modules/feed/feed_model.php
index f6db96c..4d34a7e 100644
--- a/Modules/feed/feed_model.php
+++ b/Modules/feed/feed_model.php
@@ -275,11 +275,12 @@ class Feed
     $updatetime = date("Y-n-j H:i:s", $updatetime);
     $this->mysqli->query("UPDATE feeds SET value = '$value', time = '$updatetime' WHERE id='$feedid'");

-    // Check feed event if event module is installed
-    // if (is_dir(realpath(dirname(__FILE__)).'/../event/')) {
-    //    require_once(realpath(dirname(__FILE__)).'/../event/event_model.php');
-    //    check_feed_event($feedid,$updatetime,$feedtime,$value);
-    // }
+    //Check feed event if event module is installed
+    if (is_dir(realpath(dirname(__FILE__)).'/../event/')) {
+      require_once(realpath(dirname(__FILE__)).'/../event/event_model.php');
+      $event = new Event($this->mysqli);
+      $event->check_feed_event($feedid,$updatetime,$feedtime,$value);
+    }

     return $value;
   }
@@ -307,11 +308,12 @@ class Feed
     $updatetime = date("Y-n-j H:i:s", $updatetime);
     $this->mysqli->query("UPDATE feeds SET value = '$value', time = '$updatetime' WHERE id='$feedid'");

-    // Check feed event if event module is installed
-    // if (is_dir(realpath(dirname(__FILE__)).'/../event/')) {
-    //    require_once(realpath(dirname(__FILE__)).'/../event/event_model.php');
-    //    check_feed_event($feedid,$updatetime,$feedtime,$value);
-    // }
+    //Check feed event if event module is installed
+    if (is_dir(realpath(dirname(__FILE__)).'/../event/')) {
+      require_once(realpath(dirname(__FILE__)).'/../event/event_model.php');
+      $event = new Event($this->mysqli);
+      $event->check_feed_event($feedid,$updatetime,$feedtime,$value);
+    }

     return $value;
   }

  • Apply the following patch to Modules/event/event_model.php in order to correctly read the settings (and to give a more meaningful subject to the email sent):

diff --git a/event_model.php b/event_model.php
index 1b5b13d..e6ac6ad 100644
--- a/event_model.php
+++ b/event_model.php
@@ -112,19 +112,21 @@ class Event
       return $row;
     }

+
     public function check_feed_event($feedid,$updatetime,$feedtime,$value,$row=NULL) {

-        global $session;
+        global $user,$session,$feed;
         $userid = $session['userid'];

         $result = $this->mysqli->query("SELECT * FROM event WHERE eventfeed = $feedid");

         // check type
         while ($row = $result->fetch_array()) {
+
             if ($row['lasttime']+$row['mutetime'] > time() ) {
                 return 0;   
             }
-           
+          
             $sendAlert = 0;
             switch($row['eventtype']) {
                 case 0:
@@ -184,7 +186,7 @@ class Event
                     case 0:
                         // email
                         require_once(realpath(dirname(__FILE__)).'/../event/scripts/phpmailer/class.phpmailer.php');
-                        $smtp = get_user_smtp($userid);
+                        $smtp = $this->get_settings($userid);

                         $mail             = new PHPMailer();
                        
@@ -200,24 +202,24 @@ class Event
                         $mail->SMTPAuth   = true;                  // enable SMTP authentication
                         $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier

-                        $mail->Host       = $smtp['smtpserver'];     // sets GMAIL as the SMTP server
-                        $mail->Port       = $smtp['smtpport'];       // set the SMTP port for the GMAIL server
+                        $mail->Host       = $smtp['smtpserver'];      // sets GMAIL as the SMTP server
+                        $mail->Port       = $smtp['smtpport'];         // set the SMTP port for the GMAIL server
                         $mail->Username   = $smtp['smtpuser'];       // GMAIL username
-                        $salt = get_user_salt($row['userid']);
+                        $salt = $user->get_salt($userid);

                         $mail->Password   = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($smtp['smtppassword']), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));   // GMAIL password
-                       
-                        $mail->SetFrom($smtp['smtpuser'], 'emoncms');
+                      
+                        $address = $smtp['smtpuser'];
+                        $mail->SetFrom($address, 'emoncms');
                        
                         //$mail->AddReplyTo("[email protected]', 'First Last");
                        
-                        $mail->Subject    = "emoncms update";
+                        $mail->Subject    = "emoncms update on feed -> " . $feed->get_field($row['eventfeed'],'name');;
                        
                         //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
                        
                         $mail->MsgHTML($body);
-                       
-                        $address = $smtp['smtpuser'];
+                   
                         $mail->AddAddress($address, "emoncms");
                        
                         //$mail->AddAttachment("images/phpmailer.gif");      // attachment
@@ -225,8 +227,10 @@ class Event
                        
                         if(!$mail->Send()) {
                           echo "Mailer Error: " . $mail->ErrorInfo;
+                          error_log("Mailer Error: " . $mail->ErrorInfo);
                         } else {
                           echo "Message sent!";
+                          error_log("Message sent");
                         }

                         break;

 

PS: the feed.diff patch also includes a fix that enables the use of dashboards through a port forward connection to emoncms

PPS: don't really know whether these changes will be enough to allow the use of the event module on the hosted emoncms.org 

Now I'll start looking into why the event creation doesn't get registered, looking at the chrome debugger it looks like a problem with a jquery call that gets canceled from the client .. re-running the query in the same browser session successfully creates the event .... will have to investigate

 

Regards

Mattia Rossi's picture

Re: New entry

This is a new patch for the event module that fixes the problem when adding and deleting events :the add and delete buttons were performing an ajax call that was canceled by the page reload, added the proper login to allow for the ajax call to finish before reloading the page

 

 

Paul Reed's picture

Re: New entry

Mattia, have you submitted a pull request on Git for your work, to update the current branch.

Paul

Mattia Rossi's picture

Re: New entry

Erm, no .. I think there should be more than what I changed in order to make it work as intended, otherwise the original author would have done it himself .. it realy is a couple of lines per file ... what I am thinking is that either there are complications to use this code online on emoncms.org or he wants to do a complete overhaul ... 

Anyway, it's done now, just in case ....

Mattia Rossi's picture

Re: New entry

Small update .. I have been able to do some electrical work and have the pump monitoring emontx up, running, tested and safe, both from electrical hazards and from accidental cable pulling, still have to work on the electrical side on the main monitoring placement , I hope tomorrow will be the day ....

In the meantime, I have been playing with a WH1080 weather station (I bought only the sensors for around 40 euro) and an RFM01 .. yesterday I was able to cobble together some wires and some soldering and managed to connect it to my emonbase (raspberry) together with the rfm12 .. the idea is to receive data from the emontx nodes with the rfm12 and from the weather sensors with the RFM01.

So far so good, I have used this project https://github.com/ToninoTarsi/swpi as a (very good) starting point and have modified it to feed data to emoncms. So far I only have the temperature sensor up and running, will try to get everything (rain and wind sensors) up and running in the weeknd .. will post some photos once everything is working

 

Still amazed about how easy it is to get things going with the raspberry in general and the RFMxx modules in particular ...

 

Regards

calypso_rae's picture

Re: New entry

madmatt: I have a 5-7% discrepancy between the calibrated watt calculation and the power sensor calculation.

My suggestion would be to adjust your cal value(s) until your system records exactly the same amount of consumed power as does your meter.   Once the measured and actual values match, one would hope that this state of alignment would be maintained.  Alternatively, if nothing is changed, you would hope that the "discrepancy" would remain at "5 to 7%" as before.

When using a standard sketch, power is not sensed continuously, so any rapid variations in the rate of consumed power may not be detected by your system.

Mattia Rossi's picture

Re: New entry

Thanks calypso_rae , I already realized I would have to do some additional calibration. At the moment I am waiting to complete the electrical re-wiring before tackling the problem of fixing properly the optical sensor ... electrician tape, even for tests, won't do ... I get a lot of spurious inputs (I guess because of external light filtering in ...)

 

On the other hand I am almost done (I hope) with the weather data logging and monitoring, these are my dashboards and teh events I have set up so far:

 

 

calypso_rae's picture

Re: New entry

A blob of Blu-tac should keep stray light out without any problems.  It works fine with my (polled) LDR approach.

Mattia Rossi's picture

Re: New entry

Doh ... I was already thinking about a 3d printed custom  cover that would probably have cost me more than the emontx ... Sometimes us software guys really get lost while playing instead of getting things done ... Thanks calypso

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.