sr-g / current-cost-forwarder Goto Github PK
View Code? Open in Web Editor NEWForwards readings from a Current Cost ENVIR through a MQTT Broker
Forwards readings from a Current Cost ENVIR through a MQTT Broker
Hello,
I know it is two years since last update, but I was just hoping you can help me. I did managed to make it work on my Synology. I'm able to use forwarder and receive data into my openHab. But for some reason i cannot split reading between different IAM's. When I add this code:
current-cost-forwarder.sh --broker-topic 'metrics/current-cost/${id}/'
I'm getting this output without proper ID, so I cannot use it.
09:48:08.037 [THREAD-CURRENT-COST-FORWARDER-MQTT] INFO org.tensin.ccf.forwarder.mqtt.ForwarderMQTT - Forwarding event #9 EventWatts : timestamp [1504774087976], watts [89] on topic [metrics/current-cost/${id}/watts]
What am I doing wrong?
Hi Serge
Firstly thanks for implementing this software. My system has been running very well for a while now, and I am able to look at my 3 phase power consumption via Openhab. I would be very interested to see the Current Cost history data as well. I could probably implement rules in Openhab to integrate the power readings and generate the energy used over a period, but it would be much cleaner to use the history data emitted by the Envi device.
At first I would just be interested in the most recent history items i.e. h002, d001, m001 and would use Openhab's persistence tools to store and graph these items. In future I might also want the rest of the history. If the Current Cost Forwarder published all the history data with appropriate topics, users could simply subscribe to the history items they were interested in.
Hopefully this would not be too difficult to implement.
Regards
Nigel
Hi,
Trying this out on a Raspberry Pi, I just seem to get lots of Now Connected messages.
17:55:38.684 [main] INFO org.tensin.ccf.CurrentCostForwarder - Now starting reader
17:55:38.695 [main] INFO org.tensin.ccf.reader.CurrentCostReader - Trying to autodect mirror4j device in [/dev/] with pattern [ttyUSB.*]
17:55:38.792 [main] INFO org.tensin.ccf.reader.CurrentCostReader - Auto-detected current cost device [/dev/ttyUSB0]
17:55:38.913 [main] INFO org.tensin.ccf.reader.CurrentCostReader - Starting CurrentCostForwarder reader thread on device [/dev/ttyUSB0]
17:55:38.915 [main] INFO org.tensin.ccf.CurrentCostForwarder - CurrentCostForwarder started in [572ms]
17:55:38.918 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.020 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.120 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.220 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.320 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.420 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.520 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.620 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.720 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.820 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:39.920 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:40.020 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:40.120 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:40.220 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:40.320 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
17:55:40.420 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB0]
First of all: great piece of software!
I was just wondering if and how support for the currentcost IAM's can be built into the program? I am truely not a coding expert (am runninging the Perl code below now to post the values from the currentcost to my Emoncms installation, but prefer to go to MQTT)
> #!/usr/bin/perl -w
> # Reads data from a Current Cost device via serial port.
> BEGIN {
> push @INC,"/usr/lib/perl5/";
> }
> use warnings;
> use Device::SerialPort qw( :PARAM :STAT 0.07 );
> use LWP::UserAgent;
>
> my $PORT = "/dev/ttyUSB-envi";
> my $meas = 0;
> my $sumW = 0;
> my $sumT = 0;
> my $watts;
> #2 extra variables for IAM 1
> my $watts_sensor1;
> my $sumwatts_sensor1= 0;
> my $watts_sensor2;
> my $sumwatts_sensor2= 0;
> my $watts_sensor3;
> my $sumwatts_sensor3= 0;
> # my $watts_sensor4;
> # my $sumwatts_sensor4= 0;
> my $temp;
> $meassensormain= 0;
> $meassensor1 = 0;
> $meassensor2 = 0;
> $meassensor3 = 0;
> # $meassensor4 = 0;
>
>
>
> my $ob = Device::SerialPort->new($PORT) || die "Can't open $PORT: $!\n";
> $ob->baudrate(57600);
> $ob->write_settings;
>
> open(SERIAL, "+>$PORT");
> while (my $line = <SERIAL>) {
> if ($line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>0</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
> my $watts = $2;
> my $temp = $1;
> print "SUCCESS mainunit $meas: ... $watts, $temp\n";
> $meassensormain = 1;
> $sumW = $watts;
> $sumT = $temp;
> }
> #extra if statement to get watts for IAM 3, change the sensorname to reflect this
> if ($line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>3</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
> my $watts_sensor3 = $2;
> print "SUCCESS IAM3 $meas: ... $watts_sensor3\n";
> $meassensor3 = 1;
> $sumwatts_sensor3 = $watts_sensor3;
> }
> #extra if statement to get watts for IAM 4, change the sensorname to reflect this
> # if ($line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>4</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
> # my $watts_sensor4 = $2;
> # print "SUCCESS IAM4 $meas: ... #$watts_sensor4\n";
> # $meassensor4 = 1;
> # $sumwatts_sensor4 = $watts_sensor4;
> # }
>
> #extra if statement to get watts for IAM 2, change the sensorname to reflect this
> if ($line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>2</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
> my $watts_sensor2 = $2;
> print "SUCCESS IAM2 $meas: ... $watts_sensor2\n";
> $meassensor2 = 1;
> $sumwatts_sensor2 = $watts_sensor2;
> }
> #extra if statement to get watts for IAM 1, change the sensorname to reflect this
> if ($line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>1</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
> my $watts_sensor1 = $2;
> print "SUCCESS IAM1 $meas: ... $watts_sensor1\n";
> $meassensor1 = 1;
> $sumwatts_sensor1 = $watts_sensor1;
> }
> if ($meassensormain ==1 and $meassensor1 ==1 and $meassensor2 == 1 and $meassensor3 == 1) { #time to send
> $watts = $sumW;
> $temp = $sumT;
> #Additional line for each sensor, note that meas increases 2 times in the cases of 1 additional IAM, so watt readings need to be divided by meascount/sensoramount
> $watts_sensor1 = $sumwatts_sensor1;
> $watts_sensor2 = $sumwatts_sensor2;
> $watts_sensor3 = $sumwatts_sensor3;
> # $watts_sensor4 = $sumwatts_sensor4;
> print "AVERAGE: ... $watts, $temp, $sumwatts_sensor1, $sumwatts_sensor2, $sumwatts_sensor3\n";
> #print "AVERAGE: ... $watts, $temp, $watts_sensor1, $watts_sensor2, $watts_sensor3, $watts_sensor4\n";
> my $emon_ua = LWP::UserAgent->new;
> #Line below is because I upload readings to 2 sites in parallel as backup
> my $emon_url2 = "http://URL/emoncms9/input/post.json?node=1&apikey=MYAPIKEY&json={powerenvi:$watts,temp:$temp,sensor1:$watts_sensor1,sensor2:$watts_sensor2,sensor3:$watts_sensor3}";
> my $emon_response2 = $emon_ua->get($emon_url2);
> print "$emon_url2\n";
> #Do not forget to reset the sum for an additional sensor
> $meas = $sumW = $sumT = $sumwatts_sensor1 = $sumwatts_sensor2 = $sumwatts_sensor3 = $meassensormain = $meassensor1 = $meassensor2 = $meassensor3 = 0;
> }
> }
Hi.
I'm trying to get this to work on my ubuntu x86 installation. My CurrentCost device is actually connected to the same computer as I'm running both the MQTT broker and OpenHab on, but i guess that should be irrelevant (i could not find any other solution for using CurrentCost with OpenHab).
After startup, the current-cost-forwarder stops after this:
21:32:39.593 [main] INFO org.tensin.ccf.reader.CurrentCostReader - Starting CurrentCostForwarder reader thread on device [/dev/ttyUSB1]
21:32:39.596 [main] INFO org.tensin.ccf.CurrentCostForwarder - CurrentCostForwarder started in [508ms]
21:32:39.603 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB1]
It never starts forwarding events to MQTT. If i start it with the debug flag, i can see that it actually receives data from my CurrentCost:
07:48:44.648 [main] INFO org.tensin.ccf.reader.CurrentCostReader - Starting CurrentCostForwarder reader thread on device [/dev/ttyUSB1]
07:48:44.649 [main] INFO org.tensin.ccf.CurrentCostForwarder - CurrentCostForwarder started in [500ms]
07:48:44.656 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.reader.CurrentCostReader - Now connected on specified device [/dev/ttyUSB1]
07:48:44.657 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Now starting acquisition from device
07:48:58.029 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.030 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.031 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.032 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.034 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.035 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.036 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.037 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.038 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.038 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.039 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.039 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.040 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
07:48:58.041 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Just received some characters from device
etc.
cat /dev/ttyUSB1 works ok:
CC128-v1.290101802:10:0723.5003344101229
Any ideas of where it's failing?
-AB
Edit: Forgot to mention, the MQTT broker seems to work fine. I've tested it with mosquitto_sub and mosquitto_sub w/o any problems (no authentication). I also set --broker-url "tcp://localhost:1883" in current-cost-forwarder.sh.
Not sure whether you use any IAM's, and need to separate the wattage data?
From what I can see, all the data is pushed into the same topic.
08:43:24.497 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.forwarder.mqtt.ForwarderMQTT - Forwarding event #5 EventWatts : watts [2] on topic [metrics/current-cost/watts]
08:43:26.976 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.forwarder.mqtt.ForwarderMQTT - Forwarding event #6 EventTemperature : temperature [22.6] on topic [metrics/current-cost/temperature]
08:43:27.049 [THREAD-CURRENT-COST-FORWARDER-READER] INFO org.tensin.ccf.forwarder.mqtt.ForwarderMQTT - Forwarding event #7 EventWatts : watts [151] on topic [metrics/current-cost/watts]
Here is a debug example of an IAM, with an alternate id ...
08:57:58.213 [THREAD-CURRENT-COST-FORWARDER-READER] DEBUG org.tensin.ccf.reader.CurrentCostReader - Now processing XML [CC128-v1.290163910:36:5622.5103047100002]
So, all the data that comes through is not able to be identified, AFAIK. Unless, I'm missing something.
pi@raspberrypi ~ $ mosquitto_sub -h 127.0.0.1 -p 1883 -t metrics/#
22.4
143
22.4
2
22.4
164
22.4
229
22.4
2
22.4
146
22.4
231
22.4
2
22.4
169
22.4
259
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.